hvac.adapters¶
HTTP Client Library Adapters
Classes
|
Abstract base class used when constructing adapters for use with the Client class. |
|
The JSONAdapter adapter class. |
|
The RawAdapter adapter class. |
The RawAdapter adapter class. |
-
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.
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.
-
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
-
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 _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
-
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
-
-
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:
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.
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:
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.
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
hvac.adapters.RawAdapter
|
Extracts the client token from a login response. |
|
Main method for routing HTTP requests to the configured Vault base_uri. |
Methods