o
    gZh                    @   sH   d dl Zd dlmZ ddlmZ ddlmZmZm	Z	 G dd deZ
dS )    N)ObjectApiResponse   )NamespacedClient)SKIP_IN_PATH_quote_rewrite_parametersc                   @   s(  e Zd Zedddddddddddejdef deje deje d	ejejeej	e f  d
eje deje deje deje de
ej fddZe ddddddeje d	ejejeej	e f  d
eje deje de
ej f
ddZeddddddddddddeje deje d	ejejeej	e f  d
eje deje deje deje dejejdeef  de
ej fddZe ddddddejeej	e f deje d	ejejeej	e f  d
eje deje de
ej fddZe ddddddedeje d	ejejeej	e f  d
eje deje de
ej fddZe dddddd d!ejeej	e f deje d	ejejeej	e f  d
eje deje d"ejej	e  de
ej fd#d$Ze dddddd%ejeej	e f deje d	ejejeej	e f  d
eje deje de
ej fd&d'Ze dddddd(ed)ed%ejeej	e f deje d	ejejeej	e f  d
eje deje de
ej fd*d+Zedddddddddddd,	deje d-ejejd.d/ef  d	ejejeej	e f  d
eje d0ejejeejf  d%eje deje dejejdeef  d1ejejeejeejf f  de
ej fd2d3Ze ddddddd4d(ed)ed%eje deje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fd5d6Ze dddddd7ded%ejeej	e f deje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fd8d9Ze dddddd7d%edeje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fd:d;Ze dddddd7d%edeje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fd<d=Ze dddddd7d(ed)ed%edeje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fd>d?Ze dddddd7dedeje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fd@dAZe dddddd7dedeje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fdBdCZe dddddd7dDedeje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fdEdFZe dddddd7dedeje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fdGdHZe dddddd7dDedeje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fdIdJZe ddddddeje d	ejejeej	e f  d
eje deje de
ej f
dKdLZ e ddddddeje d	ejejeej	e f  d
eje deje de
ej f
dMdNZ!e dddddddddddO
deje d	ejejeej	e f  d
eje dPeje d%eje dQeje deje dReje deje dSeje de
ej fdTdUZ"e ddddddeje d	ejejeej	e f  d
eje deje de
ej f
dVdWZ#e dddddddXdeje d%ejejeej	e f  deje d	ejejeej	e f  d
eje deje de
ej fdYdZZ$e dddddd[d%ejejeej	e f  deje d	ejejeej	e f  d
eje deje de
ej fd\d]Z%e dddddd[d%ejejeej	e f  deje d	ejejeej	e f  d
eje deje de
ej fd^d_Z&e ddddddd`d(eje d)eje deje d	ejejeej	e f  d
eje deje de
ej fdadbZ'e dddddd(ed)edeje d	ejejeej	e f  d
eje deje de
ej fdcddZ(eddddddddddddde
deje d	ejejeej	e f  dejejdfef  d
eje dgeje deje deje dheje dieje deje de
ej fdjdkZ)e dddddddldejejeej	e f  deje d	ejejeej	e f  d
eje deje dmeje de
ej fdndoZ*e ddddddddpdeje deje d	ejejeej	e f  d
eje deje dqeje dejejdef  de
ej fdrdsZ+e ddddddtdDejeej	e f duejejeej	e f  deje d	ejejeej	e f  d
eje deje de
ej fdvdwZ,eddxhdydddddddddzdxejeejf dejdef deje deje d	ejejeej	e f  d
eje deje deje d{eje deje de
ej fd|d}Z-eddddddddddd~deje dejej	ejeejf   dejej	ejdef   deje d	ejejeej	e f  d
eje dejej	ejeejf   deje de
ej fddZ.eddddddddejeejf dej	e deje d	ejejeej	e f  d
eje deje de
ej fddZ/eddddddddddddd
deje d	ejejeej	e f  d
eje dPeje dejej	e  d%eje dQeje deje dReje deje de
ej fddZ0eddddddddddddeje d	ejejeej	e f  d
eje deje dReje dheje deje deje de
ej fddZ1edddddddd7dejeejeejeejf f f deje d	ejejeej	e f  d
eje deje dejejdeef  de
ej fddZ2edddiddddddddddddddd%edejej	ejeejf   dejej	ejdef   deje d	ejejeej	e f  dejejeejf  d
eje dejej	ejeejf   d0ejejeejf  deje dejejdeef  d{ejej	e  dejejeejf  de
ej fddZ3eddddddddddddddd%edeje deje d	ejejeej	e f  d
eje d0ejejeejf  deje dejejdeef  dejej	ejeejf   dejej	e  dejejeejf  d{ejej	e  de
ej fddZ4eddddddddddddddddedejejdef  deje deje d	ejejeej	e f  dejejdef  d
eje d0ejejeejf  deje deje deje dejejdeef  dejej	e  de
ej fddZ5edddidddddddddddd
deje d	ejejeej	e f  deje6 d
eje deje dejejeejf  dejej	ejdee7e6eejf   deje6 dejejej	ejeejeejf f  ejeejeejf f f  dSeje de
ej fddZ8edddddddddedejeej	e f deje d	ejejeej	e f  d
eje deje deje de
ej fddZ9eddddddddddejeej	e f dedeje deje d	ejejeej	e f  d
eje deje deje de
ej fddZ:eddddddddddedeje deje d	ejejeej	e f  d
eje deje deje de
ej fddZ;edddddddddedeje d	ejejeej	e f  d
eje deje dheje de
ej fddZ<edddddddddddeje deje d	ejejeej	e f  d
eje deje deje deje de
ej fddĄZ=e ddddddRedeje d	ejejeej	e f  d
eje deje de
ej fddƄZ>edddddddddddǜduejejeej	e f  deje d	ejejeej	e f  dejejeejf  d
eje d%eje deje deje6 de
ej fddʄZ?eddddddddd˜dPedeje d	ejejeej	e f  d
eje d0ejejeejf  deje d1ejejeejeejf f  de
ej fdd̈́Z@eddddddddddddΜ	dDeduejejeejf  deje d	ejejeej	e f  d
eje deje6 deje6 dejejeejf  deje dejejdeef  de
ej fddӄZAdS )SecurityClientT)body_fieldsN)access_tokenerror_tracefilter_pathhumanpasswordprettyusername
grant_typez%t.Literal['access_token', 'password']r
   r   r   r   r   r   r   returnc                C   s   |du rt dd}	i }
i }|dur||
d< |dur||
d< |dur&||d< |dur.||d< |dur6||d< |dur>||
d	< |durF||d
< |durN||
d< ddd}| jd|	|||
dS )a.  
        Creates or updates the user profile on behalf of another user.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-activate-user-profile.html>`_

        :param grant_type:
        :param access_token:
        :param password:
        :param username:
        N-Empty value passed for parameter 'grant_type'z/_security/profile/_activater   r
   r   r   r   r   r   r   application/jsonacceptcontent-typePOSTparamsheadersbody
ValueErrorperform_request)selfr   r
   r   r   r   r   r   r   _SecurityClient__path_SecurityClient__body_SecurityClient__query_SecurityClient__headers r%   Z/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/security.pyactivate_user_profile   s2   

z$SecurityClient.activate_user_profile)r   r   r   r   c                C   b   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< ddi}| j d	|||d
S )z
        Enables authentication as a user and retrieve information about the authenticated
        user.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-authenticate.html>`_
        z/_security/_authenticateNr   r   r   r   r   r   GETr   r   r   r    r   r   r   r   r!   r#   r$   r%   r%   r&   authenticateN      zSecurityClient.authenticate)r   r   r   r   r   password_hashr   refreshr/   r0   z&t.Literal['false', 'true', 'wait_for']c                C   s   |t vrdt| d}	nd}	i }
i }|dur||
d< |dur#||
d< |dur+||
d< |dur3||d< |dur;||d	< |durC||
d
< |durK||
d< ddd}| jd|	|
||dS )a  
        Changes the passwords of users in the native realm and built-in users.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-change-password.html>`_

        :param username: The user whose password you want to change. If you do not specify
            this parameter, the password is changed for the current user.
        :param password: The new password value. Passwords must be at least 6 characters
            long.
        :param password_hash: A hash of the new password value. This must be produced
            using the same hashing algorithm as has been configured for password storage.
            For more details, see the explanation of the `xpack.security.authc.password_hashing.algorithm`
            setting.
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        /_security/user/z
/_passwordz/_security/user/_passwordNr   r   r   r   r/   r   r0   r   r   PUTr   r   r   r   )r    r   r   r   r   r   r/   r   r0   r!   r#   r"   r$   r%   r%   r&   change_passwordl   s.   "

zSecurityClient.change_passwordidsc          	      C   ~   |t v rtddt| d}i }|dur||d< |dur"||d< |dur*||d< |dur2||d< d	d
i}| jd|||dS )ah  
        Clear a subset or all entries from the API key cache.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-clear-api-key-cache.html>`_

        :param ids: Comma-separated list of API key IDs to evict from the API key cache.
            To evict all API keys, use `*`. Does not support other wildcard patterns.
        &Empty value passed for parameter 'ids'/_security/api_key//_clear_cacheNr   r   r   r   r   r   r   r*   r   r   r   r   )	r    r5   r   r   r   r   r!   r#   r$   r%   r%   r&   clear_api_key_cache   s    z"SecurityClient.clear_api_key_cacheapplicationc          	      C   r6   )a  
        Evicts application privileges from the native application privileges cache.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-clear-privilege-cache.html>`_

        :param application: A comma-separated list of application names
        .Empty value passed for parameter 'application'/_security/privilege/r9   Nr   r   r   r   r   r   r   r*   r:   )	r    r<   r   r   r   r   r!   r#   r$   r%   r%   r&   clear_cached_privileges       z&SecurityClient.clear_cached_privileges)r   r   r   r   	usernamesrealmsrA   c          
      C      |t v rtddt| d}i }|dur||d< |dur"||d< |dur*||d< |dur2||d< |dur:||d	< d
di}	| jd|||	dS )ap  
        Evicts users from the user cache. Can completely clear the cache or evict specific
        users.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-clear-cache.html>`_

        :param realms: Comma-separated list of realms to clear
        :param usernames: Comma-separated list of usernames to clear from the cache
        z)Empty value passed for parameter 'realms'z/_security/realm/r9   Nr   r   r   r   rA   r   r   r   r*   r:   )
r    rB   r   r   r   r   rA   r!   r#   r$   r%   r%   r&   clear_cached_realms   s$   z"SecurityClient.clear_cached_realmsnamec          	      C   r6   )z
        Evicts roles from the native role cache.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-clear-role-cache.html>`_

        :param name: Role name
        'Empty value passed for parameter 'name'/_security/role/r9   Nr   r   r   r   r   r   r   r*   r:   	r    rE   r   r   r   r   r!   r#   r$   r%   r%   r&   clear_cached_roles  r@   z!SecurityClient.clear_cached_roles	namespaceservicec                C   s   |t v rtd|t v rtd|t v rtddt| dt| dt| d}i }	|dur4||	d	< |dur<||	d
< |durD||	d< |durL||	d< ddi}
| jd||	|
dS )aw  
        Evicts tokens from the service account token caches.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-clear-service-token-caches.html>`_

        :param namespace: An identifier for the namespace
        :param service: An identifier for the service name
        :param name: A comma-separated list of service token names
        ,Empty value passed for parameter 'namespace'*Empty value passed for parameter 'service'rF   /_security/service///credential/token/r9   Nr   r   r   r   r   r   r   r*   r:   )r    rJ   rK   rE   r   r   r   r   r!   r#   r$   r%   r%   r&   clear_cached_service_tokens5  s(   $z*SecurityClient.clear_cached_service_tokens)	r   
expirationr   r   metadatarE   r   r0   role_descriptorsrR   zt.Literal[-1]zt.Literal[0]rS   rT   c       	         C   s   d}
i }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< |	durN|	|d< ddd}| j d|
|||dS )u  
        Creates an API key for access without requiring basic authentication.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-create-api-key.html>`_

        :param expiration: Expiration time for the API key. By default, API keys never
            expire.
        :param metadata: Arbitrary metadata that you want to associate with the API key.
            It supports nested data structure. Within the metadata object, keys beginning
            with `_` are reserved for system usage.
        :param name: Specifies the name for this API key.
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        :param role_descriptors: An array of role descriptors for this API key. This
            parameter is optional. When it is not specified or is an empty array, then
            the API key will have a point in time snapshot of permissions of the authenticated
            user. If you supply role descriptors then the resultant permissions would
            be an intersection of API keys permissions and authenticated user’s permissions
            thereby limiting the access scope for API keys. The structure of role descriptor
            is the same as the request for create role API. For more details, see create
            or update roles API.
        /_security/api_keyNr   rR   r   r   rS   rE   r   r0   rT   r   r   r2   r   r+   )r    r   rR   r   r   rS   rE   r   r0   rT   r!   r#   r"   r$   r%   r%   r&   create_api_key_  s2   )

zSecurityClient.create_api_key)rE   r   r   r   r   r0   c                C   s  |t v rtd|t v rtd|t vr0|t vr0|t vr0dt| dt| dt| }	d}
n|t vrH|t vrHdt| dt| d}	d}
ntd	i }|d
urV||d< |d
ur^||d< |d
urf||d< |d
urn||d< |d
urv||d< ddi}| j|
|	||dS )a  
        Creates a service account token for access without requiring basic authentication.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-create-service-token.html>`_

        :param namespace: An identifier for the namespace
        :param service: An identifier for the service name
        :param name: An identifier for the token name
        :param refresh: If `true` then refresh the affected shards to make this operation
            visible to search, if `wait_for` (the default) then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        rL   rM   rN   rO   rP   r2   z/credential/tokenr   z-Couldn't find a path for the given parametersNr   r   r   r   r0   r   r   r*   r:   )r    rJ   rK   rE   r   r   r   r   r0   r!   Z_SecurityClient__methodr#   r$   r%   r%   r&   create_service_token  s8   "z#SecurityClient.create_service_token)r   r   r   r   r0   c                C   s   |t v rtd|t v rtddt| dt| }i }	|dur&||	d< |dur.||	d< |dur6||	d< |dur>||	d	< |durF||	d
< ddi}
| jd||	|
dS )a  
        Removes application privileges.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-delete-privilege.html>`_

        :param application: Application name
        :param name: Privilege name
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        r=   rF   r>   rO   Nr   r   r   r   r0   r   r   DELETEr*   r:   )r    r<   rE   r   r   r   r   r0   r!   r#   r$   r%   r%   r&   delete_privileges  s(   z SecurityClient.delete_privilegesc          
      C      |t v rtddt| }i }|dur||d< |dur!||d< |dur)||d< |dur1||d< |dur9||d< d	d
i}	| jd|||	dS )a  
        Removes roles in the native realm.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-delete-role.html>`_

        :param name: Role name
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        rF   rG   Nr   r   r   r   r0   r   r   rX   r*   r:   
r    rE   r   r   r   r   r0   r!   r#   r$   r%   r%   r&   delete_role  $   zSecurityClient.delete_rolec          
      C   rZ   )a  
        Removes role mappings.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-delete-role-mapping.html>`_

        :param name: Role-mapping name
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        rF   /_security/role_mapping/Nr   r   r   r   r0   r   r   rX   r*   r:   r[   r%   r%   r&   delete_role_mapping5  r]   z"SecurityClient.delete_role_mappingc                C   s   |t v rtd|t v rtd|t v rtddt| dt| dt| }	i }
|dur3||
d< |dur;||
d	< |durC||
d
< |durK||
d< |durS||
d< ddi}| jd|	|
|dS )a^  
        Deletes a service account token.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-delete-service-token.html>`_

        :param namespace: An identifier for the namespace
        :param service: An identifier for the service name
        :param name: An identifier for the token name
        :param refresh: If `true` then refresh the affected shards to make this operation
            visible to search, if `wait_for` (the default) then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        rL   rM   rF   rN   rO   rP   Nr   r   r   r   r0   r   r   rX   r*   r:   )r    rJ   rK   rE   r   r   r   r   r0   r!   r#   r$   r%   r%   r&   delete_service_token_  s,   "z#SecurityClient.delete_service_tokenc          
      C   rZ   )a  
        Deletes users from the native realm.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-delete-user.html>`_

        :param username: username
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        +Empty value passed for parameter 'username'r1   Nr   r   r   r   r0   r   r   rX   r*   r:   
r    r   r   r   r   r   r0   r!   r#   r$   r%   r%   r&   delete_user  r]   zSecurityClient.delete_userc          
      C   rC   )a  
        Disables users in the native realm.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-disable-user.html>`_

        :param username: The username of the user to disable
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        ra   r1   	/_disableNr   r   r   r   r0   r   r   r2   r*   r:   rb   r%   r%   r&   disable_user  $   zSecurityClient.disable_useruidc          
      C   rC   )a  
        Disables a user profile so it's not visible in user profile searches.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-disable-user-profile.html>`_

        :param uid: Unique identifier for the user profile.
        :param refresh: If 'true', Elasticsearch refreshes the affected shards to make
            this operation visible to search, if 'wait_for' then wait for a refresh to
            make this operation visible to search, if 'false' do nothing with refreshes.
        &Empty value passed for parameter 'uid'/_security/profile/rd   Nr   r   r   r   r0   r   r   r2   r*   r:   
r    rg   r   r   r   r   r0   r!   r#   r$   r%   r%   r&   disable_user_profile  rf   z#SecurityClient.disable_user_profilec          
      C   rC   )a  
        Enables users in the native realm.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-enable-user.html>`_

        :param username: The username of the user to enable
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        ra   r1   /_enableNr   r   r   r   r0   r   r   r2   r*   r:   rb   r%   r%   r&   enable_user  rf   zSecurityClient.enable_userc          
      C   rC   )a  
        Enables a user profile so it's visible in user profile searches.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-enable-user-profile.html>`_

        :param uid: Unique identifier for the user profile.
        :param refresh: If 'true', Elasticsearch refreshes the affected shards to make
            this operation visible to search, if 'wait_for' then wait for a refresh to
            make this operation visible to search, if 'false' do nothing with refreshes.
        rh   ri   rl   Nr   r   r   r   r0   r   r   r2   r*   r:   rj   r%   r%   r&   enable_user_profile9  rf   z"SecurityClient.enable_user_profilec                C   r(   )z
        Allows a kibana instance to configure itself to communicate with a secured elasticsearch
        cluster.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-kibana-enrollment.html>`_
        z/_security/enroll/kibanaNr   r   r   r   r   r   r)   r*   r+   r,   r%   r%   r&   enroll_kibanac  r.   zSecurityClient.enroll_kibanac                C   r(   )z
        Allows a new node to enroll to an existing cluster with security enabled.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-node-enrollment.html>`_
        z/_security/enroll/nodeNr   r   r   r   r   r   r)   r*   r+   r,   r%   r%   r&   enroll_node  s   zSecurityClient.enroll_node)
r   r   r   idrE   ownerr   
realm_namer   with_limited_byrq   rr   rs   rt   c       
         C   s   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |	durL|	|d< |
durT|
|d< ddi}| j d|||dS )aV  
        Retrieves information for one or more API keys.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-api-key.html>`_

        :param id: An API key id. This parameter cannot be used with any of `name`, `realm_name`
            or `username`.
        :param name: An API key name. This parameter cannot be used with any of `id`,
            `realm_name` or `username`. It supports prefix search with wildcard.
        :param owner: A boolean flag that can be used to query API keys owned by the
            currently authenticated user. The `realm_name` or `username` parameters cannot
            be specified when this parameter is set to `true` as they are assumed to
            be the currently authenticated ones.
        :param realm_name: The name of an authentication realm. This parameter cannot
            be used with either `id` or `name` or when `owner` flag is set to `true`.
        :param username: The username of a user. This parameter cannot be used with either
            `id` or `name` or when `owner` flag is set to `true`.
        :param with_limited_by: Return the snapshot of the owner user's role descriptors
            associated with the API key. An API key's actual permission is the intersection
            of its assigned role descriptors and the owner user's role descriptors.
        rU   Nr   r   r   rq   rE   rr   r   rs   r   rt   r   r   r)   r*   r+   )r    r   r   r   rq   rE   rr   r   rs   r   rt   r!   r#   r$   r%   r%   r&   get_api_key  s4   $zSecurityClient.get_api_keyc                C   r(   )a   
        Retrieves the list of cluster privileges and index privileges that are available
        in this version of Elasticsearch.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-builtin-privileges.html>`_
        z/_security/privilege/_builtinNr   r   r   r   r   r   r)   r*   r+   r,   r%   r%   r&   get_builtin_privileges  r.   z%SecurityClient.get_builtin_privileges)r<   rE   r   r   r   r   c          
      C      |t vr|t vrdt| dt| }n|t vr!dt| }nd}i }|dur-||d< |dur5||d< |dur=||d< |durE||d< d	d
i}	| jd|||	dS )z
        Retrieves application privileges.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-privileges.html>`_

        :param application: Application name
        :param name: Privilege name
        r>   rO   /_security/privilegeNr   r   r   r   r   r   r)   r*   r3   )
r    r<   rE   r   r   r   r   r!   r#   r$   r%   r%   r&   get_privileges  s$   zSecurityClient.get_privileges)rE   r   r   r   r   c          	      C   z   |t vrdt| }nd}i }|dur||d< |dur ||d< |dur(||d< |dur0||d< dd	i}| jd
|||dS )am  
        Retrieves roles in the native realm.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-role.html>`_

        :param name: The name of the role. You can specify multiple roles as a comma-separated
            list. If you do not specify this parameter, the API returns information about
            all roles.
        rG   z/_security/roleNr   r   r   r   r   r   r)   r*   r3   rH   r%   r%   r&   get_role"  s    zSecurityClient.get_rolec          	      C   rz   )a:  
        Retrieves role mappings.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-role-mapping.html>`_

        :param name: The distinct name that identifies the role mapping. The name is
            used solely as an identifier to facilitate interaction via the API; it does
            not affect the behavior of the mapping in any way. You can specify multiple
            mapping names as a comma-separated list. If you do not specify this parameter,
            the API returns information about all role mappings.
        r^   z/_security/role_mappingNr   r   r   r   r   r   r)   r*   r3   rH   r%   r%   r&   get_role_mappingG  s    zSecurityClient.get_role_mapping)rJ   rK   r   r   r   r   c          
      C   rw   )a:  
        Retrieves information about service accounts.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-service-accounts.html>`_

        :param namespace: Name of the namespace. Omit this parameter to retrieve information
            about all service accounts. If you omit this parameter, you must also omit
            the `service` parameter.
        :param service: Name of the service name. Omit this parameter to retrieve information
            about all service accounts that belong to the specified `namespace`.
        rN   rO   z/_security/serviceNr   r   r   r   r   r   r)   r*   r3   
r    rJ   rK   r   r   r   r   r!   r#   r$   r%   r%   r&   get_service_accountsn  s$   z#SecurityClient.get_service_accountsc          
      C   s   |t v rtd|t v rtddt| dt| d}i }|dur'||d< |dur/||d< |dur7||d	< |dur?||d
< ddi}	| jd|||	dS )a2  
        Retrieves information of all service credentials for a service account.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-service-credentials.html>`_

        :param namespace: Name of the namespace.
        :param service: Name of the service name.
        rL   rM   rN   rO   z/credentialNr   r   r   r   r   r   r)   r*   r:   r}   r%   r%   r&   get_service_credentials  s$   z&SecurityClient.get_service_credentials)
r   r   r   r   kerberos_ticketr   r   refresh_tokenscoper   zIt.Literal['_kerberos', 'client_credentials', 'password', 'refresh_token']r   r   r   c       
         C   s   d}i }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< |	durN|	|d< |
durV|
|d< ddd}| j d||||dS )ad  
        Creates a bearer token for access without requiring basic authentication.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-token.html>`_

        :param grant_type:
        :param kerberos_ticket:
        :param password:
        :param refresh_token:
        :param scope:
        :param username:
        /_security/oauth2/tokenNr   r   r   r   r   r   r   r   r   r   r   r   r   r   r+   )r    r   r   r   r   r   r   r   r   r   r   r!   r#   r"   r$   r%   r%   r&   	get_token  s6   "

zSecurityClient.get_token)r   r   r   r   r   with_profile_uidr   c          
      C   s   |t vrdt| }nd}i }|dur||d< |dur ||d< |dur(||d< |dur0||d< |dur8||d< d	d
i}	| jd|||	dS )a  
        Retrieves information about users in the native realm and built-in users.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-user.html>`_

        :param username: An identifier for the user. You can specify multiple usernames
            as a comma-separated list. If you omit this parameter, the API retrieves
            information about all users.
        :param with_profile_uid: If true will return the User Profile ID for a user,
            if any.
        r1   z/_security/userNr   r   r   r   r   r   r   r)   r*   r3   )
r    r   r   r   r   r   r   r!   r#   r$   r%   r%   r&   get_user  s$   zSecurityClient.get_user)r<   r   r   r   r   
priviledger   r   c                C   s   d}i }	|dur||	d< |dur||	d< |dur||	d< |dur$||	d< |dur,||	d< |dur4||	d< |dur<||	d	< d
di}
| j d||	|
dS )a  
        Retrieves security privileges for the logged in user.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-user-privileges.html>`_

        :param application: The name of the application. Application privileges are always
            associated with exactly one application. If you do not specify this parameter,
            the API returns information about all privileges for all applications.
        :param priviledge: The name of the privilege. If you do not specify this parameter,
            the API returns information about all privileges for the requested application.
        :param username:
        z/_security/user/_privilegesNr<   r   r   r   r   r   r   r   r   r)   r*   r+   )r    r<   r   r   r   r   r   r   r!   r#   r$   r%   r%   r&   get_user_privileges&  s(   z"SecurityClient.get_user_privileges)datar   r   r   r   r   c          
      C   rZ   )a  
        Retrieves user profiles for the given unique ID(s).

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-get-user-profile.html>`_

        :param uid: A unique identifier for the user profile.
        :param data: List of filters for the `data` field of the profile document. To
            return all content use `data=*`. To return a subset of content use `data=<key>`
            to retrieve content nested under the specified `<key>`. By default returns
            no `data` content.
        rh   ri   Nr   r   r   r   r   r   r   r)   r*   r:   )
r    rg   r   r   r   r   r   r!   r#   r$   r%   r%   r&   get_user_profileS  s$   zSecurityClient.get_user_profileapi_key)r	   Zignore_deprecated_options)r
   r   r   r   r   r   run_asr   r   c       
         C   s   |du rt d|du rt dd}i }i }|dur||d< |dur&||d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< |durN||d< |durV||d< |	dur^|	|d< |
durf|
|d< ddd}| jd||||dS )u  
        Creates an API key on behalf of another user.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-grant-api-key.html>`_

        :param api_key: Defines the API key.
        :param grant_type: The type of grant. Supported grant types are: `access_token`,
            `password`.
        :param access_token: The user’s access token. If you specify the `access_token`
            grant type, this parameter is required. It is not valid with other grant
            types.
        :param password: The user’s password. If you specify the `password` grant type,
            this parameter is required. It is not valid with other grant types.
        :param run_as: The name of the user to be impersonated.
        :param username: The user name that identifies the user. If you specify the `password`
            grant type, this parameter is required. It is not valid with other grant
            types.
        Nz*Empty value passed for parameter 'api_key'r   z/_security/api_key/grantr   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   )r    r   r   r
   r   r   r   r   r   r   r   r!   r"   r#   r$   r%   r%   r&   grant_api_key|  s>   $

zSecurityClient.grant_api_key)userr<   clusterr   r   r   indexr   r   r   a  t.Literal['all', 'cancel_task', 'create_snapshot', 'grant_api_key', 'manage', 'manage_api_key', 'manage_ccr', 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', 'manage_watcher', 'monitor', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'read_ccr', 'read_ilm', 'read_pipeline', 'read_slm', 'transport_client']r   c                C   s   |t vrdt| d}	nd}	i }
i }|dur||
d< |dur#||
d< |dur+||d< |dur3||d< |dur;||d	< |durC||
d
< |durK||d< ddd}| jd|	|||
dS )ai  
        Determines whether the specified user has a specified list of privileges.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-has-privileges.html>`_

        :param user: Username
        :param application:
        :param cluster: A list of the cluster privileges that you want to check.
        :param index:
        r1   z/_has_privilegesz/_security/user/_has_privilegesNr<   r   r   r   r   r   r   r   r   r   r   r3   )r    r   r<   r   r   r   r   r   r   r!   r"   r#   r$   r%   r%   r&   has_privileges  s.    

zSecurityClient.has_privileges
privilegesuidsc                C   s   |du rt d|du rt dd}i }i }	|dur||d< |dur&||d< |dur.||	d< |dur6||	d< |dur>||	d	< |durF||	d
< ddd}
| jd||	|
|dS )a  
        Determines whether the users associated with the specified profile IDs have all
        the requested privileges.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-has-privileges-user-profile.html>`_

        :param privileges:
        :param uids: A list of profile IDs. The privileges are checked for associated
            users of the profiles.
        N-Empty value passed for parameter 'privileges'z'Empty value passed for parameter 'uids'z"/_security/profile/_has_privilegesr   r   r   r   r   r   r   r   r   r   r   )r    r   r   r   r   r   r   r!   r"   r#   r$   r%   r%   r&   has_privileges_user_profile  s.   

z*SecurityClient.has_privileges_user_profile)
r   r   r   rq   r5   rE   rr   r   rs   r   c       
         C   s   d}i }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< |	durN|	|d< |
durV|
|d< ddd}| j d||||dS )a+  
        Invalidates one or more API keys.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-invalidate-api-key.html>`_

        :param id:
        :param ids: A list of API key ids. This parameter cannot be used with any of
            `name`, `realm_name`, or `username`.
        :param name: An API key name. This parameter cannot be used with any of `ids`,
            `realm_name` or `username`.
        :param owner: Can be used to query API keys owned by the currently authenticated
            user. The `realm_name` or `username` parameters cannot be specified when
            this parameter is set to `true` as they are assumed to be the currently authenticated
            ones.
        :param realm_name: The name of an authentication realm. This parameter cannot
            be used with either `ids` or `name`, or when `owner` flag is set to `true`.
        :param username: The username of a user. This parameter cannot be used with either
            `ids` or `name`, or when `owner` flag is set to `true`.
        rU   Nr   r   r   rq   r5   rE   rr   r   rs   r   r   r   rX   r   r+   )r    r   r   r   rq   r5   rE   rr   r   rs   r   r!   r#   r"   r$   r%   r%   r&   invalidate_api_key(  s6   $

z!SecurityClient.invalidate_api_key)r   r   r   r   rs   r   tokenr   r   c                C   s   d}	i }
i }|dur||
d< |dur||
d< |dur||
d< |dur&||
d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< ddd}| j d|	|
||dS )a!  
        Invalidates one or more access tokens or refresh tokens.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-invalidate-token.html>`_

        :param realm_name:
        :param refresh_token:
        :param token:
        :param username:
        r   Nr   r   r   r   rs   r   r   r   r   r   rX   r   r+   )r    r   r   r   r   rs   r   r   r   r!   r#   r"   r$   r%   r%   r&   invalidate_tokenh  s.   

zSecurityClient.invalidate_token)Z	body_namec                C   s   |du rt dd}i }|dur||d< |dur||d< |dur$||d< |dur,||d< |dur4||d< |}	d	d	d
}
| jd|||
|	dS )a  
        Adds or updates application privileges.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-put-privileges.html>`_

        :param privileges:
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        Nr   rx   r   r   r   r   r0   r   r   r2   r   r   )r    r   r   r   r   r   r0   r!   r#   r"   r$   r%   r%   r&   put_privileges  s&   

zSecurityClient.put_privilegesglobalglobal_)r	   Zparameter_aliases)applicationsr   r   r   r   r   indicesrS   r   r0   r   transient_metadatar   r   r   c                C   s  |t v rtddt| }i }i }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d< |durC||d	< |durK||d
< |	durS|	|d< |
dur[|
|d< |durc||d< |durk||d< |durs||d< ddd}| jd||||dS )u  
        Adds and updates roles in the native realm.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-put-role.html>`_

        :param name: The name of the role.
        :param applications: A list of application privilege entries.
        :param cluster: A list of cluster privileges. These privileges define the cluster-level
            actions for users with this role.
        :param global_: An object defining global privileges. A global privilege is a
            form of cluster privilege that is request-aware. Support for global privileges
            is currently limited to the management of application privileges.
        :param indices: A list of indices permissions entries.
        :param metadata: Optional metadata. Within the metadata object, keys that begin
            with an underscore (`_`) are reserved for system use.
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        :param run_as: A list of users that the owners of this role can impersonate.
        :param transient_metadata: Indicates roles that might be incompatible with the
            current cluster license, specifically roles with document and field level
            security. When the cluster license doesn’t allow certain features for a given
            role, this parameter is updated dynamically to list the incompatible features.
            If `enabled` is `false`, the role is ignored, but is still listed in the
            response from the authenticate API.
        rF   rG   Nr   r   r   r   r   r   r   rS   r   r0   r   r   r   r   r2   r   r:   )r    rE   r   r   r   r   r   r   r   rS   r   r0   r   r   r!   r"   r#   r$   r%   r%   r&   put_role  sB   8

zSecurityClient.put_role)enabledr   r   r   rS   r   r0   role_templatesrolesrulesr   r   r   r   r   c                C   s   |t v rtddt| }i }i }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d< |durC||d	< |durK||d
< |	durS|	|d< |
dur[|
|d< |durc||d< |durk||d< ddd}| jd||||dS )ak  
        Creates and updates role mappings.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-put-role-mapping.html>`_

        :param name: Role-mapping name
        :param enabled:
        :param metadata:
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        :param role_templates:
        :param roles:
        :param rules:
        :param run_as:
        rF   r^   Nr   r   r   r   rS   r   r0   r   r   r   r   r   r   r2   r   r:   )r    rE   r   r   r   r   rS   r   r0   r   r   r   r   r!   r"   r#   r$   r%   r%   r&   put_role_mapping   s>   %

zSecurityClient.put_role_mapping)emailr   r   r   	full_namer   rS   r   r/   r   r0   r   r   r   c                C   s  |t v rtddt| }i }i }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d< |durC||d	< |durK||d
< |	durS|	|d< |
dur[|
|d< |durc||d< |durk||d< |durs||d< ddd}| jd||||dS )a  
        Adds and updates users in the native realm. These users are commonly referred
        to as native users.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-put-user.html>`_

        :param username: The username of the User
        :param email:
        :param enabled:
        :param full_name:
        :param metadata:
        :param password:
        :param password_hash:
        :param refresh: If `true` (the default) then refresh the affected shards to make
            this operation visible to search, if `wait_for` then wait for a refresh to
            make this operation visible to search, if `false` then do nothing with refreshes.
        :param roles:
        ra   r1   Nr   r   r   r   r   r   rS   r   r/   r   r0   r   r   r   r2   r   r:   )r    r   r   r   r   r   r   r   rS   r   r/   r   r0   r   r!   r"   r#   r$   r%   r%   r&   put_usere  sB   (

zSecurityClient.put_userfromfrom_)
r   r   r   r   r   querysearch_aftersizesortrt   r   r   r   r   c       
         C   s8  d}i }i }|	dur2t |	trd|	v s,t |	ttfr2tdd |	D r2tdd |	D r2|	|d< d}	|dur:||d< |durB||d	< |durJ||d
< |durR||d< |durZ||d< |durb||d< |durj||d< |durr||d< |	durz|	|d< |
dur|
|d< |sd}ddi}|durd|d< | jd||||dS )a  
        Retrieves information for API keys using a subset of query DSL

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-query-api-key.html>`_

        :param from_: Starting document offset. By default, you cannot page through more
            than 10,000 hits using the from and size parameters. To page through more
            hits, use the `search_after` parameter.
        :param query: A query to filter which API keys to return. The query supports
            a subset of query types, including `match_all`, `bool`, `term`, `terms`,
            `ids`, `prefix`, `wildcard`, and `range`. You can query all public information
            associated with an API key.
        :param search_after: Search after definition
        :param size: The number of hits to return. By default, you cannot page through
            more than 10,000 hits using the `from` and `size` parameters. To page through
            more hits, use the `search_after` parameter.
        :param sort: Other than `id`, all public fields of an API key are eligible for
            sorting. In addition, sort can also be applied to the `_doc` field to sort
            by index order.
        :param with_limited_by: Return the snapshot of the owner user's role descriptors
            associated with the API key. An API key's actual permission is the intersection
            of its assigned role descriptors and the owner user's role descriptors.
        z/_security/_query/api_keyN:c                 s   s    | ]}t |tV  qd S )N)
isinstancestr.0Z_xr%   r%   r&   	<genexpr>  s    z0SecurityClient.query_api_keys.<locals>.<genexpr>c                 s   s    | ]}d |v V  qdS )r   Nr%   r   r%   r%   r&   r     s    r   r   r   r   r   r   r   r   r   rt   r   r   r   r   r   )r   r   listtupleallanyr   )r    r   r   r   r   r   r   r   r   r   rt   r!   r#   r"   r$   r%   r%   r&   query_api_keys  sV   0
zSecurityClient.query_api_keys)r   r   r   r   realmcontentr   c                C   s   |du rt d|du rt dd}i }	i }
|dur||	d< |dur&||	d< |dur.||
d< |dur6||
d< |dur>||
d	< |durF||
d
< |durN||	d< ddd}| jd||
||	dS )u  
        Exchanges a SAML Response message for an Elasticsearch access token and refresh
        token pair

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-saml-authenticate.html>`_

        :param content: The SAML response as it was sent by the user’s browser, usually
            a Base64 encoded XML document.
        :param ids: A json array with all the valid SAML Request Ids that the caller
            of the API has for the current user.
        :param realm: The name of the realm that should authenticate the SAML response.
            Useful in cases where many SAML realms are defined.
        Nz*Empty value passed for parameter 'content'r7   z/_security/saml/authenticater   r5   r   r   r   r   r   r   r   r   r   r   )r    r   r5   r   r   r   r   r   r!   r"   r#   r$   r%   r%   r&   saml_authenticate
  s2   

z SecurityClient.saml_authenticate)r   r   r   r   r   query_stringr   c                C   s   |du rt d|du rt dd}	i }
i }|dur||
d< |dur&||
d< |dur.||
d< |dur6||d< |dur>||d	< |durF||d
< |durN||d< |durV||
d< ddd}| jd|	|||
dS )aY  
        Verifies the logout response sent from the SAML IdP

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-saml-complete-logout.html>`_

        :param ids: A json array with all the valid SAML Request Ids that the caller
            of the API has for the current user.
        :param realm: The name of the SAML realm in Elasticsearch for which the configuration
            is used to verify the logout response.
        :param content: If the SAML IdP sends the logout response with the HTTP-Post
            binding, this field must be set to the value of the SAMLResponse form parameter
            from the logout response.
        :param query_string: If the SAML IdP sends the logout response with the HTTP-Redirect
            binding, this field must be set to the query string of the redirect URI.
        Nr7   z(Empty value passed for parameter 'realm'z/_security/saml/complete_logoutr5   r   r   r   r   r   r   r   r   r   r   r   r   )r    r5   r   r   r   r   r   r   r   r!   r"   r#   r$   r%   r%   r&   saml_complete_logout?  s6   

z#SecurityClient.saml_complete_logout)acsr   r   r   r   r   r   c                C   s   |du rt dd}i }	i }
|dur||	d< |dur||	d< |dur&||
d< |dur.||
d< |dur6||
d< |dur>||
d	< |durF||	d
< ddd}| jd||
||	dS )uT  
        Consumes a SAML LogoutRequest

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-saml-invalidate.html>`_

        :param query_string: The query part of the URL that the user was redirected to
            by the SAML IdP to initiate the Single Logout. This query should include
            a single parameter named SAMLRequest that contains a SAML logout request
            that is deflated and Base64 encoded. If the SAML IdP has signed the logout
            request, the URL should include two extra parameters named SigAlg and Signature
            that contain the algorithm used for the signature and the signature value
            itself. In order for Elasticsearch to be able to verify the IdP’s signature,
            the value of the query_string field must be an exact match to the string
            provided by the browser. The client application must not attempt to parse
            or process the string in any way.
        :param acs: The Assertion Consumer Service URL that matches the one of the SAML
            realm in Elasticsearch that should be used. You must specify either this
            parameter or the realm parameter.
        :param realm: The name of the SAML realm in Elasticsearch the configuration.
            You must specify either this parameter or the acs parameter.
        Nz/Empty value passed for parameter 'query_string'z/_security/saml/invalidater   r   r   r   r   r   r   r   r   r   r   r   )r    r   r   r   r   r   r   r   r!   r"   r#   r$   r%   r%   r&   saml_invalidatey  s.   #

zSecurityClient.saml_invalidate)r   r   r   r   r   c                C   s   |du rt dd}i }i }	|dur||d< |dur||	d< |dur&||	d< |dur.||	d< |dur6||	d< |dur>||d	< d
d
d}
| jd||	|
|dS )a  
        Invalidates an access token and a refresh token that were generated via the SAML
        Authenticate API

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-saml-logout.html>`_

        :param token: The access token that was returned as a response to calling the
            SAML authenticate API. Alternatively, the most recent token that was received
            after refreshing the original one by using a refresh_token.
        :param refresh_token: The refresh token that was returned as a response to calling
            the SAML authenticate API. Alternatively, the most recent refresh token that
            was received after refreshing the original access token.
        Nz(Empty value passed for parameter 'token'z/_security/saml/logoutr   r   r   r   r   r   r   r   r   r   r   )r    r   r   r   r   r   r   r!   r"   r#   r$   r%   r%   r&   saml_logout  s*   

zSecurityClient.saml_logout)r   r   r   r   r   r   relay_stater   c                C   s   d}i }	i }
|dur||	d< |dur||
d< |dur||
d< |dur&||
d< |dur.||
d< |dur6||	d< |dur>||	d	< d
d
d}| j d||
||	dS )a  
        Creates a SAML authentication request

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-saml-prepare-authentication.html>`_

        :param acs: The Assertion Consumer Service URL that matches the one of the SAML
            realms in Elasticsearch. The realm is used to generate the authentication
            request. You must specify either this parameter or the realm parameter.
        :param realm: The name of the SAML realm in Elasticsearch for which the configuration
            is used to generate the authentication request. You must specify either this
            parameter or the acs parameter.
        :param relay_state: A string that will be included in the redirect URL that this
            API returns as the RelayState query parameter. If the Authentication Request
            is signed, this value is used as part of the signature computation.
        z/_security/saml/prepareNr   r   r   r   r   r   r   r   r   r   r   r+   )r    r   r   r   r   r   r   r   r!   r"   r#   r$   r%   r%   r&   saml_prepare_authentication  s*   

z*SecurityClient.saml_prepare_authenticationc          	      C   s|   |t v rtddt| }i }|dur||d< |dur!||d< |dur)||d< |dur1||d< dd	i}| jd
|||dS )a  
        Generates SAML metadata for the Elastic stack SAML 2.0 Service Provider

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-saml-sp-metadata.html>`_

        :param realm_name: The name of the SAML realm in Elasticsearch.
        z-Empty value passed for parameter 'realm_name'z/_security/saml/metadata/Nr   r   r   r   r   r   r)   r*   r:   )	r    rs   r   r   r   r   r!   r#   r$   r%   r%   r&   saml_service_provider_metadata	  s    z-SecurityClient.saml_service_provider_metadata)r   r   r   hintr   rE   r   r   r   c                C   s   d}	i }
i }|dur||
d< |dur||d< |dur||d< |dur&||
d< |dur.||d< |dur6||
d< |dur>||d	< |durF||
d
< |
sJd}
ddi}|
durVd|d< | j d|	|||
dS )a"  
        Get suggestions for user profiles that match specified search criteria.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-suggest-user-profile.html>`_

        :param data: List of filters for the `data` field of the profile document. To
            return all content use `data=*`. To return a subset of content use `data=<key>`
            to retrieve content nested under the specified `<key>`. By default returns
            no `data` content.
        :param hint: Extra search criteria to improve relevance of the suggestion result.
            Profiles matching the spcified hint are ranked higher in the response. Profiles
            not matching the hint don't exclude the profile from the response as long
            as the profile matches the `name` field query.
        :param name: Query string used to match name-related fields in user profile documents.
            Name-related fields are the user's `username`, `full_name`, and `email`.
        :param size: Number of profiles to return.
        z/_security/profile/_suggestNr   r   r   r   r   rE   r   r   r   r   r   r   r   r+   )r    r   r   r   r   r   rE   r   r   r!   r"   r#   r$   r%   r%   r&   suggest_user_profiles9	  s6    
z$SecurityClient.suggest_user_profiles)r   r   r   rS   r   rT   c                C   s   |t v rtddt| }i }	i }
|dur||	d< |dur#||	d< |dur+||	d< |dur3||
d< |dur;||	d< |durC||
d	< |
sGd}
d
di}|
durSd|d< | jd||	||
dS )uX  
        Updates attributes of an existing API key.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-update-api-key.html>`_

        :param id: The ID of the API key to update.
        :param metadata: Arbitrary metadata that you want to associate with the API key.
            It supports nested data structure. Within the metadata object, keys beginning
            with _ are reserved for system usage.
        :param role_descriptors: An array of role descriptors for this API key. This
            parameter is optional. When it is not specified or is an empty array, then
            the API key will have a point in time snapshot of permissions of the authenticated
            user. If you supply role descriptors then the resultant permissions would
            be an intersection of API keys permissions and authenticated user’s permissions
            thereby limiting the access scope for API keys. The structure of role descriptor
            is the same as the request for create role API. For more details, see create
            or update roles API.
        z%Empty value passed for parameter 'id'r8   Nr   r   r   rS   r   rT   r   r   r   r2   r   r:   )r    rq   r   r   r   rS   r   rT   r!   r#   r"   r$   r%   r%   r&   update_api_keyu	  s2    
zSecurityClient.update_api_key)	r   r   r   r   if_primary_term	if_seq_nolabelsr   r0   r   r   r   c       
         C   s   |t v rtddt| d}i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< ddd}| jd||||dS )a  
        Update application specific data for the user profile of the given unique ID.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/security-api-update-user-profile-data.html>`_

        :param uid: A unique identifier for the user profile.
        :param data: Non-searchable data that you want to associate with the user profile.
            This field supports a nested data structure.
        :param if_primary_term: Only perform the operation if the document has this primary
            term.
        :param if_seq_no: Only perform the operation if the document has this sequence
            number.
        :param labels: Searchable data that you want to associate with the user profile.
            This field supports a nested data structure.
        :param refresh: If 'true', Elasticsearch refreshes the affected shards to make
            this operation visible to search, if 'wait_for' then wait for a refresh to
            make this operation visible to search, if 'false' do nothing with refreshes.
        rh   ri   z/_dataNr   r   r   r   r   r   r   r   r0   r   r   r2   r   r:   )r    rg   r   r   r   r   r   r   r   r   r0   r!   r"   r#   r$   r%   r%   r&   update_user_profile_data	  s6   %

z'SecurityClient.update_user_profile_data)B__name__
__module____qualname__r   tUnionr   OptionalboolSequencer   Anyr'   r-   r4   r;   r?   rD   rI   rQ   MappingrV   rW   rY   r\   r_   r`   rc   re   rk   rm   rn   ro   rp   ru   rv   ry   r{   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   intfloatr   r   r   r   r   r   r   r   r   r   r%   r%   r%   r&   r      s
   	
0	
8"!	&!	
)	
@	
:	-))	
1)))))	
>	&$&	)	%;	)	
,	(		
@6	,	
=	
."*V	
B	
G	W	
2	
7	
8	-	
0!	
9	
7	
r   )typingr   Zelastic_transportr   _baser   utilsr   r   r   r   r%   r%   r%   r&   <module>   s
   