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)[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)[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.
-
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
-
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.
Request
(base_uri='http://localhost:8200', token=None, cert=None, verify=True, timeout=30, proxies=None, allow_redirects=True, session=None, namespace=None)[source]¶ Bases:
hvac.adapters.Adapter
The Request adapter class
-
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
-