hvac.utilsΒΆ
Misc utility functions and constants
Functions
|
Convert comma-delimited list / string into a list of strings |
|
This is a decorator which can be used to mark methods as deprecated. |
|
Creates a URL using the specified format after escaping the provided arguments. |
|
Generate a message to be used when warning about the use of deprecated methods. |
|
Generate a message to be used when warning about the use of deprecated properties. |
Get the token from env var, VAULT_TOKEN. |
|
|
Helper method to use in the getattr method of a class with deprecated properties. |
|
Convert a list of strings into a comma-delimited list / string. |
|
Helper method to raise exceptions based on the status code of a response received back from Vault. |
|
Removes None values from optional arguments in a parameter dictionary. |
|
Validate that an argument is a list of strings. |
|
Validate that an argument is a PEM-formatted public key or certificate |
-
hvac.utils.
comma_delimited_to_list
(list_param)[source]ΒΆ Convert comma-delimited list / string into a list of strings
- Parameters
list_param (str | unicode) β Comma-delimited string
- Returns
A list of strings
- Return type
list
-
hvac.utils.
deprecated_method
(to_be_removed_in_version, new_method=None)[source]ΒΆ This is a decorator which can be used to mark methods as deprecated. It will result in a warning being emitted when the function is used.
- Parameters
to_be_removed_in_version (str) β Version of this module the decorated method will be removed in.
new_method (function) β Method intended to replace the decorated method. This methodβs docstrings are included in the decorated methodβs docstring.
- Returns
Wrapped function that includes a deprecation warning and update docstrings from the replacement method.
- Return type
types.FunctionType
-
hvac.utils.
format_url
(format_str, *args, **kwargs)[source]ΒΆ Creates a URL using the specified format after escaping the provided arguments.
- Parameters
format_str (str) β The URL containing replacement fields.
kwargs (dict) β Positional replacement field values.
kwargs β Named replacement field values.
- Returns
The formatted URL path with escaped replacement fields.
- Return type
str
-
hvac.utils.
generate_method_deprecation_message
(to_be_removed_in_version, old_method_name, method_name=None, module_name=None)[source]ΒΆ Generate a message to be used when warning about the use of deprecated methods.
- Parameters
to_be_removed_in_version (str) β Version of this module the deprecated method will be removed in.
old_method_name (str) β Deprecated method name.
method_name (str) β Method intended to replace the deprecated method indicated. This methodβs docstrings are included in the decorated methodβs docstring.
module_name (str) β Name of the module containing the new method to use.
- Returns
Full deprecation warning message for the indicated method.
- Return type
str
-
hvac.utils.
generate_property_deprecation_message
(to_be_removed_in_version, old_name, new_name, new_attribute, module_name='Client')[source]ΒΆ Generate a message to be used when warning about the use of deprecated properties.
- Parameters
to_be_removed_in_version (str) β Version of this module the deprecated property will be removed in.
old_name (str) β Deprecated property name.
new_name (str) β Name of the new property name to use.
new_attribute (str) β The new attribute where the new property can be found.
module_name (str) β Name of the module containing the new method to use.
- Returns
Full deprecation warning message for the indicated property.
- Return type
str
-
hvac.utils.
get_token_from_env
()[source]ΒΆ Get the token from env var, VAULT_TOKEN. If not set, attempt to get the token from, ~/.vault-token
- Returns
The vault token if set, else None
- Return type
str | None
-
hvac.utils.
getattr_with_deprecated_properties
(obj, item, deprecated_properties)[source]ΒΆ Helper method to use in the getattr method of a class with deprecated properties.
- Parameters
obj (object) β Instance of the Class containing the deprecated properties in question.
item (str) β Name of the attribute being requested.
deprecated_properties (List[dict]) β List of deprecated properties. Each item in the list is a dict with at least a βto_be_removed_in_versionβ and βclient_propertyβ key to be used in the displayed deprecation warning.
- Returns
The new property indicated where available.
- Return type
object
-
hvac.utils.
list_to_comma_delimited
(list_param)[source]ΒΆ Convert a list of strings into a comma-delimited list / string.
- Parameters
list_param (list) β A list of strings.
- Returns
Comma-delimited string.
- Return type
str
-
hvac.utils.
raise_for_error
(method, url, status_code, message=None, errors=None)[source]ΒΆ Helper method to raise exceptions based on the status code of a response received back from Vault.
- Parameters
method (str) β HTTP method of a request to Vault.
url (str) β URL of the endpoint requested in Vault.
status_code (int) β Status code received in a response from Vault.
message (str) β Optional message to include in a resulting exception.
errors (list | str) β Optional errors to include in a resulting exception.
- Raises
hvac.exceptions.InvalidRequest | hvac.exceptions.Unauthorized | hvac.exceptions.Forbidden | hvac.exceptions.InvalidPath | hvac.exceptions.RateLimitExceeded | hvac.exceptions.InternalServerError | hvac.exceptions.VaultNotInitialized | hvac.exceptions.BadGateway | hvac.exceptions.VaultDown | hvac.exceptions.UnexpectedError
-
hvac.utils.
remove_nones
(params)[source]ΒΆ Removes None values from optional arguments in a parameter dictionary.
- Parameters
params (dict) β The dictionary of parameters to be filtered.
- Returns
A filtered copy of the parameter dictionary.
- Return type
dict
-
hvac.utils.
validate_list_of_strings_param
(param_name, param_argument)[source]ΒΆ Validate that an argument is a list of strings.
- Parameters
param_name (str | unicode) β The name of the parameter being validated. Used in any resulting exception messages.
param_argument (list) β The argument to validate.
- Returns
True if the argument is validated, False otherwise.
- Return type
bool
-
hvac.utils.
validate_pem_format
(param_name, param_argument)[source]ΒΆ Validate that an argument is a PEM-formatted public key or certificate
- Parameters
param_name (str | unicode) β The name of the parameter being validate. Used in any resulting exception messages.
param_argument (str | unicode) β The argument to validate
- Returns
True if the argument is validate False otherwise
- Return type
bool