Skip to content

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, validate_certs=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:

Name Type Description Default
base_url str

The base URL inlcuding the HTTP scheme, hostname and optional subpaths of the served api.

required
doc_path str

Path of the json api doc schema relative to the base_url.

required
headers Optional[Dict[str, str]]

Dictionary of additional request headers.

None
auth_provider Optional[AuthProviderBase]

Object that returns requests auth objects according to the api spec.

None
cert Optional[str]

Client certificate used for auth.

None
key Optional[str]

Matching key for cert if not already included.

None
validate_certs bool

Whether to check server TLS certificates agains a CA.

True
refresh_cache bool

Whether to fetch the api doc regardless.

False
safe_calls_only bool

Flag to disallow issuing POST, PUT, PATCH or DELETE calls.

False
debug_callback Optional[Callable[[int, str], Any]]

Callback that will be called with strings useful for logging or debugging.

None
user_agent Optional[str]

String to use in the User-Agent header.

None
cid Optional[str]

Correlation ID to send with all requests.

None

call(operation_id, parameters=None, body=None, validate_body=True)

Make a call to the server.

Parameters:

Name Type Description Default
operation_id str

ID of the operation in the openapi v3 specification.

required
parameters Optional[Dict[str, Any]]

Arguments that are to be sent as headers, querystrings or part of the URI.

None
body Optional[Dict[str, Any]]

Body payload for POST, PUT, PATCH calls.

None
validate_body bool

Indicate whether the body should be validated.

True

Returns:

Type Description
Any

The JSON decoded server response if any.

Raises:

Type Description
OpenAPIValidationError

on failed input validation (no request was sent to the server).

HTTPError

on failures related to the HTTP call made.