
    T              	       Z   S 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\	R.                  5      rS rS r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r! " S  S!\	R.                  5      r"S" r#S# r$SNS% jr%SNS& jr&S' r'S( r(S) r)S* r*SNS+ jr+SNS, jr,SNS- jr- " S. S/\	R\                  5      r/SNS0 jr0S1 r1 " S2 S3\5      r2S4 r3 " S5 S6\5      r4S7 r5S8 r6SNS9 jr7S: r8S; r9SNS< jr:S= r;SNS> jr<SNS? jr=SNS@ jr>SNSA jr?SNSB jr@SNSC jrASNSD jrBSE rCSF rDSG rE\R                  " SH\6" 5       SISJS$SJSK9rG\R                  " SL\D" 5       SMSJS$SJSK9rHg)Oz-Shared resource flags for Cloud Run commands.    N)global_methods)concepts)deps)util)
exceptions)	platforms)presentation_specs)log)
properties)	resources)
console_ioc                   V   ^  \ rS rSrSrU 4S jr\R                  S 5       rS r	Sr
U =r$ )PromptFallthrough$   z3Fall through to reading from an interactive prompt.c                 *   > [         [        U ]  S US9  g )Nfunctionhint)superr   __init__)selfr   	__class__s     3lib/googlecloudsdk/command_lib/run/resource_args.pyr   PromptFallthrough.__init__'   s    	
T+T+E    c                     g N r   parsed_argss     r   _PromptPromptFallthrough._Prompt*   s    r   c                 Z    [         R                  " 5       (       d  g U R                  U5      $ r   )r   	CanPromptr!   r   s     r   _CallPromptFallthrough._Call.   s#    !!<<$$r   r   )__name__
__module____qualname____firstlineno____doc__r   abcabstractmethodr!   r%   __static_attributes____classcell__r   s   @r   r   r   $   s0    ;F 	 	% %r   r   c                 4   [         R                  R                  U R                  [         R                  5      5      nUR                  S5      S   nUR                  S5      S   n[        R                  " SSU5      R                  S5      R                  5       $ )a  Produce a valid default service name from a container image path.

Converts a file path or image path into a reasonable default service name by
stripping file path delimeters, image tags, and image hashes.
For example, the image name 'gcr.io/myproject/myimage:latest' would produce
the service name 'myimage'.

Args:
  image: str, The container path.

Returns:
  A valid Cloud Run service name.
:r   @z[^a-zA-Z0-9-] -)
ospathbasenamerstripsepsplitresubstriplower)image	base_names     r   _GenerateServiceNamerB   4   ss     ggu||BFF34)ooc"1%)ooc"1%)	 "i	0	6	6s	;	A	A	CCr   c                     [         R                  R                  [         R                  R                  U 5      5      u  pU(       a*  [         R                  R                  U5      u  pU(       a  M*  [	        U5      $ )a  Produce a valid default service name from a local file or directory path.

Converts a file or directory path into a reasonable default service name by
resolving relative paths to absolute paths, removing any extensions, and then
removing any invalid characters.

For example, the paths /tmp/foo/bar/.. and /tmp/foo.tar.gz would both produce
the service name 'foo'. A source path of "." will be expanded to the current
directory name."

Args:
  source: str, The file or directory path.

Returns:
  A valid Cloud Run service name.
)r6   r7   splitextabspathrB   )sourcer7   exts      r   !_GenerateServiceNameFromLocalPathrH   I   sR    " ggrwwv67)$  &ID 		d	##r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )ResourcePromptFallthrough`   zEFall through to reading the resource name from an interactive prompt.c                 V   > [         [        U ]  SR                  U5      5        Xl        g )Nz.specify the {} name from an interactive prompt)r   rJ   r   formatresource_type_lower)r   rN   r   s     r   r   "ResourcePromptFallthrough.__init__c   s,    	
#T38??	

  3r   c                     U R                   R                  5       S-   nU R                  U5      n[        R                  " X#S9$ )Nz name)messagedefault)rN   
capitalize_DefaultNameFromArgsr   PromptWithDefault)r   r    rQ   default_names       r   r!   !ResourcePromptFallthrough._Promptk   s<    &&113g=G,,[9L''NNr   c                     [        USS 5      (       a  [        UR                  5      $ [        USS 5      (       a  [        UR                  5      $ g)Nr@   rF   r4   )getattrrB   r@   rH   rF   r   s     r   rT   .ResourcePromptFallthrough._DefaultNameFromArgsp   sE    {GT**!+"3"344	h	-	-.{/A/ABBr   )rN   )
r'   r(   r)   r*   r+   r   r!   rT   r.   r/   r0   s   @r   rJ   rJ   `   s    M3O
 r   rJ   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )RegionPromptFallthroughx   z>Fall through to reading the region from an interactive prompt.c                 ,   > [         [        U ]  S5        g )Nz-specify the region from an interactive prompt)r   r\   r   r   r   s    r   r    RegionPromptFallthrough.__init__{   s    	
!417r   c                    [         R                  " 5       n[         R                  " U5      n[        R                  " USSSS9nX4   n[
        R                  R                  SR                  U5      5        U(       a  XQl	        U$ )NzPlease specify a region:
T)rQ   cancel_optionallow_freeformzHTo make this the default region, run `gcloud config set run/region {}`.
)
r   GetServerlessClientInstanceListRegionsr   PromptChoicer
   statusPrintrM   region)r   r    clientall_regionsidxri   s         r   r!   RegionPromptFallthrough._Prompt   sv    779F ,,V4K

!
!,	C FJJ	//5vf~ !Mr   r   	r'   r(   r)   r*   r+   r   r!   r.   r/   r0   s   @r   r\   r\   x   s    F
 r   r\   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )ServicePromptFallthrough   c                 ,   > [         [        U ]  S5        g )Nservice)r   rp   r   r_   s    r   r   !ServicePromptFallthrough.__init__   s    	
"D29=r   r   r'   r(   r)   r*   r   r.   r/   r0   s   @r   rp   rp      s    > >r   rp   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )WorkerPoolPromptFallthrough   c                 ,   > [         [        U ]  S5        g )N
workerpool)r   rw   r   r_   s    r   r   $WorkerPoolPromptFallthrough.__init__   s    	
%t5lCr   r   ru   r0   s   @r   rw   rw      s    D Dr   rw   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )JobPromptFallthrough   c                 ,   > [         [        U ]  S5        g )Njob)r   r}   r   r_   s    r   r   JobPromptFallthrough.__init__   s    	
.u5r   r   ru   r0   s   @r   r}   r}      s    6 6r   r}   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )InstancePromptFallthrough   c                 ,   > [         [        U ]  S5        g )Ninstance)r   r   r   r_   s    r   r   "InstancePromptFallthrough.__init__   s    	
#T3J?r   r   ru   r0   s   @r   r   r      s    @ @r   r   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )ExecutionPromptFallthrough   c                 ,   > [         [        U ]  S5        g )N	execution)r   r   r   r_   s    r   r   #ExecutionPromptFallthrough.__init__   s    	
$d4[Ar   r   ru   r0   s   @r   r   r      s    B Br   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )DefaultFallthrough   zlUse the namespace "default".

For Knative only.

For Cloud Run, raises an ArgumentError if project not set.
c                 *   > [         [        U ]  S SS9  g )Nz]For Cloud Run on Kubernetes Engine, defaults to "default". Otherwise, defaults to project ID.r   )r   r   r   r_   s    r   r   DefaultFallthrough.__init__   s     	
d,1 - r   c                 `   [         R                  " 5       [         R                  :X  d'  [         R                  " 5       [         R                  :X  a  g[	        USS 5      (       dM  [
        R                  R                  R                  R                  5       (       d  [        R                  " S5      eg )NrR   projectzThe [project] resource is not properly specified. Please specify the argument [--project] on the command line or set the property [core/project].)r   GetPlatformPLATFORM_GKEPLATFORM_KUBERNETESrY   r   VALUEScorer   Getr   ArgumentErrorr   s     r   r%   DefaultFallthrough._Call   s    9#9#99  "i&C&CCY--!!))--// $$- 
 r   r   	r'   r(   r)   r*   r+   r   r%   r.   r/   r0   s   @r   r   r      s     r   r   c            
      F   [         R                  " SS[        R                  " [        R
                  R                  R                  5      [        5       [        R                  " S5      [        R                  " [        R
                  R                  R                  5      /S9$ )N	namespacezJSpecific to Cloud Run for Anthos: Kubernetes namespace for the {resource}.r   name	help_textfallthroughs)r    ResourceParameterAttributeConfigr   PropertyFallthroughr   r   runr   r   ArgFallthroughr   r   r   r   r   NamespaceAttributeConfigr      sx    		2	25 
"
":#4#4#8#8#B#B
C




i
(

"
":#4#4#9#9#A#A
B	
 r   c                      [         R                  " [        R                  5      n [	        5       /[        R                  R
                  -   nXl        U $ r   )copydeepcopyr    DEFAULT_PROJECT_ATTRIBUTE_CONFIGr   r   )project_attribute_configr   s     r   ProjectAttributeConfigr      sK    !]]// //<<=, +7'	!!r   Fc                 X    U (       a  [        5       /nO/ n[        R                  " SSUS9$ );Attribute config with fallthrough prompt only if requested.rs   zService for the {resource}.r   )rp   r   r   promptr   s     r   ServiceAttributeConfigr      s1    ,./LL		2	2-
 r   c                 X    U (       a  [        5       /nO/ n[        R                  " SSUS9$ )r   zworker-poolzWorkerPool for the {resource}.r   )rw   r   r   r   s     r   WorkerPoolAttributeConfigr      s1    /12LL		2	20
 r   c                  ,    [         R                  " SSS9$ )Nconfigurationz!Configuration for the {resource}.r   r   r   r   r   r   r   ConfigurationAttributeConfigr     s    		2	2&I
 r   c                  ,    [         R                  " SSS9$ )NroutezRoute for the {resource}.r   r   r   r   r   RouteAttributeConfigr     s    		2	29
 r   c                  ,    [         R                  " SSS9$ )NrevisionzRevision for the {resource}.r   r   r   r   r   RevisionAttributeConfigr     s    		2	2!?
 r   c                  ,    [         R                  " SSS9$ )Ndomainz#Name of the domain to be mapped to.r   r   r   r   r   DomainAttributeConfigr     s    		2	2D
 r   c                 X    U (       a  [        5       /nO/ n[        R                  " SSUS9$ )NjobszJob for the {resource}.r   )r}   r   r   r   s     r   JobAttributeConfigr   #  s1    (*+LL		2	2)
 r   c                 X    U (       a  [        5       /nO/ n[        R                  " SSUS9$ )N	instanceszInstance for the {resource}.r   )r   r   r   r   s     r   InstanceAttributeConfigr   /  s1    -/0LL		2	2.
 r   c                 X    U (       a  [        5       /nO/ n[        R                  " SSUS9$ )N
executionsz
Execution.r   )r   r   r   r   s     r   ExecutionAttributeConfigr   ;  s/    .01LL		2	2<l
 r   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ ) TaskExecutionAndIndexFallthroughiE  zAAllow the user to provide --execution and --index to find a task.c                 V   > [         [        U ]  SR                  U5      SUS9  Xl        g )Nz;provide the arguments `{}`  and `index` on the command lineT)activeplural)r   r   r   rM   arg_name)r   r   r   r   s      r   r   )TaskExecutionAndIndexFallthrough.__init__H  s8    	
*D:ELL	
  ;  Mr   c                     [        U[        R                  " U R                  5      S 5      n[        USS 5      nSR	                  X#5      $ )Nindexz{}-{})rY   concepts_utilNamespaceFormatr   rM   )r   r    prefixr   s       r   r%   &TaskExecutionAndIndexFallthrough._CallR  sA    ]224==A4F K$/E>>&((r   )r   Fr   r0   s   @r   r   r   E  s    I) )r   r   c                 Z    U (       a  [        S5      /nO/ n[        R                  " SSUS9$ )NtasktaskszTask.r   )r   r   r   r   s     r   TaskAttributeConfigr   Z  s1    4V<=LL		2	2gL
 r   c                      [         R                  " SS[        R                  " S5      [        R                  " [
        R                  R                  R                  5      [        5       /S9$ )Nri   zsThe Cloud region for the {resource}. Overrides the default `run/region` property value for this command invocation.--regionr   )
r   r   r   r   r   r   r   r   ri   r\   r   r   r   LocationAttributeConfigr   d  sY    		2	2E 

j
)

"
":#4#4#8#8#?#?
@
!
#
 r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )ClusterPromptFallthroughis  DFall through to reading the cluster name from an interactive prompt.c                 ,   > [         [        U ]  S5        g )Nz5specify the cluster from a list of available clusters)r   r   r   r_   s    r   r   !ClusterPromptFallthrough.__init__v  s    	
"D2?r   c                    [         R                  " 5       [         R                  :w  a  g[        R                  R
                  R                  R                  SS9n[        USS5      =(       d2    [        R                  R                  R                  R                  5       nU(       a  SR                  U5      OSn[        R                  " X#5      nU(       d%  [        R                  " SR                  U5      5      eU Vs/ s H  nU R!                  XcU5      PM     nn["        R$                  " USR                  U5      SS	9nXX   n	U(       a  Sn
OS
R                  U	R&                  5      n
U	R)                  5       nU	R*                  U:w  a  U	R-                  5       nSn
[.        R0                  R3                  SR                  XS95        U	R5                  5       $ s  snf )zFallthrough to reading the cluster name from an interactive prompt.

Only prompt for cluster name if the user-specified platform is GKE.

Args:
  parsed_args: Namespace, the args namespace.

Returns:
  A cluster name string
NT)requiredcluster_locationz in [{}]r4   zJNo compatible clusters found{}. Ensure your cluster has Cloud Run enabled.zGKE cluster{}:rQ   rb   z- && gcloud config set run/cluster_location {}z[To make this the default cluster, run `gcloud config set run/cluster {cluster}{location}`.
)clusterlocation)r   r   r   r   r   r   r   r   rY   r   r   rM   r   MultiTenantClustersForProjectr   ConfigurationError_GetClusterDescriptionr   rf   zoneName	projectIdRelativeNamer
   rg   rh   SelfLink)r   r    r   r   cluster_location_msgcluster_refsccluster_refs_descsrl   cluster_reflocation_help_textcluster_names               r   r!    ClusterPromptFallthrough._Prompt{  s    )"8"88$$,,00$0?G/6 	8  11557 
 0@
*+R  "??L ))77=v"8  A 	##AA  
 
!
! ''(<=C #K :
@
@  ##%L' --/lJJ	    
 !!Gs    Gc                     UR                  5       nU(       d  SR                  XAR                  5      nX1R                  :w  a  SR                  XAR                  5      nU$ )z"Description of cluster for prompt.z{} in {})r   rM   r   r   )r   r   r   r   responses        r   r   /ClusterPromptFallthrough._GetClusterDescription  sM     ||~H""8\\:h###""8->->?hOr   r   )
r'   r(   r)   r*   r+   r   r!   r   r.   r/   r0   s   @r   r   r   s  s    L
E"N	 	r   r   c                      [         R                  " SS[        R                  " [        R
                  R                  R                  5      [        5       /S9$ )Nr   z\Name of the Kubernetes Engine cluster to use. Alternatively, set the property [run/cluster].r   )	r   r   r   r   r   r   r   r   r   r   r   r   ClusterAttributeConfigr    sJ    		2	2; 
"
":#4#4#8#8#@#@
A
"
$

 
r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ ) ClusterLocationPromptFallthroughi  r   c                 ,   > [         [        U ]  S5        g )Nz;specify the cluster location from a list of available zones)r   r  r   r_   s    r   r   )ClusterLocationPromptFallthrough.__init__  s    	
*D:Er   c                    [        USS5      =(       d2    [        R                  R                  R                  R                  5       n[        R                  " 5       [        R                  :X  a  U(       a  [        R                  " 5        Vs/ s H  o3R                  U:X  d  M  UPM     nnU(       d%  [        R                  " SR                  U5      5      eU Vs/ s H  o3R                  PM     nn[         R"                  " USR                  U5      SS9nXV   n[$        R&                  R)                  SR                  U5      5        U$ ggs  snf s  snf )a  Fallthrough to reading the cluster location from an interactive prompt.

Only prompt for cluster location if the user-specified platform is GKE
and if cluster name is already defined.

Args:
  parsed_args: Namespace, the args namespace.

Returns:
  A cluster location string
r   NzYNo cluster locations found for cluster [{}]. Ensure your clusters have Cloud Run enabled.zGKE cluster location for [{}]:Tr   z\To make this the default cluster location, run `gcloud config set run/cluster_location {}`.
)rY   r   r   r   r   r   r   r   r   r   ListClustersr   r   r   rM   r   r   rf   r
   rg   rh   )r   r    r   r   clusterscluster_locationsrl   r   s           r   r!   (ClusterLocationPromptFallthrough._Prompt  s+    	Y- 	/  ((,,.  )"8"88\#0022ff6L!2   ++;;A6,;O
 	
 ,448a6684##
299,Gc
 #'h	jj;;A6(;K o) >J8 5s   E#EEr   rn   r0   s   @r   r  r    s    L
$ $r   r  c                      [         R                  " SS[        R                  " [        R
                  R                  R                  5      [        5       /S9$ )Nr   z`Zone in which the {resource} is located. Alternatively, set the property [run/cluster_location].r   )	r   r   r   r   r   r   r   r   r  r   r   r   ClusterLocationAttributeConfigr    sK    		2	2D 
"
":#4#4#8#8#I#I
J
*
,

 
r   c                  n    [         R                  " S[         R                  [        5       [	        5       SS9$ )Nz!container.projects.zones.clustersr   )r   r   	clusterIdresource_name)r   ResourceSpecr   r  r  r   r   r   GetClusterResourceSpecr    s0    			)99)+&(
 r   c                 R    [         R                  " S[        5       [        U 5      SS9$ )Nzrun.namespaces.servicesrs   )namespacesId
servicesIdr  )r   r  r   r   r   s    r   GetServiceResourceSpecr  #  s)    			+-'/	
 r   c                  P    [         R                  " S[        5       [        5       SS9$ )Nzrun.namespaces.configurationsr   )r  configurationsIdr  )r   r  r   r   r   r   r   GetConfigurationResourceSpecr  ,  s'    			%+-35#	
 r   c                  P    [         R                  " S[        5       [        5       SS9$ )Nzrun.namespaces.routesr   )r  routesIdr  )r   r  r   r   r   r   r   GetRouteResourceSpecr  5  s'    			+-#%	
 r   c                 ~    [         R                  " SU (       d
  [        5       O[         R                  [	        5       SS9$ )Nzrun.namespaces.revisionsr   )r  revisionsIdr  )r   r  r   r   r   )is_worker_pool_revisions    r   GetRevisionResourceSpecr   ?  s5    			 $ ,-44)+
 r   c                  P    [         R                  " S[        5       [        5       SS9$ )Nzrun.namespaces.domainmappingsDomainMapping)r  domainmappingsIdr  )r   r  r   r   r   r   r   GetDomainMappingResourceSpecr$  J  s'    			%+-,.#	
 r   c                 \    [         R                  " S[         R                  [        U S9SSS9$ )Nzrun.namespaces.jobsr  Jobv1)r  jobsIdr  api_version)r   r  r   r   r  s    r   GetJobResourceSpecr*  S  s/    			<<v.
 r   c                 \    [         R                  " S[         R                  [        U S9SSS9$ )Nzrun.namespaces.instancesr  Instancer'  )r  instancesIdr  r)  )r   r  r   r   r  s    r   GetInstanceResourceSpecr.  ]  s/    			 <<)8
 r   c                 \    [         R                  " S[         R                  [        U S9SSS9$ )Nzrun.namespaces.executionsr  	Executionr'  )r  executionsIdr  r)  )r   r  r   r   r  s    r   GetExecutionResourceSpecr2  g  s/    			!<<+6:
 r   c                 \    [         R                  " S[         R                  [        U S9SSS9$ )Nzrun.namespaces.tasksr  Taskr'  )r  tasksIdr  r)  )r   r  r   r   r  s    r   GetTaskResourceSpecr6  q  s/    			<<!0
 r   c                 `    [         R                  " S[         R                  [        U 5      SSS9$ )Nzrun.namespaces.workerpools
WorkerPoolr'  )r  workerpoolsIdr  r)  )r   r  r   r   r  s    r   GetV1WorkerPoolResourceSpecr:  {  s/    			"<<-f5 
 r   c           	      r    [         R                  " S[         R                  [        5       [	        U 5      SSS9$ )Nz"run.projects.locations.workerPoolsr8  v2)
projectsIdlocationsIdworkerPoolsIdr  r)  )r   r  r   r   r   r  s    r   GetV2WorkerPoolResourceSpecr@    s5    			*::)+-f5 
 r   c           
          [         R                  " S[         R                  [        5       [	        U 5      [        5       SSS9$ )Nz,run.projects.locations.workerPools.revisionsWorkerPoolRevisionr<  )r=  r>  r?  r  r  r)  )r   r  r   r   r   r   r  s    r   #GetV2WorkerPoolRevisionResourceSpecrC    s;    			4::)+-f5)+(
 r   c                  >    [         R                  " SS[        5       S9$ )Nzrun.projectsr   )r  r=  )r   r  r   r   r   r   GetProjectResourceSpecrE    s!    			')
 r   c                  ^    [         R                  " S[         R                  [        5       SSS9$ )Nzrun.projects.locationsRegionr<  )r=  r>  r  r)  )r   r  r   r   r   r   r   GetRegionResourceSpecrH    s-    			::)+
 r   c                       [         R                  " S[        5       SS9$ ! [        R                   a!    [         R                  " S[        5       SS9s $ f = f)z*Returns a resource spec for the namespace.zrun.namespacesr   )r  r  zrun.api.v1.namespaces)r   r  r   r   InvalidCollectionExceptionr   r   r   GetNamespaceResourceSpecrK    s\    
  -/! 
 
	-	-   -/! s     2AAz	--clusterz(Kubernetes Engine cluster to connect to.T)hiddenr   prefixesr   zCloud region to use.r   )Ir+   r,   r   r6   r<   googlecloudsdk.api_lib.runr    googlecloudsdk.calliope.conceptsr   r   r   r   googlecloudsdk.command_lib.runr   r   (googlecloudsdk.command_lib.util.conceptsr	   googlecloudsdk.corer
   r   r   googlecloudsdk.core.consoler   Fallthroughr   rB   rH   rJ   r\   rp   rw   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r   r$  r*  r.  r2  r6  r:  r@  rC  rE  rH  rK  ResourcePresentationSpecCLUSTER_PRESENTATIONREGION_PRESENTATIONr   r   r   <module>rX     s   4   	 	 5 5 1 B 5 4 G # * ) 2%(( % D*$. 1 0/ 6>8 >D"; D64 6@ 9 @B!: B")) "J "

		)t':': )*X0 Xv,'8 ,^	& *BB.  )AA r   