
    ~!                        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
Jr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKr\R>                  " S5      r \R>                  " S5      r!\RD                  \RF                   " S S\RH                  5      5       5       r%g)a  A git credential helper that provides Google git repository passwords.

Reads a session from stdin that looks a lot like:
  protocol=https
  host=code.google.com
And writes out a session to stdout that looks a lot like:
  username=me
  password=secret

Errors will be reported on stderr.

Note that spaces may be part of key names so, for example, "protocol" must not
be proceeded by leading spaces.
    )absolute_import)division)unicode_literalsN)
exceptions)base)log)
properties)creds)store)files)	platforms)clientz	(.+)=(.*)z^ *$c                       \ rS rSrSrSrSr\\/rSr\	S 5       r
\R                  " \R                  \R                   5      S 5       rS rS	 rS
rg)	GitHelper<   zEA git credential helper to provide access to Google git repositories.getr   zgooglesource.comc                 F    U R                  SSS9  U R                  SSSS9  g )Nmethodz!The git credential helper method.)helpz--ignore-unknown
store_truezTProduce no output and exit with 0 when given an unknown method (e.g. store) or host.)actionr   )add_argument)parsers    lib/surface/auth/git_helper.pyArgsGitHelper.ArgsG   s;    
@  B
*+H  J    c           
      n	  ^^ [         R                  R                  R                  R	                  S5        UR
                  [        R                  ;  a]  UR                  (       a  g[        R                  " SR                  UR
                  SR                  [        R                  5      S95      eU R                  5       nS[        R                  /mSSS	S
[        R                  -   /m[         R                  R                  R                   R#                  5       nU(       a   TR%                  UR'                  S5      5        UR)                  S5      nUU4S jnU" U5      (       d5  UR                  (       d#  [        R                  " SR                  US95      egUR
                  [        R*                  :X  Ga#  [         R                  R                  R,                  R#                  5       n [.        R0                  " USS9n[.        R2                  " U5        U RG                  5         U[        R                  :X  d'  URI                  S
[        R                  -   5      (       a  Sn	OUn	[J        RL                  " U5      (       a  URN                  n
OURP                  n
[8        RR                  R=                  [>        R@                  " S5      R                  XS95        gUR
                  [        RT                  :X  Ga  [V        RX                  R[                  5       [V        RX                  R\                  :X  a  [^        R`                  " S5         SR                  UR)                  S5      UR)                  S5      S9n[^        R`                  " SU5        [b        Rd                  " SS/[b        Rf                  [b        Rf                  [b        Rf                  S9nURi                  U5      u  pURj                  (       a  [^        R`                  " SX5        gggg! [4        R6                   a^  n[8        R:                  R=                  [>        R@                  " SR                  [B        RD                  " U5      S95      5         SnAgSnAff = f! [l         a  n[^        R`                  " S SS!9   SnAgSnAff = f)"zRun the helper command.FNz8Unexpected method [{meth}]. One of [{methods}] expected.z, )methmethodssource.developers.google.comz.sourcemanager.devz.blueoryx.devz.developerconnect.dev.,hostc                 V   > U T;   a  gT H  nU R                  U5      (       d  M    g   g)NTF)endswith)r$   suffixcredentialed_domainscredentialed_domains_suffixs     r   _ValidateHost$GitHelper.Run.<locals>._ValidateHostn   s0    	%	%/&==   0 r   zUnknown host [{host}].)r$   T)use_google_authzV            ERROR: {error}
            Run 'gcloud auth login' to log in.
            )errorzgit-accountzF          username={username}
          password={password}
          )usernamepasswordzClearing OSX credential cache.z!protocol={protocol}
host={host}

protocol)r0   r$   zCalling erase with input:
%szgit-credential-osxkeychainerase)stdinstdoutstderrz7Failed to clear OSX keychain:
stdout: {%s}
stderr: {%s}zFailed to clear OSX keychain)exc_info)7r	   VALUESauth#service_account_use_self_signed_jwtSetr   r   METHODSignore_unknownauth_exceptionsGitCredentialHelperErrorformatjoin_ParseInputGOOGLESOURCEcore credentialed_hosted_repo_domainsGetextendsplitr   GETaccountc_storeLoadRefreshcreds_exceptionsErrorsysr4   writetextwrapdedentsix	text_type_CheckNetrcr&   c_credsIsOauth2ClientCredentialsaccess_tokentokenr3   STOREr   OperatingSystemCurrentMACOSXr   debug
subprocessPopenPIPEcommunicate
returncode	Exception)selfargsinfoextrar$   r*   rH   credesent_accountrW   input_stringpouterrr(   r)   s                  @@r   RunGitHelper.RunP   s   
 >>BB5I{{)+++			44
D6t{{DIIi6G6G,H6IK K D&
 	I"""	# ""CCGGIE!!%++c"2388FD   66$+++68 	8{{imm#!!&&..224g||GT:  )((
(]]3y55566$		*	*4	0	0((zz	jj
//   v|vC	E
 
		' 
#
#
+
+
-

#
#
*
*+		23	C?FFxx
+$((62B G D,
))3\
B <gF%/__&0oo&0oo7! }}\2*3\\IIK + 
(7 ## 

 * S]]1-.0 	1 	l  	C
))2T
B	Cs2   /+P CR R*ARR
R4R//R4c                 R   0 n[         R                   H  n[        R                  U5      (       a  M  [        R                  U5      nU(       d2  [
        R                  " SR                  UR                  S5      S95      eUR                  5       u  pEUR                  5       X'   M     SU;  a  [
        R                  " S5      eSU;  a  [
        R                  " S5      eUR                  S5      S:w  a2  [
        R                  " S	R                  UR                  S5      S
95      eU$ )z[Parse the fields from stdin.

Returns:
  {str: str}, The parsed parameters given on stdin.
z&Invalid input line format: [{format}].
)r>   r0   z Required key "protocol" missing.r$   zRequired key "host" missing.httpsz*Invalid protocol [{p}].  "https" expected.)rl   )rN   r2   _BLANK_LINE_REmatch
_KEYVAL_REr<   r=   r>   rstripgroupsstripr   )rd   rf   lineru   keyvals         r   r@   GitHelper._ParseInput   s
    D					d	#	#t$e664V4;;t,V-/ 	/ hc))+di  44
,. . T44
(* * xx
w&44
66DHHZ(6)+ + Kr   c                     S nU" [         R                  " [        R                  R	                  SS5      5      5        U" [         R                  " [        R                  R	                  SS5      5      5        g)z:Warn on stderr if ~/.netrc contains redundant credentials.c                 *   [         R                  R                  U 5      (       d  g [        R                  " U 5      nSU;   aA  [
        R                  R                  [        R                  " SR                  U S95      5        gg! [         a     gf = f)z9Warn about other credential helpers that will be ignored.Nr!   zYou have credentials for your Google repository in [{path}]. This repository's
git credential helper is set correctly, so the credentials in [{path}] will not
be used, but you may want to remove them to avoid confusion.
)path)osr   existsr   ReadFileContentsrN   r4   rO   rP   rQ   r>   rc   )rl   datas     r   Check$GitHelper._CheckNetrc.<locals>.Check   s}    WW^^A
%%a()T1
**

8?? , FFN	  2  s   AB 
BB~z.netrc_netrcN)r   ExpandHomeDirr   r   r?   )rd   r   s     r   rT   GitHelper._CheckNetrc   sM     
%

bggll39
:;	%

bggll39
:;r    N)__name__
__module____qualname____firstlineno____doc__rG   rY   r:   rA   staticmethodr   c_excRaiseErrorInsteadOfr<   AuthenticationErrorr   rM   ro   r@   rT   __static_attributes__r   r   r   r   r   <   sp     N#
%%L'#,J J 	_@@&,,OgC PgCR@<r   r   )&r   
__future__r   r   r   r   rer^   rN   rP   googlecloudsdk.api_lib.authr   r<   googlecloudsdk.callioper   r   googlecloudsdk.corer   r	   googlecloudsdk.core.credentialsr
   rU   rL   r   rI   googlecloudsdk.core.utilr   r   oauth2clientr   rR   compilerv   rt   HiddenDefaultUniverseOnlyCommandr   r   r   r   <module>r      s     '  ' 	 	  
  E ( 7 # * < J < * .  
 ZZ%
G$ o< o<  o<r   