
    3~h~#                     r    d dl mZ d dlmZ d dlmZ d dlmZmZ d dlm	Z	m
Z
mZmZ ddlmZ  G d d	e	      Zy
)    )partial)getpass)Path)AgentPKey)AuthStrategyPasswordInMemoryPrivateKeyOnDiskPrivateKey   )win32c                   >     e Zd ZdZ fdZd Zd Z fdZd Z xZ	S )OpenSSHAuthStrategya  
    Auth strategy that tries very hard to act like the OpenSSH client.

    .. warning::
        As of version 3.1, this class is **EXPERIMENTAL** and **incomplete**.
        It works best with passphraseless (eg ssh-agent) private key auth for
        now and will grow more features in future releases.

    For example, it accepts a `~paramiko.config.SSHConfig` and uses any
    relevant ``IdentityFile`` directives from that object, along with keys from
    your home directory and any local SSH agent. Keys specified at runtime are
    tried last, just as with ``ssh -i /path/to/key`` (this is one departure
    from the legacy/off-spec auth behavior observed in older Paramiko and
    Fabric versions).

    We explicitly do not document the full details here, because the point is
    to match the documented/observed behavior of OpenSSH. Please see the `ssh
    <https://man.openbsd.org/ssh>`_ and `ssh_config
    <https://man.openbsd.org/ssh_config>`_ man pages for more information.

    .. versionadded:: 3.1
    c                 `    t         |   |       || _        || _        t	               | _        y)a  
        Extends superclass with additional inputs.

        Specifically:

        - ``fabric_config``, a `fabric.Config` instance for the current
          session.
        - ``username``, which is unified by our intended caller so we don't
          have to - it's a synthesis of CLI, runtime,
          invoke/fabric-configuration, and ssh_config configuration.

        Also handles connecting to an SSH agent, if possible, for easier
        lifecycle tracking.
        )
ssh_configN)super__init__usernameconfigr   agent)selfr   fabric_configr   	__class__s       T/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/fabric/auth.pyr   zOpenSSHAuthStrategy.__init__E   s.     	J/ # W
    c              #     K   g g g g f\  }}}}| j                   j                  j                  D ]P  }	 t        j                  |      }t        | j                  d||      }|j                  r|n|j                  |       R | j                  j                  dg       D ]P  }	 t        j                  |      }t        | j                  d||      }|j                  r|n|j                  |       R t        ||||f      st        j                         t        rdnd dz  }dD ]Z  }	|d	|	 z  }	 t        j                  |      }t        | j                  d
||      }|j                  r|n|}
|
j                  |       \ | j                   j#                         }|D ]  }|  |D ]  }|  g }|D ]Z  }d }t%        |      D ]  \  }}|j&                  |k(  s|} n |rt)        | j                  |       ||= J|j                  |       \ |D ]  }t)        | j                  |        |D ]  }|  |D ]  }|  y # t
        $ r Y &w xY w# t
        $ r Y w xY w# t
        $ r Y Qw xY ww)Nzpython-config)r   sourcepathpkeyidentityfilez
ssh-config .ssh)rsaecdsaed25519dsaid_zimplicit-home)r   r   )r   authentication
identitiesr   	from_pathFileNotFoundErrorr   r   public_blobappendr   getanyr   homer   r   get_keys	enumerater   r
   )r   config_certsconfig_keys	cli_certscli_keysr   keyr   user_sshtype_dest
agent_keysdeferred_agent_keysconfig_indexi
config_keys                   r   get_pubkeyszOpenSSHAuthStrategy.get_pubkeys[   s     :<RR6k9h
 KK..99 	HDnnT* &&	F //Yx??G	H& OO''; 	NDnnT* &#	F !__\+EEfM	N L+y(CDyy{e'=S%AAH; $Cw-/...C *!]]*	 (+|KF#$ ZZ((*
 # 	FL	 	FL	 ! 	0CL!*;!7 :??c)#$L ($--cJJ-#**3/	0 ' 	GC$dmm#FF	G 	FL	 " 	FL	_ % & % $ ) sz   /I8IAI8!I6A8I8/I(BI8A.I8	II8II8	I%!I8$I%%I8(	I51I84I55I8c              #      K   | j                         E d {    | j                  }t        t        | d      }t	        | j                  |       y 7 =w)Nz's password: )r   password_getter)rA   r   r   r   r	   )r   userprompters      r   get_sourceszOpenSSHAuthStrategy.get_sources   sL     
 ##%%%}}7tfM$:;xHH	 	&s   AA>Ac                 n    	 t        |   |i || j                          S # | j                          w xY w)N)r   authenticateclose)r   argskwargsr   s      r   rH   z OpenSSHAuthStrategy.authenticate   s-    	7'88JJLDJJLs   " 4c                 8    | j                   j                          y)zA
        Shut down any resources we ourselves opened up.
        N)r   rI   )r   s    r   rI   zOpenSSHAuthStrategy.close   s    
 	

r   )
__name__
__module____qualname____doc__r   rA   rF   rH   rI   __classcell__)r   s   @r   r   r      s%    h,[z	Ir   r   N)	functoolsr   r   pathlibr   paramikor   r   paramiko.auth_strategyr   r	   r
   r   utilr   r    r   r   <module>rX      s.          , r   