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, namespace=None, ignore_exceptions=False)[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, namespace=None, ignore_exceptions=False)[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.
-
auth
(url, use_token=True, **kwargs)[source]¶ - Call to deprecated function ‘auth’. This method will be removed in version ‘0.9.0’ Please use the ‘login’ method on the ‘hvac.adapters’ class moving forward.
- Docstring content from this method’s replacement copied below: 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 _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
-
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
-
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 _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
-
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, 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
-
-
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)[source]¶ Bases:
hvac.adapters.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.
-
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)[source]¶ Bases:
hvac.adapters.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.
-
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
hvac.adapters.RawAdapter