o |nh{C@sddlZddlZddlmZddlmZmZmZm Z ddl m Z m Z m Z mZmZmZzddlZdZWn ey=dZYnweZefeddd d ed ed ejd ejdedef ddZGdddZdS)N)warn)adaptersapi exceptionsutils) DEFAULT_URLDEPRECATED_PROPERTIES VAULT_CACERT VAULT_CAPATHVAULT_CLIENT_CERTVAULT_CLIENT_KEYTFwrite write_data)posvaluemethodreplacement_methoddictmemberdefaultrrrc Csz||}Wn!ty(|tur|YS|tur|YSt|d|dw|tur7t|d|dt|d|d|d|d|d td d |S) Nz.() missing one required positional argument: ''z%() got multiple values for argument 'z () argument 'za' was supplied as a keyword argument and will not be written as data. To write this data with a 'z' key, use the z() method. To continue using z() and suppress this warning, supply this argument positionally. For more information see: https://github.com/hvac/hvac/issues/1034 stacklevel)popKeyError _sentinel TypeErrorrDeprecationWarning)rrrrrrvaluer;/usr/local/lib/python3.10/dist-packages/hvac/v1/__init__.py _smart_pops2     r!c @seZdZdZddddddddejdf ddZddZed d Z e j d d Z ed d Z e j dd Z eddZ e j ddZ eddZ e j ddZ eddZej ddZeddZeddZeddZeddZed d!Zed"d#Zed$d%Zed&d'ZdJd(d)Zd*d+Zejd,ed-ejed.ejeejffd/d0Zd1ed.ejeejffd2d0Zddd3d,ed4ejejeejfd-ejefd5d6Z d7d8Z!dKd:d;Z"dLdd?Z$dNd@dAZ%dKdBdCZ&dDdEZ'dFdGZ(dOdHdIZ)dS)PClientz,The hvac Client class for HashiCorp's Vault.NTc Ks|dur|nt}|r|ntdt}|durtrttf}|dur.tr&t}tr*t}|s.d}| d||||||||| d | |_ t j |j d|_ t j |j d|_t j|j d|_dS)aoCreates a new hvac client instance. :param url: Base URL for the Vault instance being addressed. :type url: str :param token: Authentication token to include in requests sent to Vault. :type token: str :param cert: Certificates for use in requests sent to the Vault instance. This should be a tuple with the certificate and then key. :type cert: tuple :param verify: 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. :type verify: Union[bool,str] :param timeout: The timeout value for requests sent to Vault. :type timeout: int :param proxies: Proxies to use when performing requests. See: http://docs.python-requests.org/en/master/user/advanced/#proxies :type proxies: dict :param allow_redirects: Whether to follow redirects when sending requests to Vault. :type allow_redirects: bool :param session: Optional session object to use when performing request. :type session: request.Session :param adapter: Optional class to be used for performing requests. If none is provided, defaults to hvac.adapters.JSONRequest. :type adapter: hvac.adapters.Adapter :param kwargs: Additional parameters to pass to the adapter constructor. :type kwargs: dict :param namespace: Optional Vault Namespace. :type namespace: str N VAULT_ADDRT) base_uritokencertverifytimeoutproxiesallow_redirectssession namespace)adapterr)rget_token_from_envosgetenvrr r r r _adapterr AuthMethods_authSecretsEngines_secrets SystemBackend_sys) selfurlr&r'r(r)r*r+r,r.r-kwargsrrr __init__Es:,  zClient.__init__cCstj||tdS)N)objitemdeprecated_properties)r"getattr_with_deprecated_propertiesr)r9namerrr __getattr__szClient.__getattr__cC|jS)z%Adapter for all client's connections.)r2r9rrr r.szClient.adaptercCs"||_||j_||j_||j_dSN)r2r4r.r6r8)r9r.rrr r.s cC|jjSrEr2r%rDrrr r:z Client.urlcC ||j_dSrErG)r9r:rrr r: cCrFrEr2r&rDrrr r&rHz Client.tokencCrIrErKr9r&rrr r&rJcCrFrEr2r,rDrrr r,rHzClient.sessioncCrIrErM)r9r,rrr r,rJcCrFrEr2r+rDrrr r+rHzClient.allow_redirectscCrIrErN)r9r+rrr r+rJcCrC)zAccessor for the Client instance's auth methods. Provided via the :py:class:`hvac.api.AuthMethods` class. :return: This Client instance's associated Auth instance. :rtype: hvac.api.AuthMethods )r4rDrrr authsz Client.authcCrC)zAccessor for the Client instance's secrets engines. Provided via the :py:class:`hvac.api.SecretsEngines` class. :return: This Client instance's associated SecretsEngines instance. :rtype: hvac.api.SecretsEngines )r6rDrrr secretsszClient.secretscCrC)zAccessor for the Client instance's system backend methods. Provided via the :py:class:`hvac.api.SystemBackend` class. :return: This Client instance's associated SystemBackend instance. :rtype: hvac.api.SystemBackend )r8rDrrr syssz Client.syscC |jSrE)rQread_root_generation_progressrDrrr generate_root_status zClient.generate_root_statuscCs|jdS)zGET /sys/key-status :return: Information about the current encryption key used by Vault. :rtype: dict data)rQget_encryption_key_statusrDrrr key_statusszClient.key_statuscCrRrE)rQread_rekey_progressrDrrr rekey_statusrUzClient.rekey_statuscCrR)zRead the high availability status and current leader instance of Vault. :return: The JSON response returned by read_leader_status() :rtype: dict )rQread_leader_statusrDrrr ha_statuss zClient.ha_statuscCrR)aRead the seal status of the Vault. This is an unauthenticated endpoint. Supported methods: GET: /sys/seal-status. Produces: 200 application/json :return: The JSON response of the request. :rtype: dict )rQread_seal_statusrDrrr seal_statuss zClient.seal_statuscCs0z |jjd||dWStjyYdSw)zGET / :param path: :type path: :param wrap_ttl: :type wrap_ttl: :return: :rtype: /v1/wrap_ttlNr2getr InvalidPath)r9pathrarrr reads  z Client.readcCs8zddi}|jjd||dWStjyYdSw)ziGET /?list=true :param path: :type path: :return: :rtype: listTr_)paramsNrb)r9repayloadrrr rgs z Client.listrerar;cKsdSrEr)r9rerar;rrr r ,sz Client.writeargscOsz|d}Wn tyt}Ynwt|d|d}z|d}Wn ty*t}Ynwt|dd|d}d|vr>td td d |j|||d S) aPOST / Write data to a path. Because this method uses kwargs for the data to write, "path" and "wrap_ttl" data keys cannot be used. If these names are needed, or if the key names are not known at design time, consider using the write_data method. :param path: :type path: str :param wrap_ttl: :type wrap_ttl: str | None :param kwargs: :type kwargs: dict :return: :rtype: rre)rraN)rrrVzwrite() argument 'data' was supplied as a keyword argument. In v3.0.0 the 'data' key will be treated specially. Consider using the write_data() method instead. For more information see: https://github.com/hvac/hvac/issues/1034r)rarV) IndexErrorrr!rPendingDeprecationWarningr)r9rjr;rerarrr r 0s&     )rVrarVcCs|jjd|||dS)aIWrite data to a path. Similar to write() without restrictions on data keys. Supported methods: POST / :param path: :type path: str :param data: :type data: dict | None :param wrap_ttl: :type wrap_ttl: str | None :return: :rtype: r_jsonrar2post)r9rerVrarrr r[szClient.write_datacCs|jd|dS)zbDELETE / :param path: :type path: :return: :rtype: r_N)r2delete)r9rerrr rsrsz Client.deleteFcCsPz |jj|ddd}Wn tjyYdSw|r&ts!tdt|}|S)alRetrieve the policy body for the named policy. :param name: The name of the policy to retrieve. :type name: str | unicode :param parse: Specifies whether to parse the policy body using pyhcl or not. :type parse: bool :return: The (optionally parsed) policy body for the specified policy. :rtype: str | dict )rArVrulesNz$pyhcl is required for policy parsing)rQ read_policyrrdhas_hcl_parser ImportErrorhclloads)r9rAparsepolicyrrr get_policy|s  zClient.get_policycCsVd|i}d|i}|r!|rd}|jj|||dSd}|jj||dSd}|jj||dS) aDGET /auth/token/lookup/ GET /auth/token/lookup-accessor/ GET /auth/token/lookup-self :param token: :type token: str. :param accessor: :type accessor: str. :param wrap_ttl: :type wrap_ttl: int. :return: :rtype: r&accessorz/v1/auth/token/lookup-accessorroz/v1/auth/token/lookuprpz/v1/auth/token/lookup-selfr`)r2rrrc)r9r&r}ra token_paramaccessor_paramrerrr lookup_tokenszClient.lookup_tokencCsr|r |r d}t||rd|i}|jjd|ddS|r+d|i}|jjd|ddSd|i}|jjd|ddS) aPOST /auth/token/revoke POST /auth/token/revoke-orphan POST /auth/token/revoke-accessor :param token: :type token: :param orphan: :type orphan: :param accessor: :type accessor: :return: :rtype: zDrevoke_token does not support 'orphan' and 'accessor' flags togetherr}z/v1/auth/token/revoke-accessorr~r&z/v1/auth/token/revoke-orphanz/v1/auth/token/revokeN)rInvalidRequestr2rr)r9r&orphanr}msgrhrrr revoke_tokens zClient.revoke_tokencCs"d|i}||d<|jjd||dS)axPOST /auth/token/renew POST /auth/token/renew-self :param token: :type token: :param increment: :type increment: :param wrap_ttl: :type wrap_ttl: :return: :rtype: For calls expecting to hit the renew-self endpoint please use the "renew_self" method on "hvac_client.auth.token" instead incrementr&z/v1/auth/token/renewrorq)r9r&rrarhrrr renew_tokens zClient.renew_tokencCs|r|jjd|_dS)zClears the token used for authentication, optionally revoking it before doing so. :param revoke_token: :type revoke_token: :return: :rtype: N)rOr& revoke_self)r9rrrr logouts  z Client.logoutcCsX|jsdSz|WdStjyYdStjy!YdStjy+YdSw)znHelper method which returns the authentication status of the client :return: :rtype: FT)r&rr ForbiddenrdrrDrrr is_authenticatedszClient.is_authenticatedcCs||_|dS)aPerform a login request with a wrapped token. Stores the unwrapped token in the resulting Vault response for use by the :py:meth:`hvac.adapters.Adapter` instance under the _adapter Client attribute. :param token: Wrapped token :type token: str | unicode :return: The (JSON decoded) response of the auth request :rtype: dict z/v1/sys/wrapping/unwrap)r&loginrLrrr auth_cubbyhole s zClient.auth_cubbyholecKs|jjd||d|S)ahPerform 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 :py:meth:`hvac.adapters.Adapter` instance under the _adapter Client attribute. :param url: Path to send the authentication request to. :type url: str | unicode :param use_token: if True, uses the token in the response received from the auth request to set the "token" attribute on the the :py:meth:`hvac.adapters.Adapter` instance under the _adapter Client attribute. :type use_token: bool :param kwargs: Additional keyword arguments to include in the params sent with the request. :type kwargs: dict :return: The response of the auth request. :rtype: requests.Response )r: use_tokenNr)r2r)r9r:rr;rrr rsz Client.loginrE)F)NFN)FF)NN)T)*__name__ __module__ __qualname____doc__r JSONAdapterr<rBpropertyr.setterr:r&r,r+rOrPrQrTrXrZr\r^rfrgtoverloadstrOptionalDictAnyr rrsr|rrrrrrrrrrr r"Bs U                   */   !   r")r0typingrwarningsrhvacrrrrhvac.constants.clientrrr r r r rxrvrwobjectrrrrr!r"rrrr s>     %