
    [0                        S r SSKJr  SSKJr  SSKJ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rSrSrSrS rS rS rS rS r S r!S r"S r#S r$S r%S r&S  r'S! r(S" r)g)#zAUtility for forming settings for Artifacts Registry repositories.    )absolute_import)division)unicode_literalsN)
exceptions)requests)util)apt)credentials)gradle)mvn)npm)python)yum)
propertiesz2.2.0zFailed to find attribute [project]. The attribute can be set in the following ways:
- provide the argument [--project] on the command line
- set the property [core/project]zFailed to find attribute [repository]. The attribute can be set in the following ways:
- provide the argument [--repository] on the command line
- set the property [artifacts/repository]zFailed to find attribute [location]. The attribute can be set in the following ways:
- provide the argument [--location] on the command line
- set the property [artifacts/location]c                     U R                   (       dQ  [        R                  R                  R                   R	                  5       (       d  [
        R                  " [        5      e[        R                  " U 5      $ N)
projectr   VALUEScoreGetar_exceptionsInvalidInputValueError_PROJECT_NOT_FOUND_ERRORar_util
GetProjectargss    Hlib/googlecloudsdk/command_lib/artifacts/print_settings/settings_util.py_GetRequiredProjectValuer   8   sL    	j//44<<@@BB

.
./G
HH			D	!!    c                     U R                   (       dQ  [        R                  R                  R                   R	                  5       (       d  [
        R                  " [        5      e[        R                  " U 5      $ r   )

repositoryr   r   	artifactsr   r   r   _REPO_NOT_FOUND_ERRORr   GetRepor   s    r   _GetRequiredRepoValuer&   >   sJ    	!2!2!<!<!G!G!K!K!M!M

.
./D
EE		r    c                     U R                   (       dQ  [        R                  R                  R                   R	                  5       (       d  [
        R                  " [        5      e[        R                  " U 5      $ r   )
locationr   r   r#   r   r   r   _LOCATION_NOT_FOUND_ERRORr   GetLocationr   s    r   _GetRequiredLocationValuer+   D   sL    	z00::CCGGII

.
./H
II			T	""r    c                 &   [        U 5      n[        U 5      n[        U 5      nUS-   U-   n[        R                  " SR                  X4U5      5      nUR
                  U:w  a0  [        R                  " SR                  UR
                  U5      5      eXE4$ z,Get resource values and validate user input./(projects/{}/locations/{}/repositories/{}z-Invalid repository type {}. Valid type is {}.)r&   r   r+   ar_requestsGetRepositoryformatr   r   r   repo_formatrepor   r(   	repo_paths         r   _GetLocationAndRepoPathr7   J   s    	t	$$$T*'&t,(md")		"	"0778<>
?$ 
[[K

.
.7>>KK	&' ' 
	r    c                 <   [        U 5      n[        U 5      n[        U 5      nUS-   U-   n[        R                  " SR                  X4U5      5      nUR
                  U:w  a0  [        R                  " SR                  UR
                  U5      5      eXEUR                  4$ r-   )	r&   r   r+   r0   r1   r2   r   r   mavenConfigr3   s         r   "_GetLocationRepoPathAndMavenConfigr:   Z   s    	t	$$$T*'&t,(md")		"	"0778<>
?$ 
[[K

.
.7>>KK	&' ' 
d..	..r    c                     [         R                  " SR                  XU5      5      n[        US5      (       a7  UR                   H'  nSUR
                  ;   d  M  SUR                  ;   d  M'    g   g)zDetermine if a repository is public.

Args:
  project: Project name.
  location: Repository location.
  repo: Repository name.

Returns:
  bool, True if repository is public.
r/   bindingsallUserszartifactregistry.readerTF)r0   GetIamPolicyr2   hasattrr<   membersrole)r   r(   r5   
iam_policybindings        r   IsPublicReporD   j   sf     ''077
T#$* Z$$&&

''7<<7 '
 
r    c                 D   [         R                  " 5       n[        XR                  R                  R
                  5      u  p#[        U 5      n[        U 5      nUUUUS.n[        XRU5      (       a  [        R                  nO[        R                  nUR                  " S0 UD6$ )zForms an apt settings snippet to add to the sources.list.d directory.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  An apt settings snippet.
)r(   r   r5   r6    )r0   GetMessagesr7   
RepositoryFormatValueValuesEnumAPTr&   r   rD   r	   PUBLIC_TEMPLATEDEFAULT_TEMPLATEr2   )r   messagesr(   r6   r5   r   dataapt_setting_templates           r   GetAptSettingsSnippetrP      s     $$&(/
5599;(	t	$$$T*' 	
$ 'T**..//		$	$	,t	,,r    c                 @   [         R                  " 5       n[        XR                  R                  R
                  5      u  p#[        U 5      n[        U 5      nX$US.n[        XRU5      (       a  [        R                  nO[        R                  nUR                  " S0 UD6$ )zForms a Yum settings snippet to add to the yum.repos.d directory.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  A yum settings snippet.
)r(   r5   r6   rF   )r0   rG   r7   rH   rI   YUMr&   r   rD   r   rK   rL   r2   )r   rM   r(   r6   r5   r   rN   yum_setting_templates           r   GetYumSettingsSnippetrT      s     $$&(/
5599;(	t	$$$T*'9	E$'T**..//		$	$	,t	,,r    c                    [         R                  " 5       n[        XR                  R                  R
                  5      u  p#SR                  " S0 UUS.D6nSnU R                  (       aa  U R                  R                  S5      (       a  [        U R                  5      S::  a  [        R                  " S5      eU R                  S-   U-   nUUUS.n[        R                  " U R                  5      nU(       aH  [        R                   n["        R$                  " UR'                  S	5      5      R)                  S	5      US
'   O[        R*                  nUR                  " S0 UD6$ )zForms an npm settings snippet to add to the .npmrc file.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  An npm settings snippet.
z#{location}-npm.pkg.dev/{repo_path}/r(   r6   registry@   z>Scope name must start with "@" and be longer than 1 character.:)configured_registryregistry_pathr6   zutf-8passwordrF   )r0   rG   r7   rH   rI   NPMr2   scope
startswithlenr   r   r
   GetServiceAccountCredsjson_keyr   SERVICE_ACCOUNT_TEMPLATEbase64	b64encodeencodedecodeNO_SERVICE_ACCOUNT_TEMPLATE)	r   rM   r(   r6   r\   r[   rN   sa_credsnpm_setting_templates	            r   GetNpmSettingsSnippetrl      s;    $$&(/
5599;(7>> B - #	ZZ::  %%TZZA)=00
LN N**s*-@@ 1$
$ //>(77'' ""(&/ 	 ::		$	$	,t	,,r    c                 L   [         R                  " 5       n[        XR                  R                  R
                  5      u  p#nSUSUS.n[        R                  " U R                  5      n[        XU5      nU(       a  SUS'   SUS'   XeS'   O	[        US	'   UR                  " S
0 UD6$ )zForms a maven snippet to add to the pom.xml file.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  str, a maven snippet to add to the pom.xml file.
artifactregistryzartifact-registry)schemer(   	server_idr6   httpsro   _json_key_base64usernamer]   extension_versionrF   )r0   rG   r:   rH   rI   MAVENr
   rb   rc   GetMavenTemplate_EXT_VERSIONr2   )r   rM   r(   r6   	maven_cfgrN   rj   mvn_templates           r   GetMavenSnippetrz      s     $$&(#E
55;;$= (y #&	
$ //>(!(x@,DN)D ,D					$t	$$r    c                    [         R                  nU(       aW  UR                  U R                  R                  R
                  :X  a)  [         R                  nU(       a  [         R                  nU$ U(       aW  UR                  U R                  R                  R                  :X  a)  [         R                  nU(       a  [         R                  nU$ U(       a  [         R                  nU$ )a9  Forms a maven snippet to add to the pom.xml file.

Args:
  messages: Module, the messages module for the API.
  maven_cfg: MavenRepositoryConfig, the maven configuration proto that
    contains the version policy.
  sa_creds: str, service account credentials.

Returns:
  str, a maven template to add to pom.xml.
)r   ri   versionPolicyMavenRepositoryConfigVersionPolicyValueValuesEnumSNAPSHOT$NO_SERVICE_ACCOUNT_SNAPSHOT_TEMPLATE!SERVICE_ACCOUNT_SNAPSHOT_TEMPLATERELEASE#NO_SERVICE_ACCOUNT_RELEASE_TEMPLATE SERVICE_ACCOUNT_RELEASE_TEMPLATErd   )rM   rx   rj   ry   s       r   rv   rv     s     00,9**h.L.L.i.i.r.rr;;L::l 
 Y,,0N0N0k0k0s0ss::L99l 
 //L	r    c                 <   [         R                  " 5       n[        XR                  R                  R
                  5      u  p#n[        R                  " U R                  5      n[        XU5      nX#S.nU(       a
  SUS'   XWS'   O	[        US'   UR                  " S0 UD6$ )zForms a gradle snippet to add to the build.gradle file.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  str, a gradle snippet to add to build.gradle.
rV   rr   rs   r]   rt   rF   )r0   rG   r:   rH   rI   ru   r
   rb   rc   GetGradleTemplaterw   r2   )r   rM   r(   r6   rx   rj   gradle_templaterN   s           r   GetGradleSnippetr     s     $$&(#E
55;;$= (y//>(%h8D/	7$)D !-D					'$	''r    c                    [         R                  nU R                  R                  R                  nU R                  R                  R
                  nU(       a9  UR                  U:X  a)  [         R                  nU(       a  [         R                  nU$ U(       a9  UR                  U:X  a)  [         R                  nU(       a  [         R                  nU$ U(       a  [         R                  nU$ )aF  Forms a gradle snippet to add to the build.gradle file.

Args:
  messages: Module, the messages module for the API.
  maven_cfg: MavenRepositoryConfig, the maven configuration proto that
    contains the version policy..
  sa_creds: str, service account credentials.

Returns:
  str, a gradle template to add to build.gradle.
)r   ri   r}   r~   r   r   r|   r   r   r   r   rd   )rM   rx   rj   r   snapshotreleases         r   r   r   7  s     66/$$AAJJ  **GGOO'9**h6AAO@@o 
 Y,,7@@O??o 
 55O	r    c                 x   [         R                  " 5       n[        XR                  R                  R
                  5      u  p#[        U 5      nX#US.n[        R                  " U R                  5      nU(       a$  XeS'   [        R                  R                  " S0 UD6$ [        R                  R                  " S0 UD6$ )zForms a Python snippet for .pypirc file (twine) and pip.conf file.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  A python snippet.
)r(   r6   r5   r]   rF   )r0   rG   r7   rH   rI   PYTHONr&   r
   rb   rc   r    SERVICE_ACCOUNT_SETTING_TEMPLATEr2   #NO_SERVICE_ACCOUNT_SETTING_TEMPLATE)r   rM   r(   r6   r5   rN   rj   s          r   GetPythonSettingsSnippetr   V  s     $$&(/
55<<>(	t	$$	E$//>(2299ADAA55<<DtDDr    )*__doc__
__future__r   r   r   re    googlecloudsdk.api_lib.artifactsr   r   $googlecloudsdk.command_lib.artifactsr   r0   r   r   3googlecloudsdk.command_lib.artifacts.print_settingsr	   r
   r   r   r   r   r   googlecloudsdk.corer   rw   r   r$   r)   r   r&   r+   r7   r:   rD   rP   rT   rl   rz   rv   r   r   r   rF   r    r   <module>r      s    H &  '  H H @ C K F C C F C *% - + "# / 0-<-4%-P%@6(4>Er    