Internals - Platform - BlueCat Gateway - 20.6.1

Gateway Administration Guide

prodname
BlueCat Gateway
version_custom
20.6.1

Implementation of DNS Edge API classes includes leveraging the following to achieve the desired operation of each respective class.

class bluecat_libraries.http_client.Client(target:bluecat_libraries.http_client.instance.Instance)

Bases: object

An HTTP client with some utilities to make creating service clients easier. The class implements the necessary methods to act as a context manager.

Parameter Description
target (instance) A definition of a target service
New in version 20.6.1

close()

Release any allocated resources, e.g., an internal session.

handle_error_response(response: requests.models.Response)

Handle a response that’s considered to be an error (based on the HTTP status code). The standard implementation raises an exception. Derived classes may overwrite it to provide custom handling.

Parameter Description
response (requests.Response) Object representing the HTTP response

http_delete(url, params=None, data=None, json=None, expected_status_codes=None, **kwargs) -> requests.models.Response

Perform an HTTP DELETE request based on the provided parameters. See http_request for details

http_get(url, params=None, expected_status_codes=None, **kwargs) -> requests.models.Response

Perform an HTTP GET request based on the provided parameters. See http_request for details.

If expected_status_codes is not specified, it defaults to (200, ). 200 is the HTTP status code for successful response OK.

http_patch(url, params=None, data=None, json=None, expected_status_codes=None, **kwargs) -> requests.models.Response

Perform an HTTP PATCH request based on the provided parameters. See http_request for details.

http_post(url, params=None, data=None, json=None, expected_status_codes=None, **kwargs) -> requests.models.Response

Perform an HTTP POST request based on the provided parameters. See http_request for details.

http_put(url, params=None, data=None, json=None, expected_status_codes=None, **kwargs) -> requests.models.Response

Perform an HTTP PUT request based on the provided parameters. See http_request for details.

http_request(method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None, json=None, expected_status_codes=None)

Perform an HTTP request based on the provided parameters. It is done as part of the internally maintained session, i.e. using the set authorization. The majority of the method’s parameters correspond to their namesakes in requests.Session.request. However, this class additionally processes the response. It uses is_error_response() and handle_error_response() to detect and handle error responses. That approach allows derived classes to customize the behaviour. Additionally, it checks the HTTP status code against provided expected_status_codes and raises an exception.

Parameter Description
method (str) HTTP method to be used
url (str) URL to be used for the request
params (dict, optional) Query parameters to be passed in the request
data (dict, list[tuple], bytes, or a file-like object, optional) Value to be sent in the body of the request
headers (dict, optional) HTTP Headers to be sent with the request
cookies (dict or CookieJar object, optional) Cookies to be sent with the request
files (dict, optional) File-like objects for multipart encoding upload
auth (tuple or callable, optional) Object to handle HTTP Authentication
timeout (float or tuple, optional) How long to wait to receive data before giving up. If given as a tuple, it is used as (connect, read) timeouts
allow_redirects (bool, optional) Whether to allow redirects. Defaults to True
proxies (dict, optional) Mapping of protocol or protocol and hostname to a URL of a proxy to be used
hooks (dict) Hooks to be called upon events
stream (bool, optional) Whether to immediately read the response content. Defaults to False
verify (bool or str) Whether to verify the server’s TLS certificate. If a string is passed, it is treated as a path to a CA bundle to be used. Defaults to True
cert (str or tuple, optional) Path to a SSL client certificate file (.pem). If the certificate has a key, it can be provided as the second item in a tuple, with the first item being the path to the certificate file
json (object, optional) Object to be sent as JSON in the body of the request
expected_status_codes (iterable[int], optional) HTTP status codes that are acceptable as a status code of the HTTP response. If the received code does not match the passed values, an UnexpectedResponse is raised. If left empty, the status code validation is not performed

Returns: Object representing the HTTP response received to the performed request.

Return type: requests.Response

is_authenticated

Determine whether the authentication necessary to communicate with the target service is set.

is_error_response(response: requests.models.Response) -> bool

Determine whether a response is an error response.

This method exists to allow derived classes to customize the behaviour.

Parameter Description
response (requests.Response) Object representing the HTTP response

Returns: Whether the response conveys an error.

Return type: bool

class bluecat_libraries.http_client.Instance(url: str, logger: logging.Logger = None)

Bases: object

Definition of a service instance that can be used as a target by a client.

Parameter Description
url (str) URL of the service
logger (logging.Logger) Logger to be used for logging. This value is currently not utilized
Variables Description
url (url) URL of the service
api_url_base (str) URL to be used as a base for constructing paths to the service’s endpoints
New in version 20.6.1

parse_url()

Process the service’s URL and construct the value of the base URL of the service’s API.

class bluecat_libraries.edge.api.instance.EdgeInstance(url: str, logger: logging.Logger = None)

Bases: bluecat_libraries.http_client.instance.Instance

Definition of DNS Edge as a target instance.

New in version 20.6.1

parse_url()

Process the service’s URL and construct the value of the base URL of the service’s API.

class bluecat_libraries.service_point.api.instance.ServicePointInstance(url: str, logger: logging.Logger = None)

Bases: bluecat_libraries.http_client.instance.Instance

Definition of Service Point as a target instance.

New in version 20.6.1

parse_url()

Process the service’s URL and construct the value of the base URL of the service’s API.