Skip to content

Commit 7b477be

Browse files
committed
Use pydantic in openapi spec
1 parent 9e5549e commit 7b477be

11 files changed

Lines changed: 556 additions & 266 deletions

lower_bounds_constraints.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ schema==0.7.5
77
tomli==2.0.0
88
tomli-w==1.0.0
99
pygments==2.17.2
10-
pydantic==2.11.7
10+
pydantic==2.9.2
1111
click-shell==2.1
1212
SecretStorage==3.3.3

pulp-glue/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers = [
2424
dependencies = [
2525
"multidict>=6.0.5,<6.8",
2626
"packaging>=22.0,<=26.0", # CalVer
27-
"pydantic>=2.11.7,<2.13",
27+
"pydantic>=2.9.2,<2.13",
2828
"requests>=2.24.0,<2.33",
2929
"tomli>=2.0.0,<2.1;python_version<'3.11'",
3030
]

pulp-glue/src/pulp_glue/common/authentication.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import typing as t
22

3+
import pulp_glue.common.pydantic_oas as s
4+
35

46
class AuthProviderBase:
57
"""
@@ -18,26 +20,32 @@ def can_complete_mutualTLS(self) -> bool:
1820
def can_complete_oauth2_client_credentials(self, scopes: list[str]) -> bool:
1921
return False
2022

21-
def can_complete_scheme(self, scheme: dict[str, t.Any], scopes: list[str]) -> bool:
22-
if scheme["type"] == "http":
23-
if scheme["scheme"] == "basic":
23+
def can_complete_scheme(self, security_scheme: s.SecurityScheme, scopes: list[str]) -> bool:
24+
if isinstance(security_scheme, s.SecuritySchemeHttp):
25+
if security_scheme.scheme == "basic":
2426
return self.can_complete_http_basic()
25-
elif scheme["type"] == "mutualTLS":
27+
elif isinstance(security_scheme, s.SecuritySchemeMutualTLS):
2628
return self.can_complete_mutualTLS()
27-
elif scheme["type"] == "oauth2":
28-
for flow_name, flow in scheme["flows"].items():
29-
if flow_name == "clientCredentials" and self.can_complete_oauth2_client_credentials(
30-
flow["scopes"]
31-
):
32-
return True
29+
elif isinstance(security_scheme, s.SecuritySchemeOAuth2):
30+
client_credentials_flow = security_scheme.flows.client_credentials
31+
if client_credentials_flow is not None and self.can_complete_oauth2_client_credentials(
32+
list(client_credentials_flow.scopes.keys())
33+
):
34+
return True
3335
return False
3436

3537
def can_complete(
36-
self, proposal: dict[str, list[str]], security_schemes: dict[str, dict[str, t.Any]]
38+
self,
39+
proposal: dict[str, list[str]],
40+
security_schemes: dict[str, s.SecurityScheme | s.Reference],
3741
) -> bool:
3842
for name, scopes in proposal.items():
39-
scheme = security_schemes.get(name)
40-
if scheme is None or not self.can_complete_scheme(scheme, scopes):
43+
security_scheme = security_schemes.get(name)
44+
if (
45+
security_scheme is None
46+
or isinstance(security_scheme, s.Reference)
47+
or not self.can_complete_scheme(security_scheme, scopes)
48+
):
4149
return False
4250
# This covers the case where `[]` allows for no auth at all.
4351
return True

pulp-glue/src/pulp_glue/common/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@ class ValidationError(OpenAPIError):
5959
"""Exception raised for failed client side validation of parameters or request bodies."""
6060

6161

62+
class SchemaError(OpenAPIError):
63+
"""Exception raised for unsurmountable inconsistencies of the openapi schema."""
64+
65+
6266
class UnsafeCallError(OpenAPIError):
6367
"""Exception raised for POST, PUT, PATCH or DELETE calls with `safe_calls_only=True`."""

0 commit comments

Comments
 (0)