
    bi#                     (    d dl mZmZ  G d d      Zy)   )authutilsc                      e Zd Z ej                  d       ej
                  d      d               Z ej                  d      dd       Z ej                  d      dd       Z ej                  d      dd       Z	 ej                  d      d        Z
 ej                  d      dd	       Z ej                  d      d
        Z ej                  d      d        Z ej                  d       ej
                  d      d               Z ej                  d       ej
                  d      dd              Z ej                  d       ej
                  d      d               Zy)PluginApiMixinz1.25namec                     | j                  d|      }|}t        |t              r'|j                         D cg c]  \  }}| d|  }}}| j	                  ||      }| j                  |       yc c}}w )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}/set=)dataT)_url
isinstancedictitems
_post_json_raise_for_status)selfr   optionsurlr
   kvress           L/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/docker/api/plugin.pyconfigure_pluginzPluginApiMixin.configure_plugin   ss     ii*D1dD!+/::<841aqc1#J8D8ooco-s# 9s   A1c           
         | j                  d      }t        j                  ||t        t        j                  j                  |g                   5 }| j                  |d|i|      }ddd       | j                         y# 1 sw Y   xY w)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   plugin_data_dirr   r   archvr   s          r   create_pluginzPluginApiMixin.create_plugin   s      ii)*!! tekk&&;<
 	E **S&$e*DC		E
 	s#	E 	Es   BBc                 t    | j                  d|      }| j                  |d|i      }| j                  |       y)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   s        r   disable_pluginzPluginApiMixin.disable_plugin5   s=     ii.5jjgu%5j6s#    c                 x    | j                  d|      }d|i}| j                  ||      }| j                  |       y)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   s         r   enable_pluginzPluginApiMixin.enable_pluginG   sB     ii-t4W%jjVj,s#r,   c                 h    | j                  d|      }| j                  | j                  |      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   s      r   inspect_pluginzPluginApiMixin.inspect_pluginZ   s.     ii+T2||DIIcND11r,   Nc                    | j                  d      }d|i}|r||d<   i }t        j                  |      \  }}t        j                  | |      }	|	r|	|d<   | j	                  ||||d      }
| j                  |
       | j                  |
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   r6   
privilegesr   r   r   r9   registry	repo_nameheaderresponses              r   pull_pluginzPluginApiMixin.pull_plugini   s    & ii(f
 !F6N"::6B)''h7)/G%&??j # 
 	x(""8D"99r,   c                 f    | j                  d      }| j                  | j                  |      d      S )z
            Retrieve a list of installed plugins.

            Returns:
                A list of dicts, one per plugin
        z/pluginsTr1   )r   r   s     r   pluginszPluginApiMixin.plugins   s+     ii
#||DIIcND11r,   c                     d|i}i }t        j                  |      \  }}t        j                  | |      }|r||d<   | j                  d      }| j	                  | j                  |||      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

        r6   r7   z/plugins/privileges)r   r9   T)r   r>   r?   r   r2   r3   )r   r   r   r9   rB   rC   rD   r   s           r   plugin_privilegesz PluginApiMixin.plugin_privileges   s     d
 "::4@)''h7)/G%&ii-.||IIc&'I:D
 	
r,   c                    | j                  d|      }i }t        j                  |      \  }}t        j                  | |      }|r||d<   | j	                  ||      }| j                  |       | j                  |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}/pullr7   )r9   Tr;   )r   r   r>   r?   r"   r   r@   )r   r   r   r9   rB   rC   rD   r   s           r   push_pluginzPluginApiMixin.push_plugin   s     ii+T2"::4@)''h7)/G%&jjgj.s#""3t"44r,   c                 t    | j                  d|      }| j                  |d|i      }| j                  |       y)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*   s        r   remove_pluginzPluginApiMixin.remove_plugin   s<     ii-ll3'7l8s#r,   z1.26c                    | j                  d|      }d|i}i }t        j                  |      \  }}t        j                  | |      }	|	r|	|d<   | j	                  ||||d      }
| j                  |
       | j                  |
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}/upgrader6   r7   Tr8   r;   r=   )r   r   r6   rA   r   r   r9   rB   rC   rD   rE   s              r   upgrade_pluginzPluginApiMixin.upgrade_plugin   s    & ii.5f
 "::6B)''h7)/G%&??j # 
 	x(""8D"99r,   )F)    )N)__name__
__module____qualname__r   minimum_versioncheck_resourcer   r%   r+   r/   r4   rF   rH   rJ   rL   rO   rQ    r,   r   r   r      s   U6"U&! " #( U6" #2 U6" #" U6" #$ U6"2 #2 U6"#: ##:J U6"2 #2 U6"
 #
8 U6"U&!5 " #5, U6"U&! " #$ U6"U&! : " # :r,   r   N) r   r   r   rX   r,   r   <module>rZ      s    A: A:r,   