hvac.adapters

HTTP Client Library Adapters

class hvac.adapters.Adapter(base_uri='http://localhost:8200', token=None, cert=None, verify=True, timeout=30, proxies=None, allow_redirects=True, session=None)[source]

Bases: object

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

__init__(base_uri='http://localhost:8200', token=None, cert=None, verify=True, timeout=30, proxies=None, allow_redirects=True, session=None)[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.
auth(url, use_token=True, **kwargs)[source]
Performs a request (typically to a path prefixed with “/v1/auth”) and optionaly stores the client token sent
in the resulting Vault response for use by the hvac.adapters.Adapter() instance under the _adapater 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 _adapater 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

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

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

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

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

request(method, url, headers=None, **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.
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.Request(base_uri='http://localhost:8200', token=None, cert=None, verify=True, timeout=30, proxies=None, allow_redirects=True, session=None)[source]

Bases: hvac.adapters.Adapter

The Request adapter class

request(method, url, headers=None, **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.
  • kwargs (dict) – Additional keyword arguments to include in the requests call.
Returns:

The response of the request.

Return type:

requests.Response