
    3~h-8                     n    d dl Z d dlZd dlZd dlmZmZ d dlmZ ddl	m
Z
mZ ddlmZmZ  G d de      Zy)	    N)Configmerge_dicts)	SSHConfig   )RemoteRemoteShell)get_local_userdebugc                   r     e Zd ZdZdZed        Z fdZd Zd Z	 fdZ
 fdZd	 Zd
 Zed        Z xZS )r   a_  
    An `invoke.config.Config` subclass with extra Fabric-related behavior.

    This class behaves like `invoke.config.Config` in every way, with the
    following exceptions:

    - its `global_defaults` staticmethod has been extended to add/modify some
      default settings (see its documentation, below, for details);
    - it triggers loading of Fabric-specific env vars (e.g.
      ``FABRIC_RUN_HIDE=true`` instead of ``INVOKE_RUN_HIDE=true``) and
      filenames (e.g. ``/etc/fabric.yaml`` instead of ``/etc/invoke.yaml``).
    - it extends the API to account for loading ``ssh_config`` files (which are
      stored as additional attributes and have no direct relation to the
      regular config data/hierarchy.)
    - it adds a new optional constructor, `from_v1`, which :ref:`generates
      configuration data from Fabric 1 <from-v1>`.

    Intended for use with `.Connection`, as using vanilla
    `invoke.config.Config` objects would require users to manually define
    ``port``, ``user`` and so forth.

    .. seealso:: :doc:`/concepts/configuration`, :ref:`ssh-config`

    .. versionadded:: 2.0
    fabricc                    |j                  di       }dD ]  }|j                  |i         |d   j                  d|j                         |j                  d|j                         |j                  d|j                         |j
                  |d   j                  d|j
                         |d   j                  d	|j                          |j                  d
|j                         |d   j                  d|j                         |j                  }|d   j                  d|       |d   d   s||d   d<   |d   j                  d|j                         |d   j                  d|j                         |j                  d|j                         |d   j                  d|j                         ||d<    | di |S )a  
        Alternate constructor which uses Fabric 1's ``env`` dict for settings.

        All keyword arguments besides ``env`` are passed unmolested into the
        primary constructor, with the exception of ``overrides``, which is used
        internally & will end up resembling the data from ``env`` with the
        user-supplied overrides on top.

        .. warning::
            Because your own config overrides will win over data from ``env``,
            make sure you only set values you *intend* to change from your v1
            environment!

        For details on exactly which ``env`` vars are imported and what they
        become in the new API, please see :ref:`v1-env-var-imports`.

        :param env:
            An explicit Fabric 1 ``env`` dict (technically, any
            ``fabric.utils._AttributeDict`` instance should work) to pull
            configuration from.

        .. versionadded:: 2.4
        	overrides)connect_kwargsrunsudotimeoutsr   ptygatewayforward_agentr   key_filenameallow_agentssh_config_pathr   passwordpromptr   connectload_ssh_configswarn )pop
setdefaultalways_use_ptyr   r   r   no_agentr   sudo_passwordr   sudo_prompttimeoutuse_ssh_config	warn_only)clsenvkwargsdatasubdictpasswds         V/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/fabric/config.pyfrom_v1zConfig.from_v1)   s   @ zz+r*D 	)GOOGR(	) 	Uuc&8&89	3;;/):):;'!"--nc>N>NO))-S\\9IJ)3+>+>?V
C,=,=>))*f=F|J''-DL$V#//:Z##Is{{;*C,>,>?Uvs}}5"{}V}    c                    |j                  dd      }|j                  dd      }| j                  |j                  dd             |j                  dd      }| j                  |       | j                  |j                  d	d
             |du}| j                  |       |
t	               }| j                  |       t        |   |i | |s| j                          yy)a  
        Creates a new Fabric-specific config object.

        For most API details, see `invoke.config.Config.__init__`. Parameters
        new to this subclass are listed below.

        :param ssh_config:
            Custom/explicit `paramiko.config.SSHConfig` object. If given,
            prevents loading of any SSH config files. Default: ``None``.

        :param str runtime_ssh_path:
            Runtime SSH config path to load. Prevents loading of system/user
            files if given. Default: ``None``.

        :param str system_ssh_path:
            Location of the system-level SSH config file. Default:
            ``/etc/ssh/ssh_config``.

        :param str user_ssh_path:
            Location of the user-level SSH config file. Default:
            ``~/.ssh/config``.

        :param bool lazy:
            Has the same meaning as the parent class' ``lazy``, but
            additionally controls whether SSH config file loading is deferred
            (requires manually calling `load_ssh_config` sometime.) For
            example, one may need to wait for user input before calling
            `set_runtime_ssh_path`, which will inform exactly what
            `load_ssh_config` does.
        
ssh_configNlazyFruntime_ssh_pathsystem_ssh_pathz/etc/ssh/ssh_config)_system_ssh_pathuser_ssh_pathz~/.ssh/config)_user_ssh_path)_given_explicit_object)base_ssh_config)r   getset_runtime_ssh_path_setr   super__init__load_ssh_config)selfargsr*   r2   r3   system_pathexplicit	__class__s          r.   r?   zConfig.__init__h   s    D ZZd3
zz&%(!!&**-?"FGjj!24IJ		;	/		O_!M	N
 T)			2 "J		*	- 	$)&)   " r0   c                 (    | j                  |       y)z
        Configure a runtime-level SSH config file path.

        If set, this will cause `load_ssh_config` to skip system and user
        files, as OpenSSH does.

        .. versionadded:: 2.0
        )_runtime_ssh_pathN)r=   rA   paths     r.   r<   zConfig.set_runtime_ssh_path   s     			D	)r0   c                 x    | j                   r| j                   | _        | j                  s| j                          yy)z
        Load SSH config file(s) from disk.

        Also (beforehand) ensures that Invoke-level config re: runtime SSH
        config file paths, is accounted for.

        .. versionadded:: 2.0
        N)r   rG   r9   _load_ssh_files)rA   s    r.   r@   zConfig.load_ssh_config   s7     %)%9%9D" **  " +r0   c           	          t        |   |i |}dD ]  }t        ||t        | |              | j	                          |S )N)rG   r6   r8   )r>   clonesetattrgetattrr@   )rA   rB   r*   newattrrE   s        r.   rM   zConfig.clone   sQ     gmT,V,
 	4D
 CwtT23	4 	
r0   c                     t        |   |i |}t               }t        j                  | j
                  j                        |_        t        ||      S )N)r2   )r>   _clone_init_kwargsr   copydeepcopyr:   _configdict)rA   rB   kwr*   
new_configrE   s        r.   rS   zConfig._clone_init_kwargs   sL    +T8R8
 [
 "]]4+?+?+G+GH
Fz22r0   c                    | j                   u| j                   }t        j                  j                  |      st	        t
        j                  d|      | j                  t        j                  j                  |             y| j                  rL| j                  | j                  fD ]0  }| j                  t        j                  j                  |             2 yy)z
        Trigger loading of configured SSH config file paths.

        Expects that ``base_ssh_config`` has already been set to an
        `~paramiko.config.SSHConfig` object.

        :returns: ``None``.
        NzNo such file or directory)rG   osrI   existsFileNotFoundErrorerrnoENOENT_load_ssh_file
expanduserr   r8   r6   rH   s     r.   rK   zConfig._load_ssh_files   s     !!-))D77>>$''LL"=t   2 24 89"",,d.C.CD >##BGG$6$6t$<=> #r0   c                    t         j                  j                  |      rt        | j                  j
                        }t        |      5 }| j                  j                  |       ddd       t        | j                  j
                        }d}t        |j                  ||z
  |             yt        d       y# 1 sw Y   UxY w)z
        Attempt to open and parse an SSH config file at ``path``.

        Does nothing if ``path`` is not a path to a valid file.

        :returns: ``None``.
        Nz(Loaded {} new ssh_config rules from {!r}zFile not found, skipping)
r[   rI   isfilelenr:   rV   openparser
   format)rA   rI   	old_rulesfd	new_rulesmsgs         r.   r`   zConfig._load_ssh_file  s     77>>$D00889Id /r$$**2./D00889I<C#**Y2D9:,-/ /s   
B::Cc                      t        j                         } g ddi dddddt        t        ddddid	dit	               d
}t        | |       | S )a  
        Default configuration values and behavior toggles.

        Fabric only extends this method in order to make minor adjustments and
        additions to Invoke's `~invoke.config.Config.global_defaults`; see its
        documentation for the base values, such as the config subtrees
        controlling behavior of ``run`` or how ``tasks`` behave.

        For Fabric-specific modifications and additions to the Invoke-level
        defaults, see our own config docs at :ref:`default-values`.

        .. versionadded:: 2.0
        .. versionchanged:: 3.1
            Added the ``authentication`` settings section, plus sub-attributes
            such as ``authentication.strategy_class``.
        N)
identitiesstrategy_classFT   )remoteremote_shellcollection_namefabfiler   )authenticationr   r   r   inline_ssh_envr   portrunnersr   tasksr   user)InvokeConfigglobal_defaultsr   r   r	   r   )defaultsourss     r.   r{   zConfig.global_defaults  sn    :  //1 !"& !"" $"(+F#'3 #D)"$#
& 	Hd#r0   )__name__
__module____qualname____doc__prefixclassmethodr/   r?   r<   r@   rM   rS   rK   r`   staticmethodr{   __classcell__)rE   s   @r.   r   r      sZ    4 F< <|;#z	*#&43>0.$ 6 6r0   r   )rT   r^   r[   invoke.configr   rz   r   paramiko.configr   rw   r   r   utilr	   r
   r   r0   r.   <module>r      s(      	 = % ( '\ r0   