o
    2.aC                     @   s2   d dl Z ddlmZ ddlmZ G dd dZdS )    N   )errors)utilsc                   @   sl   e Zd ZeddddZededdd Zededdd	 Zeddd
dZ	dS )SecretApiMixinz1.25Nc                 C   s|   t |ts
|d}t|}|d}|||d}|dur.t| jdr*t	
d||d< | d}| | j||d	d
S )a  
            Create a secret

            Args:
                name (string): Name of the secret
                data (bytes): Secret data to be stored
                labels (dict): A mapping of labels to assign to the secret
                driver (DriverConfig): A custom driver configuration. If
                    unspecified, the default ``internal`` driver will be used

            Returns (dict): ID of the newly created secret
        zutf-8ascii)ZDataNameZLabelsNz1.31z6Secret driver is only available for API version > 1.31ZDriverz/secrets/create)dataT)
isinstancebytesencodebase64Z	b64encodedecoder   Z
version_ltZ_versionr   ZInvalidVersion_url_resultZ
_post_json)selfnamer   labelsZdriverbodyurl r   3/usr/lib/python3/dist-packages/docker/api/secret.pycreate_secret   s$   




zSecretApiMixin.create_secretidc                 C   s   |  d|}| | |dS )a2  
            Retrieve secret metadata

            Args:
                id (string): Full ID of the secret to inspect

            Returns (dict): A dictionary of metadata

            Raises:
                :py:class:`docker.errors.NotFound`
                    if no secret with that ID exists
        /secrets/{0}T)r   r   _get)r   r   r   r   r   r   inspect_secret.   s   zSecretApiMixin.inspect_secretc                 C   s$   |  d|}| |}| | dS )a%  
            Remove a secret

            Args:
                id (string): Full ID of the secret to remove

            Returns (boolean): True if successful

            Raises:
                :py:class:`docker.errors.NotFound`
                    if no secret with that ID exists
        r   T)r   Z_deleteZ_raise_for_status)r   r   r   resr   r   r   remove_secret@   s   

zSecretApiMixin.remove_secretc                 C   s6   |  d}i }|rt||d< | | j||ddS )z
            List secrets

            Args:
                filters (dict): A map of filters to process on the secrets
                list. Available filters: ``names``

            Returns (list): A list of secrets
        z/secretsfilters)paramsT)r   r   Zconvert_filtersr   r   )r   r   r   r   r   r   r   secretsT   s
   
zSecretApiMixin.secrets)NN)N)
__name__
__module____qualname__r   Zminimum_versionr   Zcheck_resourcer   r   r    r   r   r   r   r      s    %r   )r    r   r   r   r   r   r   r   <module>   s    