o
    Nrf#                     @   s"   d dl mZmZ G dd dZdS )   )authutilsc                   @   s  e Zd Zededdd ZeddddZedddd	ZeddddZ	eddd Z
eddddZeddd Zeddd Zededdd ZededdddZededdd ZdS ) PluginApiMixinz1.25namec                 C   sH   |  d|}|}t|trdd | D }| j||d}| | dS )aC  
            Configure a plugin.

            Args:
                name (string): The name of the plugin. The ``:latest`` tag is
                    optional, and is the default if omitted.
                options (dict): A key-value mapping of options

            Returns:
                ``True`` if successful
        z/plugins/{0}/setc                 S   s   g | ]\}}| d | qS )= ).0kvr   r   Z/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/docker/api/plugin.py
<listcomp>   s    z3PluginApiMixin.configure_plugin.<locals>.<listcomp>)dataT)_url
isinstancedictitems
_post_json_raise_for_status)selfr   optionsurlr   resr   r   r   configure_plugin   s   

zPluginApiMixin.configure_pluginFc                 C   sj   |  d}tj||ttj|g d}| j|d|i|d}W d   n1 s)w   Y  | | dS )a*  
            Create a new plugin.

            Args:
                name (string): The name of the plugin. The ``:latest`` tag is
                    optional, and is the default if omitted.
                plugin_data_dir (string): Path to the plugin data directory.
                    Plugin data directory must contain the ``config.json``
                    manifest file and the ``rootfs`` directory.
                gzip (bool): Compress the context using gzip. Default: False

            Returns:
                ``True`` if successful
        z/plugins/create)rootgzipfilesr   )paramsr   NT)r   r   create_archivesetbuildwalk_postr   )r   r   Zplugin_data_dirr   r   Zarchvr   r   r   r   create_plugin   s   

zPluginApiMixin.create_pluginc                 C   ,   |  d|}| j|d|id}| | dS )aP  
            Disable an installed plugin.

            Args:
                name (string): The name of the plugin. The ``:latest`` tag is
                    optional, and is the default if omitted.
                force (bool): To enable the force query parameter.

            Returns:
                ``True`` if successful
        z/plugins/{0}/disableforcer   Tr   r!   r   r   r   r$   r   r   r   r   r   disable_plugin5   s   
zPluginApiMixin.disable_plugin    c                 C   s0   |  d|}d|i}| j||d}| | dS )aV  
            Enable an installed plugin.

            Args:
                name (string): The name of the plugin. The ``:latest`` tag is
                    optional, and is the default if omitted.
                timeout (int): Operation timeout (in seconds). Default: 0

            Returns:
                ``True`` if successful
        z/plugins/{0}/enabletimeoutr%   Tr&   )r   r   r*   r   r   r   r   r   r   enable_pluginG   s
   
zPluginApiMixin.enable_pluginc                 C   s   |  d|}| | |dS )a  
            Retrieve plugin metadata.

            Args:
                name (string): The name of the plugin. The ``:latest`` tag is
                    optional, and is the default if omitted.

            Returns:
                A dict containing plugin info
        z/plugins/{0}/jsonTr   _result_get)r   r   r   r   r   r   inspect_pluginZ   s   zPluginApiMixin.inspect_pluginNc                 C   st   |  d}d|i}|r||d< i }t|\}}t| |}	|	r$|	|d< | j||||dd}
| |
 | j|
ddS )a  
            Pull and install a plugin. After the plugin is installed, it can be
            enabled using :py:meth:`~enable_plugin`.

            Args:
                remote (string): Remote reference for the plugin to install.
                    The ``:latest`` tag is optional, and is the default if
                    omitted.
                privileges (:py:class:`list`): A list of privileges the user
                    consents to grant to the plugin. Can be retrieved using
                    :py:meth:`~plugin_privileges`.
                name (string): Local name for the pulled plugin. The
                    ``:latest`` tag is optional, and is the default if omitted.

            Returns:
                An iterable object streaming the decoded API logs
        z/plugins/pullremoter   X-Registry-AuthTr   headersr   streamdecoder   r   resolve_repository_nameget_config_headerr   r   _stream_helper)r   r0   
privilegesr   r   r   r3   registry	repo_nameheaderresponser   r   r   pull_plugini   s    

zPluginApiMixin.pull_pluginc                 C   s   |  d}| | |dS )z
            Retrieve a list of installed plugins.

            Returns:
                A list of dicts, one per plugin
        z/pluginsTr,   )r   r   r   r   r   plugins   s   
zPluginApiMixin.pluginsc                 C   sT   d|i}i }t |\}}t | |}|r||d< | d}| | j|||ddS )al  
            Retrieve list of privileges to be granted to a plugin.

            Args:
                name (string): Name of the remote plugin to examine. The
                    ``:latest`` tag is optional, and is the default if omitted.

            Returns:
                A list of dictionaries representing the plugin's
                permissions

        r0   r1   z/plugins/privileges)r   r3   T)r   r8   r9   r   r-   r.   )r   r   r   r3   r<   r=   r>   r   r   r   r   plugin_privileges   s   
z PluginApiMixin.plugin_privilegesc                 C   s\   |  d|}i }t|\}}t| |}|r||d< | j||d}| | | j|ddS )a  
            Push a plugin to the registry.

            Args:
                name (string): Name of the plugin to upload. The ``:latest``
                    tag is optional, and is the default if omitted.

            Returns:
                ``True`` if successful
        z/plugins/{0}/pullr1   )r3   Tr5   )r   r   r8   r9   r!   r   r:   )r   r   r   r3   r<   r=   r>   r   r   r   r   push_plugin   s   
zPluginApiMixin.push_pluginc                 C   r#   )a  
            Remove an installed plugin.

            Args:
                name (string): Name of the plugin to remove. The ``:latest``
                    tag is optional, and is the default if omitted.
                force (bool): Disable the plugin before removing. This may
                    result in issues if the plugin is in use by a container.

            Returns:
                ``True`` if successful
        z/plugins/{0}r$   r%   T)r   _deleter   r'   r   r   r   remove_plugin   s   
zPluginApiMixin.remove_pluginz1.26c                 C   sj   |  d|}d|i}i }t|\}}t| |}	|	r|	|d< | j||||dd}
| |
 | j|
ddS )a  
            Upgrade an installed plugin.

            Args:
                name (string): Name of the plugin to upgrade. The ``:latest``
                    tag is optional and is the default if omitted.
                remote (string): Remote reference to upgrade to. The
                    ``:latest`` tag is optional and is the default if omitted.
                privileges (:py:class:`list`): A list of privileges the user
                    consents to grant to the plugin. Can be retrieved using
                    :py:meth:`~plugin_privileges`.

            Returns:
                An iterable object streaming the decoded API logs
        z/plugins/{0}/upgrader0   r1   Tr2   r5   r7   )r   r   r0   r;   r   r   r3   r<   r=   r>   r?   r   r   r   upgrade_plugin   s   
zPluginApiMixin.upgrade_plugin)F)r)   )N)__name__
__module____qualname__r   minimum_versionZcheck_resourcer   r"   r(   r+   r/   r@   rA   rB   rC   rE   rF   r   r   r   r   r      s6    
%


r   N) r   r   r   r   r   r   r   <module>   s    