hvac.utils¶
Misc utility functions and constants
-
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.
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
(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: - 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.VaultDown | hvac.exceptions.UnexpectedError
-
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