pulp_glue.common.openapi¶
pulp_glue.common.openapi
¶
OpenAPIError
¶
Bases: Exception
Base Exception for errors related to using the openapi spec.
OpenAPIValidationError
¶
Bases: OpenAPIError
Exception raised for failed client side validation of parameters or request bodies.
UnsafeCallError
¶
Bases: OpenAPIError
Exception raised for POST, PUT, PATCH or DELETE calls with safe_calls_only=True
.
AuthProviderBase
¶
Base class for auth providers.
This abstract base class will analyze the authentication proposals of the openapi specs.
Different authentication schemes should be implemented by subclasses.
Returned auth objects need to be compatible with requests.auth.AuthBase
.
basic_auth(scopes)
¶
Implement this to provide means of http basic auth.
http_auth(security_scheme, scopes)
¶
Select a suitable http auth scheme or return None.
oauth2_client_credentials_auth(flow, scopes)
¶
Implement this to provide other authentication methods.
oauth2_auth(security_scheme, scopes)
¶
Select a suitable oauth2 flow or return None.
BasicAuthProvider(username, password)
¶
Bases: AuthProviderBase
Implementation for AuthProviderBase providing basic auth with fixed username
, password
.
OpenAPI(base_url, doc_path, headers=None, auth_provider=None, cert=None, key=None, verify=True, refresh_cache=False, safe_calls_only=False, debug_callback=None, user_agent=None, cid=None)
¶
The abstraction Layer to interact with a server providing an openapi v3 specification.
Parameters:
-
base_url
(str
) –The base URL inlcuding the HTTP scheme, hostname and optional subpaths of the served api.
-
doc_path
(str
) –Path of the json api doc schema relative to the
base_url
. -
headers
(Optional[Dict[str, str]]
, default:None
) –Dictionary of additional request headers.
-
auth_provider
(Optional[AuthProviderBase]
, default:None
) –Object that returns requests auth objects according to the api spec.
-
cert
(Optional[str]
, default:None
) –Client certificate used for auth.
-
key
(Optional[str]
, default:None
) –Matching key for
cert
if not already included. -
verify
(Optional[Union[bool, str]]
, default:True
) –Whether to check server TLS certificates agains a CA (requests semantic).
-
refresh_cache
(bool
, default:False
) –Whether to fetch the api doc regardless.
-
safe_calls_only
(bool
, default:False
) –Flag to disallow issuing POST, PUT, PATCH or DELETE calls.
-
debug_callback
(Optional[Callable[[int, str], Any]]
, default:None
) –Callback that will be called with strings useful for logging or debugging.
-
user_agent
(Optional[str]
, default:None
) –String to use in the User-Agent header.
-
cid
(Optional[str]
, default:None
) –Correlation ID to send with all requests.
call(operation_id, parameters=None, body=None, validate_body=True)
¶
Make a call to the server.
Parameters:
-
operation_id
(str
) –ID of the operation in the openapi v3 specification.
-
parameters
(Optional[Dict[str, Any]]
, default:None
) –Arguments that are to be sent as headers, querystrings or part of the URI.
-
body
(Optional[Dict[str, Any]]
, default:None
) –Body payload for POST, PUT, PATCH calls.
-
validate_body
(bool
, default:True
) –Indicate whether the body should be validated.
Returns:
-
Any
–The JSON decoded server response if any.
Raises:
-
OpenAPIValidationError
–on failed input validation (no request was sent to the server).
-
HTTPError
–on failures related to the HTTP call made.