
    E                        d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z
 ddlmZ dd	lmZ dd
lmZ dZ ej&                  d      Zd ZdefdZd ZdededefdZdefdZdefdZdededefdZdedefdZdedefdZdefdZ dedefdZ!defdZ"d Z#dedefdZ$dedefdZ%dedefd Z&defd!Z'deded"ee   fd#Z(y)$z<Remote repo utils for Artifact Registry repository commands.    )absolute_import)division)unicode_literalsN)List)
exceptions)base)requests)	arg_utilszhttps://github.comz#(http(|s))://proxy\.golang\.org(|/)c                     t        j                  dt        dd            t        j                  dt        dd            t        j                  dt        d	d            t        j                  d
t        dd            t        j                  dt        dd            t        j                  dt        dd            t        j                  dt	                     t        j                  dd      t        j                  dd      t        j                  ddd      t        j                  dt               d      gS )z$Adds the remote-<facade>-repo flags.z--remote-mvn-repoMavenFfacadehide_custom_remotes)helpz--remote-docker-repoDockerz--remote-npm-repoNpmz--remote-python-repoPythonz--remote-apt-repoAptTz--remote-yum-repoYumz--remote-go-repoz--remote-usernamez-Remote Repository upstream registry username.z --remote-password-secret-versionzw          Secret Manager secret version that contains password for the
          remote repository upstream.
          z--service-directory-configz          Service Directory config link for using Private Networks. Format:
          projects/<project>/locations/<location>/namespaces/<namespace>/services/<service>
          )r   hiddenz--remote-repo)r   Argument_RemoteRepoHelpText_OsPackageRemoteRepoHelpText_GoRemoteRepoHelpText_CommonRemoteRepoHelpText     <lib/googlecloudsdk/command_lib/artifacts/remote_repo_util.pyArgsr   #   s*   
 mm
"'uM mm
 "(N mm
"%UK mm
 "(N mm
+ mm
+ mm
#8#: mm
> mm
, mm
& . 	 mm
(*4c5
 5r   returnc                 b    t        | d      xr" t        j                  | j                        dk(  S )zCReturns whether or not the repo mode specifies a remote repository.modeREMOTE_REPOSITORY)hasattrr
   ChoiceToEnumNamer"   )	repo_argss    r   IsRemoteRepoRequestr'   _   s1     i  L

$
$Y^^
48K
Kr   c                    | j                         }|j                  |_        |j                  }|j                  }|s|rR| j                         }| j                         |_        |r||j                  _        |r||j                  _	        ||_
        |j                  rd|_        |j                  rd|_        nd|_        |j                  }|r&| j!                         |_        ||j"                  _        |j&                  rd|j&                  }	}t)        ||	      }
|
r(| j+                         |_        |
|j,                  _        n4t1        |	      r(| j3                         |_        |	|j4                  _        nt9        |	      r(| j3                         |_        |	|j4                  _        nt;        ||	       n|j<                  rd|j<                  }	}t)        ||	      }
|
r(| j?                         |_         |
|j@                  _        npt1        |	      r(| j3                         |_        |	|j4                  _        n=t9        |	      r(| j3                         |_        |	|j4                  _        n
t;        ||	       n|jB                  rd|jB                  }	}t)        ||	      }
|
r(| jE                         |_#        |
|jF                  _        nt1        |	      r(| j3                         |_        |	|j4                  _        nyt9        |	      r(| j3                         |_        |	|j4                  _        nFt;        ||	       n8|jH                  rd|jH                  }	}t)        ||	      }
|
r(| jK                         |_&        |
|jL                  _        nt1        |	      r(| j3                         |_        |	|j4                  _        nt9        |	      r(| j3                         |_        |	|j4                  _        nt;        ||	       nt|jN                  r3d|jN                  |jP                  }}}t)        ||      }
|
rl| jS                         |_*        | jW                         |jT                  _        |
|jT                  j.                  _,        ||jT                  j.                  _-        nt1        t]        ||            r2| j3                         |_        t]        ||      |j4                  _        nt9        |      r?|rt_        j`                  d      | j3                         |_        ||j4                  _        nBt;        ||       n4|jb                  r2d	|jb                  |jd                  }}}t)        ||      }
|
rl| jg                         |_4        | jk                         |jh                  _        |
|jh                  j.                  _,        ||jh                  j.                  _-        nt1        t]        ||            r2| j3                         |_        t]        ||      |j4                  _        nLt9        |      r?|rt_        j`                  d
      | j3                         |_        ||j4                  _        nt;        ||       n|jl                  rd|jl                  }	}t1        |	      r`|	d   dk(  r|	dd }	|	tn        k7  r#tp        js                  |	      stu        ||	dg       | j3                         |_        |	|j4                  _        npt9        |	      rtw        |       nYt;        ||	       nL|jx                  r>|jx                  }	t1        |	      r)| j3                         |_        |	|j4                  _        n|S ||jz                  _>        |S )zTAdds remote repository config to CreateRepositoryRequest or UpdateRepositoryRequest.TFr   r   r   r   r   zR--remote-apt-repo-path is not supported for Artifact Registry Repository upstream.r   zR--remote-yum-repo-path is not supported for Artifact Registry Repository upstream.Go/Nzhttps://proxy.golang.org)?RemoteRepositoryConfigremote_repo_config_descdescriptionremote_usernameremote_password_secret_versionUpstreamCredentialsUsernamePasswordCredentialsusernamePasswordCredentialsusernamepasswordSecretVersionupstreamCredentialsdisable_remote_validationdisableUpstreamValidationenable_ingestion_attestationenableIngestionAttestationservice_directory_configServiceDirectoryConfigserviceDirectoryConfigserviceremote_mvn_repo_ChoiceToRemoteEnumMavenRepositorymavenRepositorypublicRepository_IsRemoteURICommonRemoteRepositorycommonRepositoryuri_IsARRemote_RaiseRemoteRepoUpstreamErrorremote_docker_repoDockerRepositorydockerRepositoryremote_npm_repoNpmRepositorynpmRepositoryremote_python_repoPythonRepositorypythonRepositoryremote_apt_reporemote_apt_repo_pathAptRepositoryaptRepositorySGoogleDevtoolsArtifactregistryV1RemoteRepositoryConfigAptRepositoryPublicRepositoryrepositoryBaserepositoryPath_OsPackageUriar_exceptionsInvalidInputValueErrorremote_yum_reporemote_yum_repo_pathYumRepositoryyumRepositorySGoogleDevtoolsArtifactregistryV1RemoteRepositoryConfigYumRepositoryPublicRepositoryremote_go_repo
GITHUB_URIGOOGLE_MODULE_PROXYmatch$_RaiseCustomUpstreamUnsupportedError._RaiseArtifactRegistryUpstreamUnsupportedErrorremote_repo
repositoryremoteRepositoryConfig)messagesr&   request
remote_cfgr4   secretcreds	sd_configr   remote_inputenum_messageremote_baseremote_paths                r   AppendRemoteRepoConfigToRequestru   g   s   ..0*$<<*&&(33&((*E(0(L(L(NE%3;e''0@Fe''=%*J" ((+/J( ++,0J),1J) 00)(0(G(G(IJ%09J%%- "I$=$=LF&v|<L#+#;#;#=j 4@j  1	l	#$,$C$C$Ej!(4j!!%	\	"$,$C$C$Ej!(4j!!%#FL9 ###Y%A%ALF&v|<L$,$=$=$?j!5Aj!!2	l	#$,$C$C$Ej!(4j!!%	\	"$,$C$C$Ej!(4j!!%#FL9    )";";LF&v|<L!)!7!7!9j2>j/	l	#$,$C$C$Ej!(4j!!%	\	"$,$C$C$Ej!(4j!!%#FL9 ###Y%A%ALF&v|<L$,$=$=$?j!5Aj!!2	l	#$,$C$C$Ej!(4j!!%	\	"$,$C$C$Ej!(4j!!%#FL9   !!&& %KF
 'v{;L!)!7!7!9j

f
f
h / BNj//>ALj//>	mK=	>$,$C$C$Ej!(5k;(Oj!!%	[	!	22$
 	
 %-$C$C$Ej!(3j!!%#FK8   !!&& %KF
 'v{;L!)!7!7!9j

f
f
h / BNj//>ALj//>	mK=	>$,$C$C$Ej!(5k;(Oj!!%	[	!	22$
 	
 %-$C$C$Ej!(3j!!%#FK8 !9!9LFL!	b	S	 #CR(		#,?,E,E
- 	-L#=">	
 %-$C$C$Ej!(4j!!%	\	"4V<#FL9 ((LL!$,$C$C$Ej!(4j!!%N.8'+	.r   r   r   c                     |r5dj                  | | j                         t        |       t        |             S dj                  | | j                         t        |       t        |             S )Nzu({facade} only) Repo upstream for {facade_lower} remote repository.
REMOTE_{command}_REPO must be one of: [{enums}].
)r   facade_lowercommandenumsz({facade} only) Repo upstream for {facade_lower} remote repository.
REMOTE_{command}_REPO can be either:
  - one of the following enums: [{enums}].
  - an http/https custom registry uri (ex: https://my.{facade_lower}.registry)
)formatlower_LanguagePackageCommandName_EnumsStrForFacader   s     r   r   r   $  ss     F\\^+F3 (	  

 F<<>)&1v&	  
r   c                       	 y)Nzf(Go only) Repo upstream for Go remote repository. "https://proxy.golang.org/" is the only valid value.r   r   r   r   r   r   <  s    =r   c                       	 y)NzAn upstream for a given remote repository. Ex: "https://github.com", "https://docker.io/v2/" are valid values for their given formats of Go and Docker respectively.r   r   r   r   r   r   C  s    %r   c                     |r:dj                  | | j                         | j                         t        |             S dj                  | | j                         | j                         t        |             S )Nz|({facade} only) Repository base for {facade_lower} remote repository.
REMOTE_{facade_upper}_REPO must be one of: [{enums}].
)r   rw   facade_upperry   z({facade} only) Repository base for {facade_lower} remote repository.
REMOTE_{facade_upper}_REPO can be either:
  - one of the following enums: [{enums}].
  - an http/https custom registry uri (ex: https://my.{facade_lower}.registry)
)rz   r{   upperr}   r   s     r   r   r   K  su     F\\^\\^ (	  

 F<<><<>v&	  
r   c                 .    | dk(  ry| j                         S )Nr   MVN)r   r   s    r   r|   r|   c  s    w	r   rq   c                     t        |       }t        j                  |      }	 |j                  |      S # t        $ r Y yw xY w)zJConverts the remote repo input to a PublicRepository Enum message or None.N)_EnumsMessageForFacader
   r%   lookup_by_nameKeyError)r   rq   ry   names       r   r@   r@   i  sD    
 
(%		#	#L	1$%%	 s   3 	??c                 b   t        j                         j                         j                  t        j                         j	                         j                  t        j                         j                         j                  t        j                         j                         j                  t        j                         j                         j                  t        j                         j                         j                  t        j                         j                         d}| |vry||    S )z8Returns the PublicRepository enum messages for a facade.)r   r   r   r   r   r   RubyN)ar_requestsGetMessagesrA   PublicRepositoryValueValuesEnumrK   rN   rQ   rW   RepositoryBaseValueValuesEnumra   rE   )r   facade_to_enums     r   r   r   s  s     
!
!
#?** 
!
!
#** 
!
!
#=?** 
!
!
#** 
!
!
#^^`(( 
!
!
#^^`(( 
!
!
#!!#C#.H >!		r   c                 *    t        t        |             S )zFReturns the human-readable PublicRepository enum strings for a facade.)_EnumsMessageToStrr   r   s    r   r}   r}     s    	26:	;;r   c                     | ydj                  d t        | j                         j                               D              S )z9Returns the human-readable PublicRepository enum strings. , c              3   V   K   | ]!  \  }}|d k7  rt        j                  |       # yw)r   N)r
   EnumNameToChoice).0r   numbers      r   	<genexpr>z%_EnumsMessageToStr.<locals>.<genexpr>  s.      9,$	1   &9s   '))joinsortedto_dictitems)ry   s    r   r   r     s<    
]	  !6!6!89 
 r   c                 .    |s| S | d   dk7  r| dz   } | |z   S )Nr*   r+   r   )rs   rt   s     r   rZ   rZ     s,    	_#K	{	""r   c                 J    | j                  d      xs | j                  d      S )Nzhttps://zhttp://
startswithrq   s    r   rD   rD     s*    		 	 	, 
0G0G1 r   c                 $    | j                  d      S )Nz	projects/r   r   s    r   rH   rH     s    		 	 	--r   c                 |    d}t        |       rt        |       }d| d}d}t        j                  d| d| |       )z1Raises an error for a remote repo upstream error.r   zJ If you intended to enter a well known upstream repo, valid choices are: [z].zd If you intended to enter a custom upstream URI, this value must start with 'https://' or 'http://'.z.Invalid repo upstream for remote repository: 'z'.)r}   r   r[   r\   )r   rq   well_known_enum_requirementry   custom_uri_requirements        r   rI   rI     sm     ""6*E		  '  	,,.678N7OQ	 r   c                 4    t        j                  d|  d      )Nz0Artifact Registry upstream is not supported for .)r[   r\   r   s    r   rg   rg     s!    ,,8B	 r   allowedc           	      b    dj                  |      }t        j                  d| d|  d| d      )Nr   zCustom upstream z is not supported for z. Valid choices are [z].
)r   r[   r\   )r   rq   r   allowed_choicess       r   rf   rf     sF     IIg&/,,&<VH E&'t-	 r   ))__doc__
__future__r   r   r   retypingr    googlecloudsdk.api_lib.artifactsr   r[   googlecloudsdk.callioper   $googlecloudsdk.command_lib.artifactsr	   r   $googlecloudsdk.command_lib.util.apisr
   rc   compilerd   r   boolr'   ru   strr   r   r   r   r|   r@   r   r}   r   rZ   rD   rH   rI   rg   rf   r   r   r   <module>r      sa   C &  ' 	  H ( H :!
 bjj* 
9xd zz $ 3 0s 3  4 C 0   3 ( 3 ( V<s <s <
 #s t .c .d .# S (3 "-1#Yr   