
    #n              
          S r SSKrSSKrSSKrSSKrSSKJrJrJr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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+J-r-  SSK+J.r.  SSK+J/r/  SSK0J1r1  SSK2J3r3  Sr4S\5S\5S \54S! jr6 " S" S#5      r7 " S$ S%5      r8 " S& S'5      r9 " S( S)5      r: " S* S+5      r; " S, S-5      r< " S. S/5      r= " S0 S15      r>S2\7S S4S3 jr?S \54S4 jr@S5\5S\5S6\S7\R                  S S4
S8 jrBS \54S9 jrCg):a  Command library for run compose resource command.

This library handles the creation of Google Cloud resources required to deploy a
Docker Compose application to Cloud Run. It's utilized by the
`gcloud run compose up` command.

The core responsibilities include:
  1.  Parsing the JSON output from the 'runcompose' Go binary, which lists
      the necessary resources based on the compose file.
  2.  Providing classes to represent these resources (e.g., Cloud Build).
  3.  Orchestrating the creation of these resources in Google Cloud.
    N)AnyDictListOptional)projects_api)global_methods)service)api)storage_api)storage_util)apis)messages)base)iam_util)config_changes)connection_context)
exceptions)flags)	platforms)serverless_operations)stages)builder)tracker)log)
properties)	resources)yaml)progress_tracker)files?   compose_project_nameregionreturnc                 V   [        5       nU R                  5       n[        R                  " SSU5      n[        R                  " SSU5      nU SU SU S3n[	        U5      [
        :  a@  [        R                  " UR                  5       5      R                  5       SS nU SU SU S3$ U$ )a  Generates a unique bucket name for the compose project.

The bucket name is derived from the project number, a sanitized version of
the compose project name, and the region. To ensure the bucket name
adheres to GCS naming conventions (e.g., max length), a hash is used
if the initial candidate name is too long.

Args:
  compose_project_name: The name of the Docker Compose project.
  region: The Google Cloud region.

Returns:
  A valid GCS bucket name.
z[^a-z0-9-]+-z-+z-composeN   )
_get_project_numberlowerresublen_MAX_BUCKET_NAME_LENGTHhashlibsha1encode	hexdigest)r!   r"   project_numbersanitized_project_namebucket_name_candidateproject_hashs         >lib/googlecloudsdk/command_lib/run/compose/compose_resource.py_generate_gcs_bucket_namer6   B   s     '(./55766.#7MN66%.DE 
016((C  		"99<<%%'ik"1L Q|nAfXX>>      c                       \ rS rSrSr   SS\\   S\\   S\\   4S jjr\S\	\\
4   S	S 4S
 j5       rSS jrS	\	\\
4   4S jrSrg)SecretConfigg   z2Represents the secret configuration for a service.Nnamefilemountc                 6    Xl         X l        S U l        X0l        g N)r;   r<   secret_versionr=   )selfr;   r<   r=   s       r5   __init__SecretConfig.__init__j   s     II)-DJr7   datar#   c                     U " UR                  S5      UR                  S5      UR                  S5      S9nUR                  S5      Ul        U$ )Nr;   r<   r=   )r;   r<   r=   r@   )getr@   clsrD   configs      r5   	from_dictSecretConfig.from_dictv   sI    XXfXXfhhwF
 !HH%56FMr7   c                 \    [         R                  " SU R                  5        [        U 5        g)zCreates the secret in Google Secret Manager and adds a version.

This method calls the internal function _create_secret_and_add_version
to perform the actual resource creation and versioning.
zHandling secret: %sN)r   debugr;   _create_secret_and_add_versionrA   s    r5   handleSecretConfig.handle   s     II#TYY/"4(r7   c                 `    U R                   U R                  U R                  U R                  S.$ )z5Serializes the SecretConfig instance to a dictionary.r;   r<   r=   r@   rS   rO   s    r5   to_dictSecretConfig.to_dict   s,     				--	 r7   )r<   r=   r;   r@   NNN)r#   N__name__
__module____qualname____firstlineno____doc__r   strrB   classmethodr   r   rJ   rP   rT   __static_attributes__ r7   r5   r9   r9   g   s    : ! !	
SM
 SM
 c]	
 4S> n  )tCH~ r7   r9   c                       \ rS rSrSr   SS\\   S\\   S\\   4S jjr\S\	\\
4   S	S 4S
 j5       rS\S\S	S4S jrS	\	\\
4   4S jrSrg)Config   z2Represents the config configuration for a service.Nr;   r<   targetc                 6    Xl         X l        X0l        S U l        g r?   r;   r<   rd   bucket_name)rA   r;   r<   rd   s       r5   rB   Config.__init__   s     IIK&*Dr7   rD   r#   c                     U " UR                  S5      UR                  S5      UR                  S5      S9nUR                  S5      Ul        U$ )Nr;   r<   rd   )r;   r<   rd   rg   )rF   rg   rG   s      r5   rJ   Config.from_dict   sH    XXfXXfxx!F
 -0FMr7   rg   r"   c                    U R                   (       d#  [        R                  " SU R                   35      e[        R
                  " SU R                   5        [        X5      nUR                  5         Xl        U R                  nU(       a$  [        R                  R                  U5      (       d'  [        R                  " SU SU R                    S35      e[        R                  R                  U5      nSR                  SU R                   U/5      n[        R                  R                  U5      (       a  UR                  Xd5        g
[        R                  " SU S	35      e)z1Handles the creation of resources for the config.z6Config declared without a name, but name is required: Handling config: %szConfig source 'z' for config '' does not exist./configszConfig source path '' is not a file.N)r;   r   Errorr<   r   rM   
GcsHandlerensure_bucketrg   ospathexistsbasenamejoinisfileupload_file)rA   rg   r"   gcs_handlersourcesource_basenamegcs_paths          r5   rP   Config.handle   s   99B499+
N  II#TYY/[1K"YYF//F8>$))<M
N  gg&&v.OxxDII?@H	ww~~fh/3F8;KLMMr7   c                 `    U R                   U R                  U R                  U R                  S.$ )z5Serializes the ConfigConfig instance to a dictionary.rf   rf   rO   s    r5   rT   Config.to_dict   s,     				++''	 r7   )rg   r<   r;   rd   rV   rW   r`   r7   r5   rb   rb      s    : ! "		+SM	+ SM	+ sm		+ 4S> h  N NS NT N0tCH~ r7   rb   c                       \ rS rSrSr SS\\   S\\   4S jjr\S\	\\
4   SS 4S	 j5       rS
SS\SS4S jrS\	\\
4   4S jrSrg)BindMountConfig   z6Represents the bind mount configuration for a service.Nr|   rd   c                 *    Xl         X l        S U l        g r?   r|   rd   mount_source)rA   r|   rd   s      r5   rB   BindMountConfig.__init__   s     KK'+Dr7   rD   r#   c                 |    U " UR                  S5      UR                  S5      S9nUR                  S5      Ul        U$ )Nr|   rd   )r|   rd   r   )rF   r   rG   s      r5   rJ   BindMountConfig.from_dict   s<    xx!xx!F
 ((>2FMr7   r{   rr   service_namec                    UR                  5         U R                  nU(       a$  [        R                  R	                  U5      (       d  [
        R                  " SU SU S35      e[        R                  R                  U5      [        R                  " 5       :X  a  SR                  SU/5      nO2[        R                  R                  U5      nSR                  SX%/5      nX@l        [        R                  R                  U5      (       a  UR                  XC5        g[        R                  R                  U5      (       a  UR                  XC5        g[
        R                  " SU S35      e)	z5Handles the creation of resources for the bind mount.zBind mount source 'z' for service 'rm   rn   bind_mountsSource path 'z' is not a file or directory.N)rs   r|   rt   ru   rv   r   rq   abspathgetcwdrx   rw   r   isdirupload_directoryry   rz   )rA   r{   r   r|   r~   r}   s         r5   rP   BindMountConfig.handle   s   [[F//x|n E   
wwv"))+-=,78h((0o=,HIh 	ww}}V""84			h/&!>
? r7   c                 J    U R                   U R                  U R                  S.$ )z8Serializes the BindMountConfig instance to a dictionary.r   r   rO   s    r5   rT   BindMountConfig.to_dict   s%     ++++)) r7   )r   r|   rd   NNrW   r`   r7   r5   r   r      s    > CG,SM,2:3-, 4S> .?   C D 6tCH~ r7   r   c                   n    \ rS rSrSrSS\\   4S jjr\S\	\\
4   SS 4S j5       rS\	\\
4   4S	 jrS
rg)NamedVolumeConfigi  z8Represents the named volume configuration for a service.Nr;   c                     Xl         g r?   r;   )rA   r;   s     r5   rB   NamedVolumeConfig.__init__	  s    Ir7   rD   r#   c                 ,    U " UR                  S5      S9$ )Nr;   r   rF   )rH   rD   s     r5   rJ   NamedVolumeConfig.from_dict  s    XXf r7   c                     SU R                   0$ )z:Serializes the NamedVolumeConfig instance to a dictionary.r;   r   rO   s    r5   rT   NamedVolumeConfig.to_dict  s     			 r7   r   r?   )rX   rY   rZ   r[   r\   r   r]   rB   r^   r   r   rJ   rT   r_   r`   r7   r5   r   r     sT    @8C=  4S> .A  
tCH~ r7   r   c                   n    \ rS rSrSrS\S\4S jrS rS\SS4S	 jrS
\S\SS4S jr	S
\S\SS4S jr
Srg)rr   i  z-Handles GCS operations for compose resources.rg   r"   c                     [         R                  " SUU5        Xl        X l        [        R
                  " 5       U l        SU l        g )Nz2Initializing GcsHandler for bucket %s in region %sF)r   rM   rg   r"   r   StorageClient_gcs_client_bucket_ensured)rA   rg   r"   s      r5   rB   GcsHandler.__init__  s=    II<
 #K"002D Dr7   c                 l    U R                   (       d#  U R                  U R                  5        SU l         gg)zEnsures the GCS bucket exists.TN)r   _ensure_bucket_existsrg   rO   s    r5   rs   GcsHandler.ensure_bucket'  s,    
  !1!12!d  r7   r#   Nc                     U R                   R                  XR                  S9  [        R                  " SU SU R                   S35         [        5       n[        R                  " U5      nU R                   R                  U5      nUR                  S5      R                  n[        R                  " UUS	U 3S
5        U R                   R!                  XE5        [        R                  " SU SU S35        g! [
         a!  n[        R                  " SU SU 35      eSnAff = f! [
         a!  n[        R                  " SU SU 35      eSnAff = f)z?Creates the GCS bucket if it doesn't exist and sets IAM policy.)locationzEnsured bucket 'z' exists in region ''.zFailed to create bucket '': NbindingsserviceAccount:zroles/storage.objectUserz!Set roles/storage.objectUser for z on bucket 'z$Failed to set IAM policy on bucket ')r   CreateBucketIfNotExistsr"   r   rM   	Exceptionr   rq   _get_compute_service_accountr   BucketReferenceGetIamPolicyfield_by_namemessage_typer   AddBindingToIamPolicySetIamPolicy)rA   rg   eservice_accountbucket_resourcepolicybinding_classs          r5   r    GcsHandler._ensure_bucket_exists-  s[   

..
 /  
ii[M)=dkk]"
M46o$44[Ao,,_=f**:6CCm$$

O,
-
$	 ##O<	ii-o-> ?m2%  %k]#aS
9 ,  0S
D s1   A
C8 B*D& 8
D#DD#&
E0EEr~   source_pathc           	      z   [         R                  R                  U5      (       d  [        R                  " SU S35      e[         R
                  " U5       H  u  p4nU H  n[         R                  R                  X65      n[         R                  R                  Xr5      nSR                  XR                  [         R                  S5      /5      n	[        R                  " U R                  U	5      n
U R                  R                  Xz5        M     M     [        R                   " SU SU R                   SU S35        g)zUploads a directory to GCS.r   z' is not a directory.rn   zUploaded directory '' to 'gs://'N)rt   ru   r   r   rq   walkrx   relpathreplacesepr   ObjectReferencerg   r   CopyFileToGCSr   rM   )rA   r~   r   root_files_in_dir	file_name
local_filerelative_pathgcs_file_path
object_refs              r5   r   GcsHandler.upload_directoryQ  s     77==%%}[M9NOPP!#!5#)WW\\$2

@,,RVVS9:
 "11$2B2BMR
&&z> $ "6 II
{m ,""#1XJa	1r7   c           	      L   [         R                  R                  U5      (       d  [        R                  " SU S35      e[
        R                  " U R                  U5      nU R                  R                  X#5        [        R                  " SU SU R                   SU S35        g)zUploads a single file to GCS.r   rp   zUploaded file 'r   rn   r   N)rt   ru   ry   r   rq   r   r   rg   r   r   r   rM   )rA   r~   r   r   s       r5   rz   GcsHandler.upload_fileh  s    77>>+&&}[M9IJKK--d.>.>IJ"";;II
+k$2B2B1C1XJaPr7   )r   r   rg   r"   )rX   rY   rZ   r[   r\   r]   rB   rs   r   r   rz   r_   r`   r7   r5   rr   rr     sl    5	!# 	!s 	!""s "t "H  	.# C D r7   rr   c                       \ rS rSrSr  SS\\\\\	   4      S\\\\
4      4S jjr\S\\\4   SS 4S	 j5       rS
\S\SS4S jrS\\\4   4S jrSrg)VolumeConfigis  zARepresents the volume configuration for a docker compose project.N
bind_mountnamed_volumec                 B    Ub  UO0 U l         Ub  UO0 U l        S U l        g r?   r   r   rg   )rA   r   r   s      r5   rB   VolumeConfig.__init__v  s)    
 %/$:jDO(4(@bD&*Dr7   rD   r#   c                 v   UR                  S0 5      R                  5        VVVs0 s H+  u  p#X# Vs/ s H  n[        R                  U5      PM     sn_M-     nnnnUR                  S0 5      R                  5        VVs0 s H  u  p#U[        R                  U5      _M     nnnU " XVS9$ s  snf s  snnnf s  snnf )z2Creates a VolumeConfig instance from a dictionary.r   r   )r   r   )rF   itemsr   rJ   r   )rH   rD   keyvalueitemr   r   s          r5   rJ   VolumeConfig.from_dict  s    
 ((<4::<<JC 	%@%$o''-%@@<   ((>26<<>>JC 	((//>   *@@ As   B.B)B.>"B5)B.rg   r"   c                    U R                   (       d(  U R                  (       d  [        R                  " S5        g[        R                  " S5        [	        X5      nUR                  5         Xl        U R                   R                  5        H  u  pEU H  nUR                  X45        M     M!     [        R                  " S5        g)z"Handles all volume configurations.zNo volumes to handle.NzHandling volume configurations.zVolume handling complete.)	r   r   r   rM   rr   rs   rg   r   rP   )rA   rg   r"   r{   r   r   	bm_configs          r5   rP   VolumeConfig.handle  s    ??4#4#4	ii'(II/0[1K" &*__%:%:%<!")3 # &= II)*r7   c                 V   U R                   R                  5        VVVs0 s H%  u  pX Vs/ s H  o3R                  5       PM     sn_M'     snnnU R                  R                  5        VVs0 s H  u  pXR                  5       _M     snnU R                  S.$ s  snf s  snnnf s  snnf )z5Serializes the VolumeConfig instance to a dictionary.r   )r   r   rT   r   rg   )rA   r   r   r   s       r5   rT   VolumeConfig.to_dict  s    
 #oo335
5
 U3UT,,.U335

 483D3D3J3J3L
3LZSC 3L
 ''	 	3

s   BBB,B%B)r   rg   r   r   )rX   rY   rZ   r[   r\   r   r   r]   listr   r   rB   r^   r   rJ   rP   rT   r_   r`   r7   r5   r   r   s  s    I @D=A+4T/%: :;<+ T#'8"89:+ 
A4S> 
An 
A 
A+ +S +T +$tCH~ r7   r   c                   L   \ rS rSrSr     SS\\\\R                  4      S\\\\
4      S\\   S\\   S\\\      4
S	 jjrSS
\S\\   4S jjr\S\SS 4S j5       r\S\\\4   SS 4S j5       r SS\S\S\R.                  S
\SS 4
S jjrS\\\4   4S jrS\4S jrSrg)ResourcesConfigi  z?Represents the resources config sent form runcompose go binary.Nsource_buildssecretsvolumesprojectro   c                     Ub  UO0 U l         Ub  UO0 U l        Ub  UO	[        5       U l        X@l        Ub  XPl        g / U l        g r?   )r   r   r   r   r   ro   )rA   r   r   r   r   ro   s         r5   rB   ResourcesConfig.__init__  sF     +8*CD%17rDL%17|~DLL%17LrDLr7   no_buildr#   c                    SS1nU R                   (       a  U(       d  UR                  1 Sk5        U R                  (       a  UR                  SS15        U R                  R                  (       d,  U R                  R
                  (       d  U R                  (       a  UR                  SS15        [        [        U5      5      $ )zAReturns a list of APIs required for the resources in this config.zrun.googleapis.comz#cloudresourcemanager.googleapis.com>   storage.googleapis.comcloudbuild.googleapis.comartifactregistry.googleapis.comzsecretmanager.googleapis.comziam.googleapis.comr   )	r   updater   r   r   r   ro   sortedr   )rA   r   required_apiss      r5   get_required_apis!ResourcesConfig.get_required_apis  s     	-M
 (  	
 ||)+?
@ ||$,,";";t||46JKL$}%&&r7   	json_datac                 T    [         R                  " U5      nU R                  U5      nU$ )z<Parses the JSON string to create a ResourcesConfig instance.jsonloadsrJ   )rH   r   rD   rI   s       r5   	from_jsonResourcesConfig.from_json  s%     ::i D]]4 FMr7   rD   c                 B   UR                  S0 5      R                  5        VVs0 s H%  u  p#U[        R                  R	                  U5      _M'     nnnUR                  S0 5      R                  5        VVs0 s H  u  p#U[
        R	                  U5      _M     nnn[        R	                  UR                  S0 5      5      nUR                  S/ 5       Vs/ s H  n[        R	                  U5      PM     nnUR                  S5      n	U " UUUU	US9$ s  snnf s  snnf s  snf )z5Creates a ResourcesConfig instance from a dictionary.r   r   r   ro   r   )r   r   r   r   ro   )rF   r   r   BuildConfigrJ   r9   r   rb   )
rH   rD   r   r   r   r   r   r   ro   r   s
             r5   rJ   ResourcesConfig.from_dict  s#   
 ((?B7==??JC 	W  **511?   ((9b17799JC 	\##E**9   $$TXXi%<=G+/88Ir+B+B4+B   hhy!G# 
s   ,D6"DDr"   repor   c                    U R                   (       d  [        R                  " S5      eU R                  (       a/  [        R
                  " U R                  UU R                   UUU5        [        R                  " SU R                   5        U R                  (       a  UR                  [        R                  R                  R                  5       5        U R                  R                  5        H.  u  pV[        R                  " SU 35        UR                  5         M0     UR                  [        R                  R                  R                  5       5        U R                   R"                  (       d-  U R                   R$                  (       d  U R&                  (       Ga  [        R                  " S5        [)        U R                   U5      nU R                   R"                  (       d  U R                   R$                  (       a  UR                  [        R                  R*                  R                  5       5        U R                   R                  Xq5        UR                  [        R                  R*                  R                  5       5        U R&                  (       a  UR                  [        R                  R,                  R                  5       5        U R&                   H5  n[        R                  " SUR.                  5        UR                  Xq5        M7     UR                  [        R                  R,                  R                  5       5        U $ )a  Creates or updates all resources defined in the configuration.

This method orchestrates the handling of each type of resource,
such as secrets, by calling their respective handle() methods.

Args:
  region: The region of the compose project.
  repo: The repo of the compose project.
  tracker: The progress tracker to use for handling the resources.
  no_build: If true, skip building from source.

Returns:
  The ResourcesConfig instance after handling the resources.
zWProject name is missing in Compose file, but is required when using volumes or configs.z*Starting resource handling for project: %szHandling secret: z4Initializing GCS handler for volumes and/or configs.rl   )r   r   rq   r   r   rP   r   rM   r   
StartStagecompose_trackerStagedProgressTrackerStageSECRETSget_keyr   CompleteStager   r   r   ro   r6   VOLUMESCONFIGSr;   )	rA   r"   r  r   r   r;   secret_configrg   rI   s	            r5   handle_resources ResourcesConfig.handle_resources  sB   * <<'  nn




,,


 II:DLLI||

4
4
<
<
D
D
F "&!3!3!5
$		%dV,- "6 

4
4
<
<
D
D
F ||$,,";";t|||	iiFG-dllFCk		 	 DLL$=$=66>>FFH	
 	K066>>FFH	
 
66>>FFH	
 llF
)))6;;
7
--
, # 	66>>FFH	
 Kr7   c           	         U R                   U R                  R                  5        VVs0 s H  u  pXR                  5       _M     snnU R                  R                  5        VVs0 s H  u  pXR                  5       _M     snnU R
                  R                  5       U R                   Vs/ s H  oDR                  5       PM     snS.$ s  snnf s  snnf s  snf )z8Serializes the ResourcesConfig instance to a dictionary.)r   r   r   r   ro   )r   r   r   rT   r   r   ro   )rA   r;   buildsecretcs        r5   rT   ResourcesConfig.to_dict:  s     <<595G5G5M5M5O
5OkdD--/!5O
 8<||7I7I7K
7K|tD..""7K
 <<''))-6AIIK6
 


 7s   C	%C
+Cc                 J    [         R                  " U R                  5       5      $ )z9Serializes the ResourcesConfig instance to a JSON string.r   dumpsrT   rO   s    r5   to_jsonResourcesConfig.to_jsonH      ::dlln%%r7   )ro   r   r   r   r   )NNNNN)F)rX   rY   rZ   r[   r\   r   r   r]   r   r  r9   r   r   rb   rB   boolr   r   r^   r   r   rJ   r   StagedProgressTrackerr  rT   r  r_   r`   r7   r5   r   r     sO   G AE37(,#(,:d3(;(;#;<=: S,./0: %	:
 }: V%:' 'c ',  (9   4S> .?  8 EE E  55	E
 E ENtCH~ &s &r7   r   c                       \ rS rSrSr  SS\\\\4      S\\\\4      4S jjr\	S\SS 4S	 j5       r
\	S
\\\4   SS 4S j5       rS\4S jrS\\\4   4S jrSrg)TranslateResultiM  zBRepresents the translate command result from runcompose go binary.Nservicesmodelsc                 >    Ub  UO0 U l         Ub  X l        g 0 U l        g r?   r  r   )rA   r  r   s      r5   rB   TranslateResult.__init__P  s"    
 !) 4H"DM".&KBDKr7   r   r#   c                 P    [         R                  " U5      nU R                  U5      $ )z<Parses the JSON string to create a TranslateResult instance.r   )rH   r   rD   s      r5   r   TranslateResult.from_jsonX  s!     ::i D==r7   rD   c                 V    UR                  S0 5      nUR                  S0 5      nU " X#S9$ )z5Creates a TranslateResult instance from a dictionary.r  r   r"  r   )rH   rD   r  r   s       r5   rJ   TranslateResult.from_dict^  s/     xx
B'HXXh#F00r7   c                 J    [         R                  " U R                  5       5      $ )z9Serializes the TranslateResult instance to a JSON string.r  rO   s    r5   r  TranslateResult.to_jsone  r  r7   c                 4    U R                   U R                  S.$ )z8Serializes the TranslateResult instance to a dictionary.r"  r"  rO   s    r5   rT   TranslateResult.to_dicti  s     MM++ r7   )r   r  r   )rX   rY   rZ   r[   r\   r   r   r]   rB   r^   r   r   rJ   r  rT   r_   r`   r7   r5   r  r  M  s    J ,0)-7c3h(7 tCH~&7  (9  
 14S> 1.? 1 1&s &tCH~ r7   r  rI   c           	         U R                   (       a"  U R                  (       a  U R                  (       d  [        S5      e[        R
                  R                  U R                  5      (       d  [        SU R                   35      e[        R                  " 5       n[        R                  R                  R                  R                  SS9n[        R                  R!                  U R                   SU0SS9nUR#                  U5      c`  [$        R&                  " S	U R                    S
U S35         UR)                  USSSSS9  [$        R&                  " SU R                    S35        O$[$        R&                  " SU R                    S35         [/        5       nUR1                  U5      nSU 3nSn[2        R4                  " XgU5      (       dp  UR7                  S5      R8                  n	[2        R:                  " U	UUU5        UR=                  X65        [$        R&                  " SU SU SU R                    S35        O*[$        R&                  " U SU SU R                    S35          [$        R&                  " SU R                   SU R                   S35        [B        RD                  " U R                  5      n
[$        R&                  " SU R                    S35        URG                  X:SS9nUR                   U l$        [$        R&                  " SU RH                   S U R                    S35        g! [*         a,  n[$        R,                  " SU R                    SU 35        e SnAff = f! [*         a+  n[>        R@                  " SU R                    SU 35      eSnAff = f! [*         a,  n[$        R,                  " S!U R                    SU 35        e SnAff = f)"zDCreates a secret if it doesn't exist and adds a version from a file.z3Secret name, file path and mount name are required.zSecret file not found: Trequired
projectsIdzsecretmanager.projects.secretsparams
collectionNzCreating secret '' in project 'r   	automatic)r   	locationslabelstagszSecret 'z
' created.zFailed to create secret 'r   z' already exists.r   z"roles/secretmanager.secretAccessorr   zSet z for z on secret 'z already exists on secret 'z$Failed to set IAM policy on secret 'zReading secret content from 'z' for secret 'zAdding new version to secret ')data_crc32czAdded secret version 'z' to secret 'z!Failed to add version to secret ')%r;   r<   r=   
ValueErrorrt   ru   rv   secrets_apiSecretsr   VALUEScorer   Getr   REGISTRYParse	GetOrNoner   rM   Creater   errorr   r   r   BindingInPolicyr   r   r   r   r   rq   r   ReadBinaryFileContents
AddVersionr@   )rI   secrets_clientr   
secret_refr   r   r   memberroler   secret_dataversions               r5   rN   rN   q  so    
FKKv||
J
KK		$	$
.v{{m<
==&&(.""**...='!!''kkG$1 ( * j)1II!&++nWIRHI
   
ii(6;;-z23
 II%67824O((4F/0F/D##FD99**:6CCm$$



	 !!*5	ii$tfE/!2,v{{m2NO	iiF%( ){{m2
II
'} 5\\N"	 ..v{{;KII.v{{m2>? ''T ( G $LLFII
 !6!6 7 8[[M	_  	ii+FKK=A3?@6 
 



.v{{m3qcB 0 
 
II1&++c!EF	
sP   07L. B-M' ;)M' &CN .
M$8'MM$'
N1&NN
O)'OOc                      [         R                  R                  R                  R	                  SS9n [
        R                  R                  U SS9n[        R                  " U5      n[        UR                  5      $ )z5Retrieves the project number for the current project.Tr-  zcloudresourcemanager.projects)r2  )r   r<  r=  r   r>  r   r?  r@  r   r]   projectNumber)
project_idproject_refr   s      r5   r'   r'     sm       %%--1141@*""((< ) + [)'	W""	##r7   yaml_file_pathargsrelease_trackc                 ,   [         R                  R                  R                  R	                  SS9n[
        R                  " [        R                  [        R                  5      n [        R                  " U 5      nU(       d  [        R                  " SU  S35      e Sn [        R                   " XeR"                  5      n	[$        R"                  " X5      nU(       a  UR,                  (       d  [        R                  " S
5      e[.        R0                  R3                  SUR,                   SU SU S35        [4        R6                  R9                  UR:                  R,                  SU0SS9n
[<        R>                  " S[@        RB                  US9n[D        RF                  " U5       nURI                  U
5      n[J        RL                  " U5      /n[N        RP                  " X,X(       + 5      nU(       d	  U(       d  SnU(       d  SUR,                   S3OSUR,                   S3n[R        RT                  " U[V        RX                  " USL5      SSSUR,                   S3S9 nUR[                  U
UUUSUSUS9nSSS5        SSS5        W(       ae  UR0                  (       aS  UR0                  R\                  (       a7  [.        R0                  R3                  SUR0                  R\                   35        gggg! [        R                  [        R                  4 a!  n[        R                  " SU  SU 35      eSnAff = f! [        R&                   a   n[(        R*                  " USS	9   SnAGNSnAff = f! , (       d  f       GN= f! , (       d  f       GN= f)a  Deploys a Cloud Run application from a YAML file.

Args:
  yaml_file_path: The path to the Cloud Run service YAML file.
  region: The region to deploy the application to.
  args: The arguments passed to the command.
  release_track: The release track of the command.
Tr-  zCould not parse YAML file 'r   z#Failed to read or parse YAML file 'r   NzPlease make sure that the YAML file matches the Knative service definition spec in https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/#Service.)	help_textz)Service name is missing in the YAML file.zDeploying service 'r3  z' in region 'namespacesIdzrun.namespaces.servicesr0  )platformregion_labelz'...zUpdating service 'zDeployment failedFz	Service 'z' has been deployed.)failure_messagesuppress_outputsuccess_message)asynallow_unauthenticatedfor_replaceprefetchzService URL: )/r   r<  r=  r   r>  r   GetMessagesModuler   SERVERLESS_API_NAMESERVERLESS_API_VERSIONr   	load_pathr   rq   r   messages_utilDictToMessageWithErrorCheckServicer	   ScalarTypeMismatchErrorserverless_exceptionsMaybeRaiseCustomFieldMismatchr;   r   statusPrintr   r?  r@  metadatar   GetConnectionContextr   PLATFORM_MANAGEDr   Connect
GetServicer   ReplaceServiceChange	run_flagsGetAllowUnauthenticatedr   r  r   ServiceStagesReleaseServiceurl)rQ  r"   rR  rS  r   run_messagesservice_dictr   new_serviceraw_serviceservice_refconn_contextclientexisting_servicechangesr]  headerr   deployed_services                      r5   deploy_applicationr    sS    ""**...='''((++,
>>.1L:>:J"MNN  +;;**K //+<K 
K,,


F
GG**[--..>wi HXS"
 ""((g&* ) +
 $88
)),
 $$\2f((522;?@G%==k#7
 $9"   {//06";#3#3"4E:  
	/	/2$>?+#K$4$4#55IJ
 
..



 5# / 	
# 3F 

!
!

!
!
%
%JJ}%5%<%<%@%@$ABC & " W ++tzz	" 



-n-=SD  
	.	. 	77	 	\
 
# 32sU   &7K3 !6L; 'B8NM26N3$L8L33L8;M/M**M/2
N	<N
Nc                       [        5       n U  S3$ )zFRetrieves the default compute service account for the current project.z&-compute@developer.gserviceaccount.com)r'   )r1   s    r5   r   r   >  s    &(.A	BBr7   )Dr\   r-   r   rt   r)   typingr   r   r   r   +googlecloudsdk.api_lib.cloudresourcemanagerr   googlecloudsdk.api_lib.runr   r	   googlecloudsdk.api_lib.secretsr
   r:  googlecloudsdk.api_lib.storager   r   googlecloudsdk.api_lib.utilr   r   rd  googlecloudsdk.callioper   googlecloudsdk.command_lib.iamr   googlecloudsdk.command_lib.runr   r   r   rh  r   rr  r   r   r   &googlecloudsdk.command_lib.run.composer   r   r  googlecloudsdk.corer   r   r   r   googlecloudsdk.core.consoler   googlecloudsdk.core.utilr   r,   r]   r6   r9   rb   r   r   rr   r   r   r  rN   r'   ReleaseTrackr  r   r`   r7   r5   <module>r     sc     	 	 , , D 5 . = 6 7 , A ( 3 9 = N = 4 @ 1 : M * # * ) $ 8 *  "!C "! "! "!J* *Z7 7t5 5p &W Wt6 6r^& ^&B! !HT
T
	T
n$S $hDhDhD hD $$	hD
 
hDVCc Cr7   