o
    Ó2.a­"  ć                   @   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	 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   ś3/usr/lib/python3/dist-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   Zcreate_archiveŚsetZbuildŚwalkŚ_postr   )r   r   Zplugin_data_dirr   r   Zarchvr   r   r   r   Ścreate_plugin   s   
žü
zPluginApiMixin.create_pluginc                 C   s$   |   d|”}|  |”}|  |” dS )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   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Śtimeout©r   Tr!   )r   r   r$   r   r   r   r   r   r   Śenable_pluginF   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_pluginY   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   r+   Ś
privilegesr   r   r   r.   ŚregistryŚ	repo_nameŚheaderŚresponser   r   r   Śpull_pluginh   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

        r+   r,   z/plugins/privileges)r   r.   T)r   r3   r4   r   r(   r)   )r   r   r   r.   r7   r8   r9   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}/pullr,   )r.   Tr0   )r   r   r3   r4   r   r   r5   )r   r   r   r.   r7   r8   r9   r   r   r   r   Śpush_plugin¶   s   
zPluginApiMixin.push_pluginc                 C   s,   |   d|”}| j|d|id}|  |” dS )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   Z_deleter   )r   r   r?   r   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}/upgrader+   r,   Tr-   r0   r2   )r   r   r+   r6   r   r   r.   r7   r8   r9   r:   r   r   r   Śupgrade_pluginā   s   ’ž
zPluginApiMixin.upgrade_plugin)F)r#   )N)Ś__name__Ś
__module__Ś__qualname__r   Zminimum_versionZcheck_resourcer   r    r"   r&   r*   r;   r<   r=   r>   r@   rA   r   r   r   r   r      s6    

%


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