hvac.adapters๏ƒ

HTTP Client Library Adapters

Classes:

Adapter([base_uri,ย token,ย cert,ย verify,ย ...])

Abstract base class used when constructing adapters for use with the Client class.

JSONAdapter([base_uri,ย token,ย cert,ย verify,ย ...])

The JSONAdapter adapter class.

RawAdapter([base_uri,ย token,ย cert,ย verify,ย ...])

The RawAdapter adapter class.

Request

alias of RawAdapter

class hvac.adapters.Adapter(base_uri='http://localhost:8200', token=None, cert=None, verify=True, timeout=30, proxies=None, allow_redirects=True, session=None, namespace=None, ignore_exceptions=False, strict_http=False, request_header=True)[source]๏ƒ

Bases: object

Abstract base class used when constructing adapters for use with the Client class.

Methods:

__init__([base_uri,ย token,ย cert,ย verify,ย ...])

Create a new request adapter instance.

close()

Close the underlying Requests session.

delete(url,ย **kwargs)

Performs a DELETE request.

from_adapter(adapter)

Create a new adapter based on an existing Adapter instance.

get(url,ย **kwargs)

Performs a GET request.

get_login_token(response)

Extracts the client token from a login response.

head(url,ย **kwargs)

Performs a HEAD request.

list(url,ย **kwargs)

Performs a LIST request.

login(url[,ย use_token])

Perform a login request.

post(url,ย **kwargs)

Performs a POST request.

put(url,ย **kwargs)

Performs a PUT request.

request(method,ย url[,ย headers,ย raise_exception])

Main method for routing HTTP requests to the configured Vault base_uri.

urljoin(*args)

Joins given arguments into a url.

__init__(base_uri='http://localhost:8200', token=None, cert=None, verify=True, timeout=30, proxies=None, allow_redirects=True, session=None, namespace=None, ignore_exceptions=False, strict_http=False, request_header=True)[source]๏ƒ

Create a new request adapter instance.

Parameters:
  • base_uri (str) โ€“ Base URL for the Vault instance being addressed.

  • token (str) โ€“ Authentication token to include in requests sent to Vault.

  • cert (tuple) โ€“ Certificates for use in requests sent to the Vault instance. This should be a tuple with the certificate and then key.

  • verify (Union[bool,str]) โ€“ Either a boolean to indicate whether TLS verification should be performed when sending requests to Vault, or a string pointing at the CA bundle to use for verification. See http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification.

  • timeout (int) โ€“ The timeout value for requests sent to Vault.

  • proxies (dict) โ€“ Proxies to use when preforming requests. See: http://docs.python-requests.org/en/master/user/advanced/#proxies

  • allow_redirects (bool) โ€“ Whether to follow redirects when sending requests to Vault.

  • session (request.Session) โ€“ Optional session object to use when performing request.

  • namespace (str) โ€“ Optional Vault Namespace.

  • ignore_exceptions (bool) โ€“ If True, _always_ return the response object for a given request. I.e., donโ€™t raise an exception based on response status code, etc.

  • strict_http (bool) โ€“ If True, use only standard HTTP verbs in request with additional params, otherwise process as is

  • request_header (bool) โ€“ If true, add the X-Vault-Request header to all requests to protect against SSRF vulnerabilities.

close()[source]๏ƒ

Close the underlying Requests session.

delete(url, **kwargs)[source]๏ƒ

Performs a DELETE request.

Parameters:
  • url (str | unicode) โ€“ Partial URL path to send the request to. This will be joined to the end of the instanceโ€™s base_uri attribute.

  • kwargs (dict) โ€“ Additional keyword arguments to include in the requests call.

Returns:

The response of the request.

Return type:

requests.Response

classmethod from_adapter(adapter)[source]๏ƒ

Create a new adapter based on an existing Adapter instance. This can be used to create a new type of adapter that inherits the properties of an existing one.

Parameters:

adapter (hvac.Adapters.Adapter) โ€“ The existing Adapter instance.

get(url, **kwargs)[source]๏ƒ

Performs a GET request.

Parameters:
  • url (str | unicode) โ€“ Partial URL path to send the request to. This will be joined to the end of the instanceโ€™s base_uri attribute.

  • kwargs (dict) โ€“ Additional keyword arguments to include in the requests call.

Returns:

The response of the request.

Return type:

requests.Response

abstract get_login_token(response)[source]๏ƒ

Extracts the client token from a login response.

Parameters:

response โ€“ The response object returned by the login method.

Returns:

A client token.

Return type:

str

head(url, **kwargs)[source]๏ƒ

Performs a HEAD request.

Parameters:
  • url (str | unicode) โ€“ Partial URL path to send the request to. This will be joined to the end of the instanceโ€™s base_uri attribute.

  • kwargs (dict) โ€“ Additional keyword arguments to include in the requests call.

Returns:

The response of the request.

Return type:

requests.Response

list(url, **kwargs)[source]๏ƒ

Performs a LIST request.

Parameters:
  • url (str | unicode) โ€“ Partial URL path to send the request to. This will be joined to the end of the instanceโ€™s base_uri attribute.

  • kwargs (dict) โ€“ Additional keyword arguments to include in the requests call.

Returns:

The response of the request.

Return type:

requests.Response

login(url, use_token=True, **kwargs)[source]๏ƒ

Perform a login request.

Associated request is typically to a path prefixed with โ€œ/v1/authโ€) and optionally stores the client token sent

in the resulting Vault response for use by the hvac.adapters.Adapter() instance under the _adapter Client attribute.

Parameters:
  • url (str | unicode) โ€“ Path to send the authentication request to.

  • use_token (bool) โ€“ if True, uses the token in the response received from the auth request to set the โ€œtokenโ€ attribute on the the hvac.adapters.Adapter() instance under the _adapter Client attribute.

  • kwargs (dict) โ€“ Additional keyword arguments to include in the params sent with the request.

Returns:

The response of the auth request.

Return type:

requests.Response

post(url, **kwargs)[source]๏ƒ

Performs a POST request.

Parameters:
  • url (str | unicode) โ€“ Partial URL path to send the request to. This will be joined to the end of the instanceโ€™s base_uri attribute.

  • kwargs (dict) โ€“ Additional keyword arguments to include in the requests call.

Returns:

The response of the request.

Return type:

requests.Response

put(url, **kwargs)[source]๏ƒ

Performs a PUT request.

Parameters:
  • url (str | unicode) โ€“ Partial URL path to send the request to. This will be joined to the end of the instanceโ€™s base_uri attribute.

  • kwargs (dict) โ€“ Additional keyword arguments to include in the requests call.

Returns:

The response of the request.

Return type:

requests.Response

abstract request(method, url, headers=None, raise_exception=True, **kwargs)[source]๏ƒ

Main method for routing HTTP requests to the configured Vault base_uri. Intended to be implement by subclasses.

Parameters:
  • method (str) โ€“ HTTP method to use with the request. E.g., GET, POST, etc.

  • url (str | unicode) โ€“ Partial URL path to send the request to. This will be joined to the end of the instanceโ€™s base_uri attribute.

  • headers (dict) โ€“ Additional headers to include with the request.

  • kwargs (dict) โ€“ Additional keyword arguments to include in the requests call.

  • raise_exception (bool) โ€“ If True, raise an exception via utils.raise_for_error(). Set this parameter to False to bypass this functionality.

Returns:

The response of the request.

Return type:

requests.Response

static urljoin(*args)[source]๏ƒ

Joins given arguments into a url. Trailing and leading slashes are stripped for each argument.

Parameters:

args (str | unicode) โ€“ Multiple parts of a URL to be combined into one string.

Returns:

Full URL combining all provided arguments

Return type:

str | unicode

class hvac.adapters.JSONAdapter(base_uri='http://localhost:8200', token=None, cert=None, verify=True, timeout=30, proxies=None, allow_redirects=True, session=None, namespace=None, ignore_exceptions=False, strict_http=False, request_header=True)[source]๏ƒ

Bases: RawAdapter

The JSONAdapter adapter class. This adapter works just like the RawAdapter adapter except that HTTP 200 responses are returned as JSON dicts. All non-200 responses are returned as Response objects.

Methods:

get_login_token(response)

Extracts the client token from a login response.

request(*args,ย **kwargs)

Main method for routing HTTP requests to the configured Vault base_uri.

get_login_token(response)[source]๏ƒ

Extracts the client token from a login response.

Parameters:

response (dict | requests.Response) โ€“ The response object returned by the login method.

Returns:

A client token.

Return type:

str

request(*args, **kwargs)[source]๏ƒ

Main method for routing HTTP requests to the configured Vault base_uri.

Parameters:
  • args (list) โ€“ Positional arguments to pass to RawAdapter.request.

  • kwargs (dict) โ€“ Keyword arguments to pass to RawAdapter.request.

Returns:

Dict on HTTP 200 with JSON body, otherwise the response object.

Return type:

dict | requests.Response

class hvac.adapters.RawAdapter(base_uri='http://localhost:8200', token=None, cert=None, verify=True, timeout=30, proxies=None, allow_redirects=True, session=None, namespace=None, ignore_exceptions=False, strict_http=False, request_header=True)[source]๏ƒ

Bases: Adapter

The RawAdapter adapter class. This adapter adds Vault-specific headers as required and optionally raises exceptions on errors, but always returns Response objects for requests.

Methods:

get_login_token(response)

Extracts the client token from a login response.

request(method,ย url[,ย headers,ย raise_exception])

Main method for routing HTTP requests to the configured Vault base_uri.

get_login_token(response)[source]๏ƒ

Extracts the client token from a login response.

Parameters:

response (requests.Response) โ€“ The response object returned by the login method.

Returns:

A client token.

Return type:

str

request(method, url, headers=None, raise_exception=True, **kwargs)[source]๏ƒ

Main method for routing HTTP requests to the configured Vault base_uri.

Parameters:
  • method (str) โ€“ HTTP method to use with the request. E.g., GET, POST, etc.

  • url (str | unicode) โ€“ Partial URL path to send the request to. This will be joined to the end of the instanceโ€™s base_uri attribute.

  • headers (dict) โ€“ Additional headers to include with the request.

  • raise_exception (bool) โ€“ If True, raise an exception via utils.raise_for_error(). Set this parameter to False to bypass this functionality.

  • kwargs (dict) โ€“ Additional keyword arguments to include in the requests call.

Returns:

The response of the request.

Return type:

requests.Response

hvac.adapters.Request๏ƒ

alias of RawAdapter Methods:

get_login_token(response)

Extracts the client token from a login response.

request(method,ย url[,ย headers,ย raise_exception])

Main method for routing HTTP requests to the configured Vault base_uri.