
    Q              	       `   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKr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\R8                  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#\R8                  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r0 " S/ S0\Rb                  5      r2SNS1 jr3S2 r4 " S3 S4\5      r5S5 r6 " S6 S7\5      r7S8 r8S9 r9SNS: jr:S; r;S< r<SNS= jr=S> r>SNS? jr?SNS@ jr@SNSA jrASNSB jrBSNSC jrCSNSD jrDSE rESF rFSG rG\R                  " SH\9" 5       SISJS&SJSK9rI\R                  " SL\F" 5       SMSJS&SJSK9rJg)Oz-Shared resource flags for Cloud Run commands.    )absolute_import)division)print_function)unicode_literalsN)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._Call2   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   _GenerateServiceNamerF   8   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.
)r:   r;   splitextabspathrF   )sourcer;   exts      r   !_GenerateServiceNameFromLocalPathrL   M   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	$ )ResourcePromptFallthroughd   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   rN   r   formatresource_type_lower)r   rR   r   s     r   r   "ResourcePromptFallthrough.__init__g   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)rR   
capitalize_DefaultNameFromArgsr   PromptWithDefault)r   r$   rU   default_names       r   r%   !ResourcePromptFallthrough._Prompto   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)NrD   rJ   r8   )getattrrF   rD   rL   rJ   r#   s     r   rX   .ResourcePromptFallthrough._DefaultNameFromArgst   sE    {GT**!+"3"344	h	-	-.{/A/ABBr   )rR   )
r+   r,   r-   r.   r/   r   r%   rX   r2   r3   r4   s   @r   rN   rN   d   s    M3O
 r   rN   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )RegionPromptFallthrough|   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)rU   cancel_optionallow_freeformzHTo make this the default region, run `gcloud config set run/region {}`.
)
r   GetServerlessClientInstanceListRegionsr   PromptChoicer   statusPrintrQ   region)r   r$   clientall_regionsidxrm   s         r   r%   RegionPromptFallthrough._Prompt   sv    779F ,,V4K

!
!,	C FJJ	//5vf~ !Mr   r"   	r+   r,   r-   r.   r/   r   r%   r2   r3   r4   s   @r   r`   r`   |   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   rt   r   rc   s    r   r   !ServicePromptFallthrough.__init__   s    	
"D29=r   r"   r+   r,   r-   r.   r   r2   r3   r4   s   @r   rt   rt      s    > >r   rt   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )WorkerPoolPromptFallthrough   c                 ,   > [         [        U ]  S5        g )N
workerpool)r   r{   r   rc   s    r   r   $WorkerPoolPromptFallthrough.__init__   s    	
%t5lCr   r"   ry   r4   s   @r   r{   r{      s    D Dr   r{   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   rc   s    r   r   JobPromptFallthrough.__init__   s    	
.u5r   r"   ry   r4   s   @r   r   r      s    6 6r   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   rc   s    r   r   #ExecutionPromptFallthrough.__init__   s    	
$d4[Ar   r"   ry   r4   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   rc   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 )NrV   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_KUBERNETESr]   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)   r2   r3   r4   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.rw   zService for the {resource}.r   )rt   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   )r{   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
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$ ) TaskExecutionAndIndexFallthroughi7  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   rQ   arg_name)r   r   r   r   s      r   r   )TaskExecutionAndIndexFallthrough.__init__:  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{}-{})r]   concepts_utilNamespaceFormatr   rQ   )r   r$   prefixr   s       r   r)   &TaskExecutionAndIndexFallthrough._CallD  sA    ]224==A4F K$/E>>&((r   )r   Fr   r4   s   @r   r   r   7  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   L  s1    4V<=LL		2	2gL
 r   c                      [         R                  " SS[        R                  " S5      [        R                  " [
        R                  R                  R                  5      [        5       /S9$ )Nrm   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   rm   r`   r"   r   r   LocationAttributeConfigr   V  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	$ )ClusterPromptFallthroughie  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   rc   s    r   r   !ClusterPromptFallthrough.__init__h  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 [{}]r8   zJNo compatible clusters found{}. Ensure your cluster has Cloud Run enabled.zGKE cluster{}:rU   rf   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   r]   r   r   rQ   r   MultiTenantClustersForProjectr   ConfigurationError_GetClusterDescriptionr   rj   zoneName	projectIdRelativeNamer   rk   rl   SelfLink)r   r$   r   r   cluster_location_msgcluster_refsccluster_refs_descsrp   cluster_reflocation_help_textcluster_names               r   r%    ClusterPromptFallthrough._Promptm  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   rQ   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   r2   r3   r4   s   @r   r   r   e  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   rc   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 {}`.
)r]   r   r   r   r   r   r   r   r   r   ListClustersr   r   r   rQ   r   r   rj   r   rk   rl   )r   r$   r   r   clusterscluster_locationsrp   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"   rr   r4   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.servicesrw   )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  '  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  1  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  <  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%  E  s/    			<<v.
 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   GetExecutionResourceSpecr)  O  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   GetTaskResourceSpecr-  Y  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   GetV1WorkerPoolResourceSpecr1  c  s/    			"<<-f5 
 r   c           	      r    [         R                  " S[         R                  [        5       [	        U 5      SSS9$ )Nz"run.projects.locations.workerPoolsr/  v2)
projectsIdlocationsIdworkerPoolsIdr
  r$  )r   r  r   r   r   r  s    r   GetV2WorkerPoolResourceSpecr7  m  s5    			*::)+-f5 
 r   c           
          [         R                  " S[         R                  [        5       [	        U 5      [        5       SSS9$ )Nz,run.projects.locations.workerPools.revisionsWorkerPoolRevisionr3  )r4  r5  r6  r  r
  r$  )r   r  r   r   r   r   r  s    r   #GetV2WorkerPoolRevisionResourceSpecr:  x  s;    			4::)+-f5)+(
 r   c                  >    [         R                  " SS[        5       S9$ )Nzrun.projectsr   )r
  r4  )r   r  r   r"   r   r   GetProjectResourceSpecr<    s!    			')
 r   c                  ^    [         R                  " S[         R                  [        5       SSS9$ )Nzrun.projects.locationsRegionr3  )r4  r5  r
  r$  )r   r  r   r   r"   r   r   GetRegionResourceSpecr?    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   GetNamespaceResourceSpecrB    s\    
  -/! 
 
	-	-   -/! s     2AAz	--clusterz(Kubernetes Engine cluster to connect to.T)hiddenr   prefixesr   zCloud region to use.r   )Kr/   
__future__r   r   r   r   r0   r   r:   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   rF   rL   rN   r`   rt   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-  r1  r7  r:  r<  r?  rB  ResourcePresentationSpecCLUSTER_PRESENTATIONREGION_PRESENTATIONr"   r   r   <module>rP     s   4 &  % ' 
  	 	 5 5 1 B 5 4 G # * ) 2%(( % D*$. 1 0/ 6>8 >D"; D64 6B!: B")) "J "

	)t':': )*X0 Xv,'8 ,^	& *BB.  )AA r   