
    2.a"                     (    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        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           3/usr/lib/python3/dist-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                 l    | j                  d|      }| j                  |      }| j                  |       y)a  
            Disable an installed plugin.

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

            Returns:
                ``True`` if successful
        z/plugins/{0}/disableTr   r"   r   )r   r   r   r   s       r   disable_pluginzPluginApiMixin.disable_plugin5   s3     ii.5jjo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timeoutr   Tr'   )r   r   r+   r   r   r   s         r   enable_pluginzPluginApiMixin.enable_pluginF   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_pluginY   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   r4   
privilegesr   r   r   r7   registry	repo_nameheaderresponses              r   pull_pluginzPluginApiMixin.pull_pluginh   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/pluginsTr/   )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

        r4   r5   z/plugins/privileges)r   r7   T)r   r<   r=   r   r0   r1   )r   r   r   r7   r@   rA   rB   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}/pullr5   )r7   Tr9   )r   r   r<   r=   r"   r   r>   )r   r   r   r7   r@   rA   rB   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}forcer,   T)r   _deleter   )r   r   rL   r   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}/upgrader4   r5   Tr6   r9   r;   )r   r   r4   r?   r   r   r7   r@   rA   rB   rC   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-   r2   rD   rF   rH   rJ   rN   rP    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   rW   r)   r   <module>rY      s    @: @:r)   