U
    ‡…”]o  ã                   @   s<   d dl Z d dlZddlmZ ddlmZ G dd„ deƒ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 |¡}tjr.| d¡}|||dœ}|dk	rbt 	| j
d¡rZt 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ÚsixZPY3Údecoder   Z
version_ltZ_versionr   ZInvalidVersionÚ_urlÚ_resultZ
_post_json)ÚselfÚnamer   ÚlabelsZdriverZ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_secret1   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_secretC   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   ÚsecretsW   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   Úobjectr   r   r   r   r   Ú<module>   s   