
    %                        S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKJr  SSKrSSKJr  SSKr " S S	\R&                  " \R(                  \5      5      r " S
 S\5      r " S S\5      r " S S\5      rSr " S S\5      rSr " S S\5      r " S S\R&                  " \R(                  \5      5      r/ SQrS r S r! " S S\5      r"\"" 5       r#g)zBThis package exposes credentials for talking to a Docker registry.    )absolute_import)division)print_functionN)docker_name)clientc                   <    \ rS rSrSr\R                  S 5       rSrg)Provider$   zHInterface for providing User Credentials for use with a Docker Registry.c                     g)z>Produces a value suitable for use in the Authorization header.N selfs    9lib/third_party/containerregistry/client/docker_creds_.pyGetProvider.Get(           r   N)	__name__
__module____qualname____firstlineno____doc__abcabstractmethodr   __static_attributes__r   r   r   r	   r	   $   s!    P I Ir   r	   c                       \ rS rSrSrS rSrg)	Anonymous.   z$Implementation for anonymous access.c                     g)z#Implement anonymous authentication. r   r   s    r   r   Anonymous.Get1   s    r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   .   s
    ,r   r   c                   R    \ rS rSrSrS r\\R                  S 5       5       r	S r
Srg)SchemeProvider6   z=Implementation for providing a challenge response credential.c                     Xl         g N_scheme)r   schemes     r   __init__SchemeProvider.__init__9   s    Lr   c                     g)z=Returns the authentication payload to follow the auth scheme.Nr   r   s    r   suffixSchemeProvider.suffix=   r   r   c                 <    U R                   < SU R                  < 3$ )zCGets the credential in a form suitable for an Authorization header. )r(   r-   r   s    r   r   SchemeProvider.GetC   s    ||T[[11r   r'   N)r   r   r   r   r   r*   propertyr   r   r-   r   r   r   r   r   r#   r#   6   s3    E H  H2r   r#   c                   \   ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r\S 5       r	Sr
U =r$ )BasicH   z=Implementation for providing a username/password-based creds.c                 D   > [         [        U ]  S5        Xl        X l        g )Nr4   )superr4   r*   	_username	_password)r   usernamepassword	__class__s      r   r*   Basic.__init__K   s    	%(NNr   c                     U R                   $ r&   )r8   r   s    r   r:   Basic.usernameP       >>r   c                     U R                   $ r&   )r9   r   s    r   r;   Basic.passwordT   r@   r   c                     U R                   R                  S5      nU R                  R                  S5      n[        R                  " US-   U-   5      R                  S5      $ )Nutf8   :)r:   encoder;   base64	b64encodedecode)r   ups      r   r-   Basic.suffixX   sN    V$AV$AAHqL)0088r   )r9   r8   )r   r   r   r   r   r*   r2   r:   r;   r-   r   __classcell__r<   s   @r   r4   r4   H   sG    E
     9 9r   r4   _tokenc                   <   ^  \ rS rSrSrU 4S jr\S 5       rSrU =r	$ )OAuth2b   zGBase class for turning OAuth2Credentials into suitable GCR credentials.c                 N   > [         [        U ]  [        S5        Xl        X l        g)zConstructor.

Args:
  creds: the credentials from which to retrieve access tokens.
  transport: the http transport to use for token exchanges.
does not matterN)r7   rQ   r*   	_USERNAME_creds
_transport)r   creds	transportr<   s      r   r*   OAuth2.__init__e   s!     
&$ ,=>KOr   c                     U R                   R                  U R                  S9nU R                   R                  U R                  S9R                  $ )N)http)rV   get_access_tokenrW   access_token)r   	unused_ats     r   r;   OAuth2.passwordq   sC     ,,$//,BI ;;''T__'=JJJr   )rV   rW   )
r   r   r   r   r   r*   r2   r;   r   rM   rN   s   @r   rQ   rQ   b   s!    O
  K Kr   rQ   z(credentials not found in native keychainc                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )Helper   z;This provider wraps a particularly named credential helper.c                 \   > [         [        U ]  SS5        Xl        UR                  U l        g)zConstructor.

Args:
  name: the name of the helper, as it appears in the Docker config.
  registry: the registry for which we're invoking the helper.
rT   N)r7   rb   r*   _nameregistry	_registry)r   namerf   r<   s      r   r*   Helper.__init__   s*     
&$ !24EFJ&&DNr   c                 p   SR                  U R                  S9n[        R                  " SU5         [        R
                  " US/[        R                  [        R                  [        R                  S9nUR                  SU R                  -   R                  S5      S	9S
   nUR                  5       [         :X  a.  [        R                  " S5        [#        5       R%                  5       $ UR&                  S
:w  a%  [        SU R                  UR&                  U4-  5      e[(        R*                  " UR-                  S5      5      n[        R                  " S5        [/        US   US   5      R%                  5       $ ! [         a2  nUR                  [        R                  :X  a  [        SU-   5      ee S nAff = f)Nzdocker-credential-{name})rh   z)Invoking %r to obtain Docker credentials.get)stdoutstdinstderrzexecutable not found: zhttps://zutf-8)inputr   z6Credentials not found, falling back to anonymous auth.z4Error fetching credential for %s, exit status: %d
%sz)Successfully obtained Docker credentials.UsernameSecret)formatre   logginginfo
subprocessPopenPIPESTDOUTOSErrorerrnoENOENT	Exceptioncommunicaterg   rF   strip_MAGIC_NOT_FOUND_MESSAGEr   r   
returncodejsonloadsrI   r4   )r   bin_namerK   erl   blobs         r   r   
Helper.Get   sl   
 *00djj0AHLL<hG	


U
""	$a ]]DNN*227;  ==>@F||~11llKL[__||qMzz1<<89 : : ::fmmG,-DLL<=j!4>26688)  	
ELL	 08;<<s   AE9 9
F5-F00F5)re   rg   )	r   r   r   r   r   r*   r   r   rM   rN   s   @r   rb   rb      s    C	'!9 !9r   rb   c                   <    \ rS rSrSr\R                  S 5       rSrg)Keychain   z;Interface for resolving an image reference to a credential.c                     g)zResolves the appropriate credential for the given registry.

Args:
  name: the registry for which we need a credential.

Returns:
  a Provider suitable for use with registry operations.
Nr   )r   rh   s     r   ResolveKeychain.Resolve   r   r   r   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r      s    C  r   r   )z%sz
https://%sz	http://%szhttps://%s/v1/zhttp://%s/v1/zhttps://%s/v2/zhttp://%s/v2/c                      [         R                  S:X  a  [         R                  R                  S5      $ [         R                  R	                  S5      $ )Nntz%USERPROFILE%~)osrh   path
expandvars
expanduserr   r   r   _GetUserHomeDirr      s9    WW_ 77o..77c""r   c                      [         R                  R                  S5      b  [         R                  R                  S5      $ [         R                  R	                  [        5       S5      $ )NDOCKER_CONFIGz.docker)r   environrk   r   joinr   r   r   r   _GetConfigDirectoryr      sB     ZZ^^O$0::>>/**77<<)955r   c                   *    \ rS rSrSrS rS rS rSrg)_DefaultKeychain   z9This implements the default docker credential resolution.c                      S U l         SU l        g )Nzconfig.json_config_dir_config_filer   s    r   r*   _DefaultKeychain.__init__   s    D &Dr   c                     [         R                  R                  U5      (       d  [        SR	                  U5      5      eXl        g )NzNAttempting to override docker configuration directory to invalid directory: {})r   r   isdirr|   rr   r   )r   
config_dirs     r   setCustomConfigDir#_DefaultKeychain.setCustomConfigDir   s;     77==$$ 228&2DF F!r   c                    [         R                  " S[        U5      5        S nU R                  b5  [        R
                  R                  U R                  U R                  5      nO2[        R
                  R                  [        5       U R                  5      n [        R                  " USSS9 n[        R                  " UR                  5       5      nS S S 5        WR!                  S0 5      n["         H2  nXaR$                  -  U;   d  M  ['        XVUR$                  -     U5      s  $    SU;   a  ['        US   U5      $ UR!                  S0 5      n["         H  nXaR$                  -  U;   d  M  XvUR$                  -     nSU;   aI  [(        R*                  " US   5      R-                  S5      n	U	R/                  S	S
5      u  p[1        X5      s  $ SU;   a  SU;   a  [1        US   US   5      s  $ [3        S[        R4                  " U5      -   5      e   [        5       $ ! , (       d  f       GNO= f! [         a    [        5       s $ f = f)Nz,Loading Docker credentials for repository %rrrD   )encodingcredHelpers
credsStoreauthsauth:   r:   r;   z6Unsupported entry in "auth" section of Docker config: )rs   rt   strr   r   r   r   r   r   ioopenr   r   readIOErrorr   rk   _FORMATSrf   rb   rG   	b64decoderI   splitr4   r|   dumps)r   rh   config_filereadercfg
cred_storeformr   entrydecodedr:   r;   s               r   r   _DefaultKeychain.Resolve   s    LL?TKK#GGLL!1!143D3DEkGGLL!4!68I8IJk77;v6&jj' 7 +J			+j!56== 
 sC%t,, GGGR E			&T]]*+U?$$U6]3::6B'&}}S!4
(x*
*5 Z5%8uZ(%
*;<
< Fjj ! !   ;E 76 [s0   H- .%HH- 
H*%H- *H- -IIr   N)	r   r   r   r   r   r*   r   r   r   r   r   r   r   r      s    A&",r   r   )$r   
__future__r   r   r   r   rG   rz   r   r   rs   r   ru   containerregistry.clientr   httplib2oauth2clientr   sixwith_metaclassABCMetaobjectr	   r   r#   r4   rU   rQ   r   rb   r   r   r   r   r   DefaultKeychainr   r   r   <module>r      s    I &  % 
   	   	  0  / 
Is!!#++v6 I 2X 2$9N 9. 	KU K> F /9U /9ds!!#++v6 "#6>x >D #$r   