o |nh|O@s@dZddlZddlmZmZddlmZdZGdddeZdS)zKvV2 methods module.N) exceptionsutils) VaultApiBasesecretc@seZdZdZdddefddZefddZedfd d Zdedfd d Zdefd dZ efddZ efddZ efddZ efddZ efddZefddZefddZdddedfddZefdd ZdS)!KvV2znKV Secrets Engine - Version 2 (API). Reference: https://www.vaultproject.io/api/secret/kv/kv-v2.html N0scCs8||d}|dur ||d<tjd|d}|jj||dS)a8Configure backend level settings that are applied to every key in the key-value store. Supported methods: POST: /{mount_point}/config. Produces: 204 (empty body) :param max_versions: The number of versions to keep per key. This value applies to all keys, but a key's metadata setting can overwrite this value. Once a key has more than the configured allowed versions the oldest version will be permanently deleted. Defaults to 10. :type max_versions: int :param cas_required: If true all keys will require the cas parameter to be set on all write requests. :type cas_required: bool :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :param delete_version_after: Specifies the length of time before a version is deleted. Accepts Go duration format string. Defaults to "0s" (i.e., disabled). :type delete_version_after: str :return: The response of the request. :rtype: requests.Response ) max_versionsdelete_version_afterN cas_required/v1/{mount_point}/config mount_pointurljsonr format_url_adapterpost)selfr r r rparamsapi_pathrI/usr/local/lib/python3.10/dist-packages/hvac/api/secrets_engines/kv_v2.py configureszKvV2.configurecCstjd|d}|jj|dS)aQRead the KV Version 2 configuration. Supported methods: GET: /auth/{mount_point}/config. Produces: 200 application/json :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The JSON response of the request. :rtype: dict r r rrrrget)rrrrrrread_configuration9s  zKvV2.read_configurationcCs|j|||dS)aRetrieve the secret at the specified location. Equivalent to calling read_secret_version with version=None. Supported methods: GET: /{mount_point}/data/{path}. Produces: 200 application/json :param path: Specifies the path of the secret to read. This is specified as part of the URL. :type path: str | unicode :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :param raise_on_deleted_version: Changes the behavior when the requested version is deleted. If True an exception will be raised. If False, some metadata about the deleted secret is returned. If None (pre-v3), a default of True will be used and a warning will be issued. :type raise_on_deleted_version: bool :return: The JSON response of the request. :rtype: dict )rraise_on_deleted_version)read_secret_version)rpathrr rrr read_secretKs zKvV2.read_secretc Cs|durd}tj|tddd}i}|dur||d<tjd||d}z |jj||d WStjyc}z+|s^z|j durQ|j d d d d krS|j WWYd}~SWWt y]Ywd}~ww)aRetrieve the secret at the specified location, with the specified version. Supported methods: GET: /{mount_point}/data/{path}. Produces: 200 application/json :param path: Specifies the path of the secret to read. This is specified as part of the URL. :type path: str | unicode :param version: Specifies the version to return. If not set the latest version is returned. :type version: int :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :param raise_on_deleted_version: Changes the behavior when the requested version is deleted. If True an exception will be raised. If False, some metadata about the deleted secret is returned. If None (pre-v3), a default of True will be used and a warning will be issued. :type raise_on_deleted_version: bool :return: The JSON response of the request. :rtype: dict NaThe raise_on_deleted_version parameter will change its default value to False in hvac v3.0.0. The current default of True will presere previous behavior. To use the old behavior with no warning, explicitly set this value to True. See https://github.com/hvac/hvac/pull/907)messagecategory stacklevelTversion/v1/{mount_point}/data/{path}rr")rrdatametadata deletion_time) warningswarnDeprecationWarningrrrrr InvalidPathrKeyError) rr"r(rr msgrrerrrr!hsJ  zKvV2.read_secret_versioncCs>i|d}|dur||dd<tjd||d}|jj||dS)akCreate a new version of a secret at the specified location. If the value does not yet exist, the calling token must have an ACL policy granting the create capability. If the value already exists, the calling token must have an ACL policy granting the update capability. Supported methods: POST: /{mount_point}/data/{path}. Produces: 200 application/json :param path: Path :type path: str | unicode :param cas: Set the "cas" value to use a Check-And-Set operation. If not set the write will be allowed. If set to 0 a write will only be allowed if the key doesn't exist. If the index is non-zero the write will only be allowed if the key's current version matches the version specified in the cas parameter. :type cas: int :param secret: The contents of the "secret" dict will be stored and returned on read. :type secret: dict :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The JSON response of the request. :rtype: dict )optionsr+Nr6casr)r*rr)rr"rr7rrrrrrcreate_or_update_secrets zKvV2.create_or_update_secretcCsjz |j||d}Wntjytdj|dw|dd}|||j||ddd||dS)aSet or update data in the KV store without overwriting. :param path: Path :type path: str | unicode :param secret: The contents of the "secret" dict will be stored and returned on read. :type secret: dict :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The JSON response of the create_or_update_secret request. :rtype: dict )r"rz>No value found at "{path}"; patch only works on existing data.)r"r+r,r()r"r7rr)r!rr2formatupdater8)rr"rrcurrent_secret_versionpatched_secretrrrpatchs(    z KvV2.patchcCtjd||d}|jj|dS)aIssue a soft delete of the secret's latest version at the specified location. This marks the version as deleted and will stop it from being returned from reads, but the underlying data will not be removed. A delete can be undone using the undelete path. Supported methods: DELETE: /{mount_point}/data/{path}. Produces: 204 (empty body) :param path: Specifies the path of the secret to delete. This is specified as part of the URL. :type path: str | unicode :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The response of the request. :rtype: requests.Response r)r*rrrrdeleterr"rrrrrdelete_latest_version_of_secrets z$KvV2.delete_latest_version_of_secretcCTt|tr t|dkrdj|d}t|d|i}tjd||d}|jj ||dS)aIssue a soft delete of the specified versions of the secret. This marks the versions as deleted and will stop them from being returned from reads, but the underlying data will not be removed. A delete can be undone using the undelete path. Supported methods: POST: /{mount_point}/delete/{path}. Produces: 204 (empty body) :param path: Specifies the path of the secret to delete. This is specified as part of the URL. :type path: str | unicode :param versions: The versions to be deleted. The versioned data will not be deleted, but it will no longer be returned in normal get requests. :type versions: int :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The response of the request. :rtype: requests.Response r]argument to "versions" must be a list containing one or more integers, "{versions}" provided.versionsrFz/v1/{mount_point}/delete/{path}r*r isinstancelistlenr9rParamValidationErrorrrrrrr"rFr error_msgrrrrrdelete_secret_versionss zKvV2.delete_secret_versionscCrC)aUndelete the data for the provided version and path in the key-value store. This restores the data, allowing it to be returned on get requests. Supported methods: POST: /{mount_point}/undelete/{path}. Produces: 204 (empty body) :param path: Specifies the path of the secret to undelete. This is specified as part of the URL. :type path: str | unicode :param versions: The versions to undelete. The versions will be restored and their data will be returned on normal get requests. :type versions: list of int :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The response of the request. :rtype: requests.Response rrDrErFz!/v1/{mount_point}/undelete/{path}r*rrGrLrrrundelete_secret_versions4s zKvV2.undelete_secret_versionscCrC)aPermanently remove the specified version data and numbers for the provided path from the key-value store. Supported methods: POST: /{mount_point}/destroy/{path}. Produces: 204 (empty body) :param path: Specifies the path of the secret to destroy. This is specified as part of the URL. :type path: str | unicode :param versions: The versions to destroy. Their data will be permanently deleted. :type versions: list of int :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The response of the request. :rtype: requests.Response rrDrErFz /v1/{mount_point}/destroy/{path}r*rrGrLrrrdestroy_secret_versionsWs zKvV2.destroy_secret_versionscCr>)aReturn a list of key names at the specified location. Folders are suffixed with /. The input must be a folder; list on a file will not return a value. Note that no policy-based filtering is performed on keys; do not encode sensitive information in key names. The values themselves are not accessible via this command. Supported methods: LIST: /{mount_point}/metadata/{path}. Produces: 200 application/json :param path: Specifies the path of the secrets to list. This is specified as part of the URL. :type path: str | unicode :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The JSON response of the request. :rtype: dict !/v1/{mount_point}/metadata/{path}r*r)rrrrIrArrr list_secretsys zKvV2.list_secretscCr>)aRetrieve the metadata and versions for the secret at the specified path. Supported methods: GET: /{mount_point}/metadata/{path}. Produces: 200 application/json :param path: Specifies the path of the secret to read. This is specified as part of the URL. :type path: str | unicode :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The JSON response of the request. :rtype: dict rQr*rrrArrrread_secret_metadatas zKvV2.read_secret_metadatac Csd|i}|dur ||d<|dur&t|ts"djt|d}t|||d<|dur@t|ts)a@Delete (permanently) the key metadata and all version data for the specified key. All version history will be removed. Supported methods: DELETE: /{mount_point}/metadata/{path}. Produces: 204 (empty body) :param path: Specifies the path of the secret to delete. This is specified as part of the URL. :type path: str | unicode :param mount_point: The "path" the secret engine was mounted on. :type mount_point: str | unicode :return: The response of the request. :rtype: requests.Response rQr*rr?rArrr delete_metadata_and_all_versionss z%KvV2.delete_metadata_and_all_versions)__name__ __module__ __qualname____doc__DEFAULT_MOUNT_POINTrrr#r!r8r=rBrNrOrPrRrSrXrYrrrrr s< '   C ( %  % # "  Ar) r]r/hvacrrhvac.api.vault_api_baserr^rrrrrs