
    v                    N   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Jr  SSKrSSKJ	r	J
r
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SKJ r   SSKJ!r!  SSKJ"r#  S r$\RJ                  " SS9 " S S\RL                  5      5       r'\RJ                  " SS9 " S S\RP                  5      5       r)\RJ                  " SS9 " S S\RP                  5      5       r*\RJ                  " SS9 " S S \RL                  5      5       r+\RJ                  " SS9 " S! S"\RL                  5      5       r,\RJ                  " SS9 " S# S$\RP                  5      5       r-\RJ                  " SS9 " S% S&\RP                  5      5       r.\RJ                  " SS9 " S' S(\RL                  5      5       r/\RJ                  " S)SS*9 " S+ S,\'5      5       r0\RJ                  " SS9 " S- S.\'5      5       r1\RJ                  " SS9 " S/ S0\'5      5       r2S1 r3        SkS2 jr4        SlS3 jr5\RJ                  " SS9 " S4 S5\RL                  5      5       r6\RJ                  " SS9 " S6 S7\RL                  5      5       r7\RJ                  " SS9 " S8 S9\RL                  5      5       r8\RJ                  " SS9 " S: S;\RL                  5      5       r9S<r:\RJ                  " SS9 " S= S>\RL                  5      5       r;\RJ                  " SS9 " S? S@\RL                  5      5       r<\RJ                  " SS9 " SA SB\RL                  5      5       r=\RJ                  " SS9 " SC SD\RL                  5      5       r>\RJ                  " S)SS*9 " SE SF\'5      5       r?\RJ                  " S)SS*9 " SG SH\'5      5       r@\RJ                  " SS9 " SI SJ\'5      5       rA\RJ                  " SS9 " SK SL\'5      5       rB\RJ                  " SS9 " SM SN\RP                  5      5       rC\RJ                  " SS9 " SO SP\RP                  5      5       rD\RJ                  " SS9 " SQ SR\R                  5      5       rF\RJ                  " SS9 " SS ST\RL                  5      5       rG\RJ                  " SS9 " SU SV\RL                  5      5       rH\RJ                  " SS9 " SW SX\RL                  5      5       rI\RJ                  " SS9 " SY SZ\RL                  5      5       rJ\RJ                  " SS9 " S[ S\\'5      5       rK\" S]\L\LS^.5      rM\RJ                  " SS9 " S_ S`\'5      5       rN\RJ                  " SS9 " Sa Sb\RL                  5      5       rO\RJ                  " SS9 " Sc Sd\RL                  5      5       rP\RJ                  " SS9 " Se Sf\RP                  5      5       rQ\RJ                  " SS9 " Sg Sh\RP                  5      5       rR\RJ                  " SS9 " Si Sj\RP                  5      5       rSg)mzBClass for representing various changes to a Cloud Run V2 resource.    )absolute_import)annotations)division)print_function)unicode_literalsN)IterableMappingSequence)	TypedDict)duration_pb2)launch_stage_pb2)base)config_changes)
exceptions)flags)resource_name_conversion)volumes)instance_split)k8s_min)vendor_settings)worker_poolc                :    U H  nUR                  U 5      n M     U $ )zApply ConfigChangers to resource.

It's undefined whether the input resource is modified.

Args:
  resource: The Cloud Run V2 resource to modify.
  changes: List of ConfigChangers.

Returns:
  Changed resource.
)Adjust)resourcechangesconfig_changes      7lib/googlecloudsdk/command_lib/run/v2/config_changes.pyWithChangesr   +   s#     m##H-H 	/    T)frozenc                  n    \ rS rSr% SrSrS\S'   SrS\S'   \R                    SS	 j5       r
S
 rS rSrg)ContainerConfigChanger<   zAn abstract class representing worker pool container configuration changes.

Attributes:
  container_name: Name of the container to modify. If None the first container
    is modified.
N
str | Nonecontainer_nameFboolnon_ingress_typec                    g)zMutate the given container.

This method is called by this class's Adjust method and should apply the
desired changes directly to container.

Args:
  container: the container to adjust.
N self	containers     r   AdjustContainer&ContainerConfigChanger.AdjustContainerH   s    r   c                J    U R                  U5      nU R                  U5        U$ )a6  Returns a modified Cloud Run V2 resource.

Adjusts Cloud Run V2 resource by applying changes to the container specified
by self.container_name if present or the first container otherwise. Calls
AdjustContainer to apply changes to the selected container.

Args:
  resource: The Cloud RUn V2 resource to modify.
)_FindContainerr-   )r+   r   r,   s      r   r   ContainerConfigChanger.AdjustV   s'     ##H-I#Or   c                   UR                   R                  nU R                  bY  U H!  nUR                  U R                  :X  d  M  Us  $    UR	                  [
        R                  " U R                  S95        US   $ U(       d%  [
        R                  " SS9nUR	                  U5        U R                  (       a  US   $ U H  nUR                  (       d  M  Us  $    US   $ )a  Find the container to adjust.

1. Make ''(empty string) name referenceable.
2. If name is specified, but not found, create one with the name.
3. No name specified, no containers, add one with name ''.
4. No name specified, we have containers, return the first one for
non-ingress types.
5. For ingress types, return the ingress container. If not found, fall-back
to the first one.

Args:
  resource: The Cloud Run V2 resource to modify.

Returns:
  The container to adjust.
)name r   )	template
containersr%   r3   appendr   	Containerr'   ports)r+   r   r7   cr,   s        r   r0   %ContainerConfigChanger._FindContainerd   s    " ""--J &!66T((((  ))t/B/BCD^%%2.	)$ 
		!}AWWWH  !}r   r)   r,   zk8s_min.Container)__name__
__module____qualname____firstlineno____doc__r%   __annotations__r'   abcabstractmethodr-   r   r0   __static_attributes__r)   r   r   r"   r"   <   sH      $.*# D " )r   r"   c                  4    \ rS rSr% SrS\S'   S\S'   S rSrg)	SetAnnotationChange   zzRepresents the user intent to set an annotation.

Attributes:
  key: Annotation to set.
  value: Annotation value to set.
strkeyvaluec                L    U R                   UR                  U R                  '   U$ N)rL   r   rK   r+   r   s     r   r   SetAnnotationChange.Adjust   s    %)ZZH"Or   r)   Nr>   r?   r@   rA   rB   rC   r   rF   r)   r   r   rH   rH           (	*r   rH   c                  *    \ rS rSr% SrS\S'   S rSrg)DeleteAnnotationChange   z^Represents the user intent to delete an annotation.

Attributes:
  key: Annotation to delete.
rJ   rK   c                V    UR                   nU R                  U;   a  X R                  	 U$ rN   )r   rK   r+   r   r   s      r   r   DeleteAnnotationChange.Adjust   s(    &&Kxx;
hh
Or   r)   NrQ   r)   r   r   rT   rT           (r   rT   c                  4    \ rS rSr% SrS\S'   S\S'   S rSrg)	SetTemplateAnnotationChange   zRepresents the user intent to set a template annotation.

Attributes:
  key: Template annotation to set.
  value: Annotation value to set.
rJ   rK   rL   c                `    U R                   UR                  R                  U R                  '   U$ rN   )rL   r6   r   rK   rO   s     r   r   "SetTemplateAnnotationChange.Adjust   s%    .2jjH!!$((+Or   r)   NrQ   r)   r   r   r[   r[      rR   r   r[   c                  *    \ rS rSr% SrS\S'   S rSrg)DeleteTemplateAnnotationChange   zoRepresents the user intent to delete a template annotation.

Attributes:
  key: Template annotation to delete.
rJ   rK   c                j    UR                   R                  nU R                  U;   a  X R                  	 U$ rN   )r6   r   rK   rW   s      r   r   %DeleteTemplateAnnotationChange.Adjust   s.    ##//Kxx;
hh
Or   r)   NrQ   r)   r   r   r`   r`      rY   r   r`   c                  *    \ rS rSr% SrS\S'   S rSrg)SetLaunchStageChange   zWSets launch stage on a resource.

Attributes:
  launch_stage: The launch stage to set.
base.ReleaseTracklaunch_stagec                    U R                   [        R                  R                  :w  a8  [        R
                  R                  U R                   R                  5      Ul         U$ rN   )rh   r   ReleaseTrackGAr   LaunchStageValueidrO   s     r   r   SetLaunchStageChange.Adjust   sK    D--000.::@@




h Or   r)   NrQ   r)   r   r   re   re      s     "!r   re   c                  4    \ rS rSr% SrS\S'   S\S'   S rSrg)	SetClientNameAndVersionChange   z{Sets the client name and version.

Attributes:
  client_name: Client name to set.
  client_version: Client version to set.
rJ   client_nameclient_versionc                ~    U R                   b  U R                   Ul        U R                  b  U R                  Ul        U$ rN   )rs   clientrt   rO   s     r   r   $SetClientNameAndVersionChange.Adjust   s:    #((ho& $ 3 3hOr   r)   NrQ   r)   r   r   rq   rq      s     r   rq   c                  *    \ rS rSr% SrS\S'   S rSrg)ServiceAccountChange   zRepresents the user intent to change service account for the revision.

Attributes:
  service_account: The service account to set.
rJ   service_accountc                <    U R                   UR                  l         U$ )zCMutates the given config's service account to match what's desired.)r{   r6   rO   s     r   r   ServiceAccountChange.Adjust  s    (,(<(<H%Or   r)   NrQ   r)   r   r   ry   ry      s     r   ry   F)initr    c                  B   ^  \ rS rSr% SrS\S'   U 4S jrSS jrSrU =r	$ )	ImageChangei  zdA Cloud Run container deployment.

Attributes:
  image: The image to set in the adjusted container.
rJ   imagec                T   > [         TU ]  " S0 UD6  [        R                  U SU5        g )Nr   r)   super__init__object__setattr__)r+   r   kwargs	__class__s      r   r   ImageChange.__init__  s%    	Gv
tWe,r   c                &    U R                   Ul         g rN   )r   r*   s     r   r-   ImageChange.AdjustContainer  s    jjIOr   r)   r=   
r>   r?   r@   rA   rB   rC   r   r-   rF   __classcell__r   s   @r   r   r     s     
*-! !r   r   c                  8    \ rS rSr% SrSrS\S'   S rS	S jrSr	g)
AddDigestToImageChangei  zAdd image digest that comes from source build.

Attributes:
  image_digest: The image digest to set in the adjusted container.
Nr$   image_digestc                    SU;   $ )z0Return true if the given image url is by-digest.z@sha256:r)   )r+   urls     r   	_IsDigest AddDigestToImageChange._IsDigest'  s    r   c                    U R                  UR                  5      (       a  g U R                  (       a"  UR                  S-   U R                  -   Ul        g g )N@)r   r   r   r*   s     r   r-   &AddDigestToImageChange.AdjustContainer+  sA    ~~ioo&&!#-0A0AAio r   r)   r=   )
r>   r?   r@   rA   rB   r   rC   r   r-   rF   r)   r   r   r   r     s     ",
!Br   r   c                  f   ^  \ rS rSr% SrSrS\S'   SrS\S'   SrS\S'   SU 4S jjr	SS	 jr
S
rU =r$ )ResourceLimitsChangei2  aP  Represents the user intent to update resource limits.

Attributes:
  memory: Updated memory limit to set in the container. Specified as string
    ending in 'Mi' or 'Gi'. If None the memory limit is not changed.
  cpu: Updated cpu limit to set in the container if not None.
  gpu: Updated gpu limit to set in the container if not None.
Nr$   memorycpugpuc                   > [         TU ]  " S0 UD6  [        R                  U SU5        [        R                  U SU5        [        R                  U SU5        g )Nr   r   r   r)   r   )r+   r   r   r   r   r   s        r   r   ResourceLimitsChange.__init__A  sI    	Gv
tXv.
tUC(
tUC(r   c                   U R                   b#  U R                   UR                  R                  S'   U R                  b#  U R                  UR                  R                  S'   U R                  b[  U R                  S:X  a'  UR                  R                  R                  SS5        gU R                  UR                  R                  S'   gg)zCMutates the given config's resource limits to match what's desired.Nr   r   0znvidia.com/gpu)r   	resourceslimitsr   r   popr*   s     r   r-   $ResourceLimitsChange.AdjustContainerG  s    {{-1[[i  *xx*.((i  'xx	S""&&'7>7;xx	""#34	 r   r)   )NNNr=   )r>   r?   r@   rA   rB   r   rC   r   r   r   r-   rF   r   r   s   @r   r   r   2  s9     &*#z#z)
@ 
@r   r   c                    U R                   R                   H*  nUR                  S:X  d  M  UR                  (       d  M(  Us  $    g)z7Returns the Cloud SQL volume for the given worker pool.cloudsqlN)r6   r   r3   cloud_sql_instance)r   volumes     r   _GetCloudSQLVolumer   T  s9    !!))f{{j V%>%>%>m * 
r   c                6   U R                  S5      n[        U5      S:X  a  U $ [        U5      S:X  aD  U(       d  [        R                  " S5      eU(       d  [        R                  " S5      eU SU SU  3$ [        R                  " SR	                  U 5      5      e)zZValidates and augments the given Cloud SQL instance with the project and region if needed.:      zJTo specify a Cloud SQL instance by plain name, you must specify a project.zITo specify a Cloud SQL instance by plain name, you must specify a region.z&Malformed CloudSQL instance string: {})splitlenr   CloudSQLErrorformat)instance_strprojectregioninstances       r   _AugmentSQLInstancer   \  s     $(]a 8}$$  $$  Yaxq//

"
"077E r   c                F    U  Vs/ s H  n[        X1U5      PM     sn$ s  snf )z[Validates and augments the given Cloud SQL instances with the project and region if needed.)r   )	instancesr   r   r   s       r   _AugmentSQLInstancesr   z  s/     FO
EN(V4Y
  
s   c                  f    \ rS rSr% SrSrS\S'   SrS\S'   \R                  " \
S9rS\S	'   S
 rSrg)AddCloudSQLChangesi  a7  Represents the intent to append the given Cloud SQL instances to the current list.

Attributes:
    project: Project to use as the default project for Cloud SQL instances.
    region: Region to use as the default region for Cloud SQL instances
    add_cloudsql_instances: List of Cloud SQL instances to append.
Nr$   r   r   default_factorySequence[str]add_cloudsql_instancesc           
        [        U5      nUcw  [        R                  " S[        R                  " [	        U R
                  U R                  U R                  5      S9S9nUR                  R                  R                  U5        U$ UR                  R                  R                  [	        U R
                  U R                  U R                  5      5        U$ Nr   )r   )r3   r   )r   r   VolumeCloudSqlInstancer   r   r   r   r6   r   r8   r   r   extendr+   r   cloud_sql_volumes      r   r   AddCloudSQLChanges.Adjust  s    )(3 $55,--t||T[[ &&'78 O ))33::
))4<<
 Or   r)   )r>   r?   r@   rA   rB   r   rC   r   dataclassesfieldlistr   r   rF   r)   r   r   r   r     s=     ':&**5*;*;+- r   r   c                  f    \ rS rSr% SrSrS\S'   SrS\S'   \R                  " \
S9rS\S	'   S
 rSrg)RemoveCloudSQLChangesi  a<  Represents the intent to remove the given Cloud SQL instances from the current list.

Attributes:
    project: Project to use as the default project for Cloud SQL instances.
    region: Region to use as the default region for Cloud SQL instances
    remove_cloudsql_instances: List of Cloud SQL instances to remove.
Nr$   r   r   r   r   remove_cloudsql_instancesc                   [        U5      nUb  [        [        U R                  U R                  U R
                  5      5      nUR                  R                   Vs/ s H  nXC;  d  M
  UPM     snUR                  l        UR                  R                  (       dH  UR                  R                   Vs/ s H  nUR                  S:w  d  M  UPM     snUR                  l	        U$ s  snf s  snf Nr   )r   setr   r   r   r   r   r   r6   r   r3   )r+   r   r   instances_to_remover   r   s         r   r   RemoveCloudSQLChanges.Adjust  s    )(3 #
,,dllDKK +==GG7Gh0 G7))3 00:: #++33%
3{{j( 3%
!
 O7%
s   	C%(C%3C*C*r)   )r>   r?   r@   rA   rB   r   rC   r   r   r   r   r   r   rF   r)   r   r   r   r     s=     ':&*-8->->.] r   r   c                      \ rS rSrSrS rSrg)ClearCloudSQLChangesi  a1  Represents the intent to clear the current list of Cloud SQL instances.

Attributes:
    project: Project to use as the default project for Cloud SQL instances.
    region: Region to use as the default region for Cloud SQL instances
    clear_cloudsql_instances: Whether to clear the Cloud SQL instances.
c                    UR                   R                   Vs/ s H  nUR                  S:w  d  M  UPM     snUR                   l        U$ s  snf r   )r6   r   r3   )r+   r   r   s      r   r   ClearCloudSQLChanges.Adjust  sN    
 ''//!/F;;*$ 	/!H
 O!s
   AAr)   Nr>   r?   r@   rA   rB   r   rF   r)   r   r   r   r     s    r   r   c                  f    \ rS rSr% SrSrS\S'   SrS\S'   \R                  " \
S9rS\S	'   S
 rSrg)SetCloudSQLChangesi  a?  Represents the intent to replace the current list of Cloud SQL instances with the given list.

Attributes:
    project: Project to use as the default project for Cloud SQL instances.
    region: Region to use as the default region for Cloud SQL instances
    set_cloudsql_instances: List of Cloud SQL instances to set.
Nr$   r   r   r   r   set_cloudsql_instancesc           
        [        U5      nUcw  [        R                  " S[        R                  " [	        U R
                  U R                  U R                  5      S9S9nUR                  R                  R                  U5        U$ [	        U R
                  U R                  U R                  5      UR                  l        U$ r   )r   r   r   r   r   r   r   r   r6   r   r8   r   r   r   s      r   r   SetCloudSQLChanges.Adjust  s    )(3 $55,--t||T[[ &&'78 O 7K

%
%t||T[[7))3 Or   r)   )r>   r?   r@   rA   rB   r   rC   r   r   r   r   r   r   rF   r)   r   r   r   r     s=     ':&**5*;*;+- r   r   ?   c                  *    \ rS rSr% SrS\S'   S rSrg)RevisionNameChangei  z{Represents the user intent to change revision name.

Attributes:
  revision_suffix: Suffix to append to the revision name.
rJ   revision_suffixc                ,   U R                   (       d  SUR                  l        U$ [        [	        U R                   5      -
  S-
  n[
        R                  " UR                  5      Gt p4SR                  USU U R                   5      UR                  l        U$ )zAMutates the given config's revision name to match what's desired.r5   r   z{}-{}N)	r   r6   revision_MAX_RESOURCE_NAME_LENGTHr   r   GetInfoFromFullNamer3   r   )r+   r   max_prefix_length_r3   s        r   r   RevisionNameChange.Adjust  s    #%h o 	"C(<(<$==A  (;;HMMJHQ!( $"6"6"H Or   r)   NrQ   r)   r   r   r   r     s     r   r   c                  4    \ rS rSr% SrS\S'   S\S'   S rSrg)	
MeshChangei,  a  Represents the user intent to enable/disable Cloud Service Mesh.

Attributes:
  project: The project to use for the mesh when not specified in mesh_name.
  mesh_name: Mesh resource name in the format of MESH_NAME or
    projects/PROJECT/locations/global/meshes/MESH_NAME.
rJ   r   	mesh_namec                    U R                   (       a  SU R                   ;   a  U R                   OSU R                   SU R                    3UR                  R                  l        U$ )N/z	projects/z/locations/global/meshes/)r   r   r6   service_meshmeshrO   s     r   r   MeshChange.Adjust9  sT     ~~!6 	&??OP ""'
 Or   r)   NrQ   r)   r   r   r   r   ,  s     ,.r   r   c                  *    \ rS rSr% SrS\S'   S rSrg)GpuTypeChangeiB  z`Sets the gpu-type on the resource template.

Attributes:
  gpu_type: The gpu_type value to set.
rJ   gpu_typec                    U R                   (       a'  U R                   UR                  R                  l        U$ S UR                  R                  l        U$ rN   )r   r6   node_selectoracceleratorrO   s     r   r   GpuTypeChange.AdjustL  sC    }}48MMh%%1 O 59h%%1Or   r)   NrQ   r)   r   r   r   r   B  s     -r   r   c                  *    \ rS rSr% SrS\S'   S rSrg)GpuZonalRedundancyChangeiT  zSets the gpu-zonal-redundancy-disabled field on the resource template.

Attributes:
  gpu_zonal_redundancy: The gpu_zonal_redundancy value to set.
r&   gpu_zonal_redundancyc                F    U R                   (       + UR                  l        U$ rN   )r   r6   gpu_zonal_redundancy_disabledrO   s     r   r   GpuZonalRedundancyChange.Adjust^  s#    %%% 3 Or   r)   NrQ   r)   r   r   r   r   T  s     r   r   c                  B   ^  \ rS rSr% SrS\S'   U 4S jrSS jrSrU =r	$ )	ContainerCommandChangeie  zRepresents the user intent to change the 'command' for the container.

Attributes:
  command: The command to set in the adjusted container.
rJ   commandc                T   > [         TU ]  " S0 UD6  [        R                  U SU5        g )Nr  r)   r   )r+   r  r   r   s      r   r   ContainerCommandChange.__init__o  s%    	Gv
tY0r   c                &    U R                   Ul         g rN   )r  r*   s     r   r-   &ContainerCommandChange.AdjustContainers  s    Ir   r)   r=   r   r   s   @r   r   r   e  s     ,1% %r   r   c                  B   ^  \ rS rSr% SrS\S'   U 4S jrSS jrSrU =r	$ )	ContainerArgsChangeiw  zRepresents the user intent to change the 'args' for the container.

Attributes:
  args: The args to set in the adjusted container.
	list[str]argsc                T   > [         TU ]  " S0 UD6  [        R                  U SU5        g )Nr	  r)   r   )r+   r	  r   r   s      r   r   ContainerArgsChange.__init__  s%    	Gv
tVT*r   c                &    U R                   Ul         g rN   )r	  r*   s     r   r-   #ContainerArgsChange.AdjustContainer  s    YYINr   r)   r=   r   r   s   @r   r  r  w  s     	/+ r   r  c                      \ rS rSr% Sr\R                  " \S9rS\	S'   \R                  " \
S9rS\	S'   SrS	\	S
'   SS jrSrg)EnvVarLiteralChangesi  zRepresents the user intent to modify environment variables string literals.

Attributes:
  updates: Updated env var names and values to set.
  removes: Env vars to remove.
  clear_others: If true clear all non-updated env vars.
r   dict[str, str]updatesr  removesFr&   clear_othersc                H   [        UR                  5      nU R                  (       a4  U Vs/ s H'  nSU;   d  UR                  U R                  ;   d  M%  UPM)     nn/ nU H  nSU;   a\  UR                  U R                  ;   a/  [
        R                  " SR                  UR                  5      5      eUR                  U5        Me  UR                  U R                  ;   a  M  UR                  U R                  ;   aC  U R                  UR                     Ul
        U R                  R                  UR                  5        UR                  U5        M     U R                  R                  5        H(  u  pVUR                  [        R                  " XVS95        M*     XAl        gs  snf )a  Mutates the given config's env vars literals to match the desired changes.

Args:
  container: container to adjust

Returns:
  The adjusted container

Raises:
  ConfigurationError if there's an attempt to replace the source of an
    existing environment variable whose source is of a different type
    (e.g. env var's secret source can't be replaced with a config map
    source).
value_sourcezpCannot update environment variable [{}] to string literal because it has already been set with a different type.)r3   rL   N)r   envr  r3   r  r   ConfigurationErrorr   r8   r  rL   r   itemsr   EnvVar)r+   r,   current_env_varsenv_varupdated_env_varsenv_var_nameenv_var_values          r   r-   $EnvVarLiteralChanges.AdjustContainer  s]     IMM* *)gw&',,$,,*F )   #	7	"<<4<<'--HHN,,I  	(		% 
	%W\\2&g&- $2 (,||'9'9';#
..l
@ (< %MIs   $FFr)   Nr=   )r>   r?   r@   rA   rB   r   r   dictr  rC   r   r  r  r-   rF   r)   r   r   r  r    sB     (--dC'>C"((>'9>,7%r   r  c                      \ rS rSr% Sr\R                  " \S9rS\	S'   \R                  " \
S9rS\	S'   SrS	\	S
'   SS jrSS jrSrg)SecretsEnvVarChangesi  zRepresents the user intent to modify environment variable secrets.

Attributes:
  updates: Updated env var names and values to set.
  removes: Secret env vars to remove.
  clear_others: If true clear all non-updated secret env vars.
r   r  r  r  r  Fr&   r  c                H   UR                  S5      n[        U5      S:X  a#  [        R                  " SR	                  US95      e[        U5      S:X  a  Uu  p4O%[        R                  " SR	                  U5      5      e[
        R                  " [
        R                  " UUS9S9$ )	zFBuilds a secret env var source from the given secret name and version.r   r   z^No secret version specified for {secret}. Use {secret}:latest to reference the latest version.)secret   z#Invalid secret name and version: {})r$  version)secret_key_ref)r   r   r   r  r   r   EnvVarSourceSecretKeySelector)r+   r$  partssecret_namesecret_versions        r   _BuildSecretEnvVarSource-SecretsEnvVarChanges._BuildSecretEnvVarSource  s    LLE
5zQ))AAG BH B  
Uq$)!k>))
/
6
6v
>  00"
 r   c           	        [        UR                  5      nU R                  (       a4  U Vs/ s H'  nSU;  d  UR                  U R                  ;   d  M%  UPM)     nn/ nU H  nSU;  a\  UR                  U R                  ;   a/  [
        R                  " SR                  UR                  5      5      eUR                  U5        Me  UR                  U R                  ;   a  M  UR                  U R                  ;   aR  U R                  U R                  UR                     5      Ul        U R                  R                  UR                  5        UR                  U5        GM     U R                  R                  5        H8  u  pVUR                  [        R                  " UU R                  U5      S95        M:     XAl        gs  snf )a~  Mutates the given config's secrets env vars to match the desired changes.

Args:
  container: container to adjust

Returns:
  The adjusted container

Raises:
  ConfigurationError if there's an attempt to replace the source of an
    existing environment variable whose source is of a different type
    (e.g. env var's secret source can't be replaced with a config map
    source).
r  zwCannot update environment variable [{}] to secret source env var because it has already been set with a different type.)r3   r  N)r   r  r  r3   r  r   r  r   r8   r  r-  r  r   r  r   r  )r+   r,   r  r  r  r  r$  s          r   r-   $SecretsEnvVarChanges.AdjustContainer  s     IMM* *)g7*glldll.J )   #	w	&<<4<<'--HHN,,I  	(		% 
	%#<<LL& 
 	&g&1 $6 !% 2 2 4
..88@ !5 %MSs   $F?F?r)   N)r$  rJ   returnzk8s_min.EnvVarSourcer=   )r>   r?   r@   rA   rB   r   r   r   r  rC   r   r  r  r-  r-   rF   r)   r   r   r"  r"    sG     (--dC'>C"((>'9>,.<%r   r"  c                  *    \ rS rSr% SrS\S'   S rSrg)DescriptionChangei5  zoRepresents the user intent to change resource description.

Attributes:
  description: The description to set.
rJ   descriptionc                (    U R                   Ul         U$ )zAMutates the given resource's description to match what's desired.)r4  rO   s     r   r   DescriptionChange.Adjust?  s    ++HOr   r)   NrQ   r)   r   r   r3  r3  5  s     r   r3  c                  J    \ rS rSr% SrSrS\S'   SrS\S'   SrS\S	'   S
 r	Sr
g)BinaryAuthorizationChangeiE  zRepresents the user intent to change binary authorization.

Attributes:
  policy: The binauthz policy to set.
  breakglass_justification: The breakglass justification to set.
  clear_binary_authorization: Whether to clear binary authorization.
Nr$   policybreakglass_justificationFr&   clear_binary_authorizationc                   U R                   (       a5  SUR                  l        SUR                  l        SUR                  l        U$ U R                  S:X  a  SUR                  l        O=U R                  (       a,  SUR                  l        U R                  UR                  l        U R                  (       a  U R                  UR                  l        U$ )z<Mutates the given resource's policy to match what's desired.Fr5   defaultT)r;  binary_authorizationuse_defaultr9  r:  rO   s     r   r    BinaryAuthorizationChange.AdjustS  s     &&27h##/-/h##*?Ah##<o{{i26h##/	27h##/-1[[h##*$$

'
' ##< Or   r)   )r>   r?   r@   rA   rB   r9  rC   r:  r;  r   rF   r)   r   r   r8  r8  E  s.     &*)-J-%*d*r   r8  c                      \ rS rSr% Sr\R                  " \S9rS\	S'   \R                  " \
S9rS\	S'   SrS	\	S
'   \S 5       rS rSrg)LabelChangeih  a9  Represents the user intent to modify metadata labels.

Attributes:
  additions: {str: str}, any label values to be updated
  subtractions: List[str], any labels to be removed
  clear_labels: bool, whether to clear the labels

Raises:
    ValueError: if both subtractions and clear are specified at the same time.
r   r  	additionsr  subtractionsFr&   clear_labelsc                    g)NTr)   )r+   s    r   adjusts_templateLabelChange.adjusts_templatey  s    r   c                P   U R                   (       a  U R                  (       a  [        S5      eU R                  (       a>  UR                  R	                  5         UR
                  R                  R	                  5         UR                  R                  U R                  5        UR
                  R                  R                  U R                  5        U R                    HE  nUR                  R                  US 5        UR
                  R                  R                  US 5        MG     U$ )NzCCannot specify both subtractions and clear_labels at the same time.)	rD  rE  
ValueErrorlabelsclearr6   updaterC  r   )r+   r   	label_keys      r   r   LabelChange.Adjust}  s    T..
O  oo$$&OO4>>*##DNN3&&	oo)T*""9d3 ' Or   r)   N)r>   r?   r@   rA   rB   r   r   r   rC  rC   r   rD  rE  propertyrG  r   rF   r)   r   r   rB  rB  h  sT    	 *//E)^E'--dC,	C, r   rB  c                      \ rS rSr% SrSrS\S'   SrS\S'   SrS\S'   \	R                  " \S9rS	\S
'   SrS\S'   SrS\S'   S rSrg)VpcAccessChangesi  az  Represents the user intent to modify VPC access.

Attributes:
  vpc_egress: str, the vpc egress setting (all traffic, private ranges only).
  network: str, vpc network to set.
  subnet: str, vpc subnet to set.
  network_tags: List[str], vpc network tags to set.
  clear_network: bool, whether to clear the network.
  clear_network_tags: bool, whether to clear the network tags.
Nr$   
vpc_egressnetworksubnetr   r  network_tagsFr&   clear_networkclear_network_tagsc                V   U R                   (       aZ  S UR                  R                  l        [        R
                  R                  R                  UR                  R                  l        U$ UR                  R                  R                  (       dK  UR                  R                  R                  R                  [        R
                  R                  5       5        UR                  R                  R                  S   nU R                  (       a  U R                  Ul        U R                  (       a  U R                  Ul        U R                  (       a  U R                  Ul        U R                   (       a  / Ul        U R"                  S:X  d  U R"                  S:X  a?  [        R
                  R                  R$                  UR                  R                  l        U$ U R"                  S:X  a=  [        R
                  R                  R&                  UR                  R                  l        U$ )Nr   allzall-trafficzprivate-ranges-only)rW  r6   
vpc_accessnetwork_interfacesr   	VpcAccess	VpcEgressVPC_EGRESS_UNSPECIFIEDegressr8   NetworkInterfacerT  rU  
subnetworkrV  tagsrX  rS  ALL_TRAFFICPRIVATE_RANGES_ONLY)r+   r   network_interfaces      r   r   VpcAccessChanges.Adjust  s   8<h""5

#
#
-
-
D
D "") o''::""55<<

#
#
4
4
6 !))44GGJ||"&,,{{%)[["#00!%4??m#C

#
#
-
-
9
9 "") O	 
1	1

#
#
-
-
A
A "") Or   r)   )r>   r?   r@   rA   rB   rS  rC   rT  rU  r   r   r   rV  rW  rX  r   rF   r)   r   r   rR  rR    sV    	  *j':&*'--dC,	C-"d"r   rR  c                  t    \ rS rSr% SrSrS\S'   SrS\S'   SrS\S'   S	r	S
\S'   S	r
S
\S'   S	rS
\S'   S rSrg)CmekKeyChangesi  aq  Represents the user intent to add cmek key related changes.

Attributes:
  key: str, cmek key to set.
  post_key_revocation_action_type: str, vpc network to set.
  encryption_key_shutdown_hours: int, the number of hours to wait before an
    automatic shutdown server after CMEK key revocation is detected.
  clear_key: bool, whether to clear any previously set CMEK key reference.
  clear_post_key_revocation_action_type: bool, whether to clear any previously
    set post CMEK key revocation action type.
  clear_encryption_key_shutdown_hours: bool, whether to clear any previously
    set CMEK key shutdown hours setting.
Nr$   rK   post_key_revocation_action_typez
int | Noneencryption_key_shutdown_hoursFr&   	clear_key%clear_post_key_revocation_action_type#clear_encryption_key_shutdown_hoursc                *   U R                   b  U R                   UR                  l        U R                  (       aS  U R                  S:X  a  [        R
                  R                  O[        R
                  R                  UR                  l        U R                  b0  [        R                  " U R                  S-  S9UR                  l        U R                  (       aK  S UR                  l        [        R
                  R                  UR                  l        S UR                  l        U R                  (       a:  [        R
                  R                  UR                  l        S UR                  l        U R                   (       a  S UR                  l        U$ )Nzprevent-newi  )seconds)rK   r6   encryption_keyrj  r   EncryptionKeyRevocationActionPREVENT_NEWSHUTDOWN encryption_key_revocation_actionrk  r   Duration encryption_key_shutdown_durationrl  ,ENCRYPTION_KEY_REVOCATION_ACTION_UNSPECIFIEDrm  rn  rO   s     r   r   CmekKeyChanges.Adjust  s5   xx)-h&++
 11]B 
7
7
C
C<<EE 8
 ))5


884? 8 ~~)-h&

7
7
d
d 8 <@h811

7
7
d
d 8 <@h8//;?h8Or   r)   )r>   r?   r@   rA   rB   rK   rC   rj  rk  rl  rm  rn  r   rF   r)   r   r   ri  ri    sN     #z04!:4.22)T05'5.3%t3!r   ri  c                  4    \ rS rSr% SrS\S'   S\S'   S rSrg	)
RemoveVolumeChangei  zrRemoves volumes from the service/job/worker-pool template.

Attributes:
  removed_volumes: The volumes to remove.
Iterable[str]removed_volumesr&   clear_volumesc                   U R                   (       a&  UR                  R                  R                  5         U$ U R                  (       at  UR                  R                   Vs0 s H  o"R
                  U_M     nnU R                   H  nXC;   d  M
  X4	 M     [        UR                  5       5      UR                  l        U$ s  snf rN   )r~  r6   r   rL  r}  r3   r   values)r+   r   r   current_volumes	to_removes        r   r   RemoveVolumeChange.Adjust  s    %%' O 
		,4,=,=,E,E,E&++v
,E   ++)'( , #''='='?"@hOs   !B?r)   NrQ   r)   r   r   r{  r{    s     ! r   r{  c                  `    \ rS rSr% SrS\S'   \R                  R                  r	S\S'   S r
Srg	)
AddVolumeChangei  zUpdates Volumes set on the service/job/worker-pool template.

Attributes:
  new_volumes: The volumes to add.
  release_track: The resource's release track. Used to verify volume types are
    supported in that release track.
z Iterable[volumes_lib.VolumeDict]new_volumesrg   release_trackc                B   UR                   R                   Vs0 s H  o"R                  U_M     nnU R                   H1  n[        R
                  " X R                  5      nXCUR                  '   M3     [        UR                  5       5      UR                   l        U$ s  snf rN   )	r6   r   r3   r  volumes_libcreate_volume_v2r  r   r  )r+   r   r   r  
new_volumes        r   r   AddVolumeChange.Adjust)  s     +3*;*;*C*C*CV*C   ""//8J8JKj)3joo& # !%_%;%;%= >HOs   Br)   N)r>   r?   r@   rA   rB   rC   r   rj   ALPHAr  r   rF   r)   r   r   r  r    s+     0/%)%6%6%<%<-"<	r   r  c                  X    \ rS rSr% Sr\R                  " \S9rS\	S'   Sr
S\	S'   S	 rS
rg)RemoveVolumeMountChangei5  zRemoves Volume Mounts from the container.

Attributes:
  removed_mounts: Volume mounts to remove from the adjusted container.
  clear_mounts: Whether to clear all volume mounts.
r   r|  removed_mountsFr&   clear_mountsc                    U R                   (       a  UR                  R                  5         U$ [        U R                  5      nUR                   Vs/ s H  nUR
                  U;  d  M  UPM     snUl        U$ s  snf rN   )r  volume_mountsrL  r   r  
mount_path)r+   r,   r  volume_mounts       r   r-   'RemoveVolumeMountChange.AdjustContainerA  sz    ##%  4../n (55!5l$$N: 5!i
 !s   A9)A9r)   N)r>   r?   r@   rA   rB   r   r   r   r  rC   r  r-   rF   r)   r   r   r  r  5  s-     #."3"3D"I.-I,
r   r  VolumeMountDict)r   
mount-pathc                  N    \ rS rSr% Sr\R                  " \S9rS\	S'   S	S jr
Srg)
AddVolumeMountChangeiW  zpUpdates Volume Mounts set on the container.

Attributes:
  new_mounts: Mounts to add to the adjusted container.
r   zIterable[VolumeMountDict]
new_mountsc                D   UR                    Vs0 s H  nUR                  U_M     nnU R                   HE  nSU;  d  SU;  a  [        R                  " S5      e[
        R                  " US   US   S9X4S   '   MG     [        UR                  5       5      Ul         U$ s  snf )Nr   r  z<Added Volume mounts must have a `volume` and a `mount-path`.)r3   r  )	r  r  r  r   r  r   VolumeMountr   r  )r+   r,   r  current_mountsmounts        r   r-   $AddVolumeMountChange.AdjustContainerc  s     &333L 	-3   		,e";++J
 	
 -4,?,?X5+>-n<() ! #>#8#8#:;Is   Br)   Nr=   )r>   r?   r@   rA   rB   r   r   r   r  rC   r-   rF   r)   r   r   r  r  W  s)     +6*;*;+*' r   r  c                  *    \ rS rSr% SrS\S'   S rSrg)RemoveContainersChangeit  z]Removes the specified containers.

Attributes:
  containers_to_remove: Containers to remove.
r|  containers_to_removec                    [        U R                  5      nUR                  R                   Vs/ s H  nUR                  U;  d  M  UPM     snUR                  l        U$ s  snf rN   )r   r  r6   r7   r3   )r+   r   r  r,   s       r   r   RemoveContainersChange.Adjust~  s`    t889 "**55$5I>>!55 	5$H 
 O$s   A A r)   NrQ   r)   r   r   r  r  t  s     &%r   r  c                  J    \ rS rSr% Sr\R                  " \S9rS\	S'   S r
Srg)	ContainerDependenciesChangei  a8  Sets container dependencies.

Updates container dependencies to add the dependencies in new_dependencies.
Additionally, dependencies to or from a container which does not exist will be
removed.

Attributes:
    new_dependencies: A map of containers to their updated dependencies.
      Defaults to an empty map.
r   zMapping[str, Iterable[str]]new_dependenciesc           
        [        UR                  R                   Vs/ s H  o"R                  PM     sn5      nUR                  R                   VVs0 s H2  nUR                  UR                   Vs/ s H  oDU;   d  M
  UPM     sn_M4     nnnU R
                  R                  5        H_  u  pg[        U5      nXs-
  =n(       a,  [        R                  " SU SSR                  U5       S35      eU(       a  [        U5      XV'   M]  XV	 Ma     UR                  R                   H$  nUR                  UR                  / 5      Ul        M&     U$ s  snf s  snf s  snnf )zUpdates container dependencies.z--depends_on for container z$ references nonexistent containers: ,.)r   r6   r7   r3   
depends_onr  r  	frozensetr   r  joinsortedget)	r+   r   r,   current_containersr;   current_dependenciesr%   r  missings	            r   r   "ContainerDependenciesChange.Adjust  sZ   )1):):)E)EF)EI)EF "**55	 6I 	 ++
+!4F/FA+
 	
 6	   '+&;&;&A&A&C"Z(j3	3	3++).)9 :((+(9':!=
 	
 
/5j/A, 0 'D &&11	155innbIi 2O/ 	G
s#   EE2	E?EEEr)   N)r>   r?   r@   rA   rB   r   r   r   r  rC   r   rF   r)   r   r   r  r    s*    	 3>2C2C3/ r   r  c                  N    \ rS rSr% SrSrS\S'   SrS\S'   SrS\S'   SS	 jr	S
r
g)WorkerPoolScalingChangei  a$  Represents the user intent to adjust worker pool scaling.

Attributes:
  min_instance_count: The minimum count of instances to set.
  max_instance_count: The maximum count of instances to set.
  scaling: Scaling flag value that either contains manual instance count or
    auto scaling mode.
Nzflags.ScaleValue | Nonemin_instance_countmax_instance_countzflags.ScalingValue | Nonescalingc                   UR                   R                  nU R                  (       d  U R                  (       aO  U R                   (       d>  U[        R
                  R                  R                  :X  a  [        R                  " S5      eU R                  (       a  U R                   (       a1  U R                   R                  (       d  [        R                  " S5      eU R                  R                  (       a  SUR                   l        O%U R                  R                  UR                   l        U R                  (       a  U R                   (       a1  U R                   R                  (       d  [        R                  " S5      eU R                  R                  (       a  SUR                   l        O%U R                  R                  UR                   l        U R                   (       a  U R                   R                  (       aF  SUR                   l        [        R
                  R                  R                  UR                   l        U$ SUR                   l        SUR                   l        [        R
                  R                  R                  UR                   l        U R                   R                  UR                   l        U$ )a  Adjusts worker pool scaling.

Args:
  worker_pool_resource: The worker pool resource to modify.

Raises:
  ConfigurationError: If the user attempts to set min or max instance count
  without setting --scaling=auto when the current scaling mode is manual.
  ConfigurationError: If the user attempts to set min or max instance count
  along with a manual instance count using --scaling flag.

Returns:
  The adjusted worker pool resource.
zBNeed to specify --scaling=auto to swtich mode from manual to auto.zBCannot set --min when --scaling is set to a manual instance count.r   zBCannot set --max when --scaling is set to a manual instance count.d   N)r  scaling_moder  r  r   WorkerPoolScalingScalingModeMANUALr   r  auto_scalingrestore_defaultinstance_countmanual_instance_count	AUTOMATIC)r+   worker_pool_resourcecurrent_scaling_modes      r   r   WorkerPoolScalingChange.Adjust  s   " 077DD		 	 D$;$; ,,88??@ ))
N  	dll77++P
 	
 
	 	 	0	0:;$$7 ##22 	$$7 	dll77++P
 	
 
	 	 	0	0:=$$7 ##22 	$$7 ||		"	"=A$$:--99CC 	$$1   ;?$$7:>$$7--99@@ 	$$1 LL'' 	$$:  r   r)   )r  worker_pool_objects.WorkerPool)r>   r?   r@   rA   rB   r  rC   r  r  r   rF   r)   r   r   r  r    s2     15-404-4'+'$+G r   r  c                  "    \ rS rSrSrSS jrSrg)NoPromoteChangei  zRRepresents the user intent to block instance assignment for a new worker revision.c                    UR                   (       d  [        R                  " S5      e[        R                  " UR
                  5      n[        R                  " [        UR                  5      U5      Ul	        U$ )znRemoves LATEST from the worker pools instance assignments and assign the percent to the latest ready revision.z;--no-promote not supported when creating a new worker pool.)

generationr   r  r   GetNameFromFullChildNamelatest_ready_revisioninstance_split_libZeroLatestAssignmentr   instance_splits)r+   r   latest_ready_revision_names      r   r   NoPromoteChange.Adjust  sl    ))
G  	!99**	
 
  2FFX%%&(B H Or   r)   Nr   r  r   r)   r   r   r  r    s
    Zr   r  c                  \    \ rS rSr% SrSrS\S'   \R                  " \	S9r
S\S'   SS	 jrS
rg)InstanceSplitChangei(  zRepresents the user intent to change a worker pool's instance split assignments.

Attributes:
  to_latest: Whether to assign all traffic to the latest revision.
  to_revisions: The new instance split percentages to set based on revision.
Fr&   	to_latestr   zdict[str, int]to_revisionsc                   U R                   (       ab  UR                  R                  5         UR                  R                  [        R
                  " [        R                  R                  SS95        U$ U R                  (       a9  [        R                  " [        UR                  5      U R                  5      Ul        U$ )Nr  )typepercent)r  r  rL  r8   r   InstanceSplitInstanceSplitAllocationType%INSTANCE_SPLIT_ALLOCATION_TYPE_LATESTr  r  GetUpdatedSplitsr   rO   s     r   r   InstanceSplitChange.Adjust4  s    ~~$$&%%

&
&!==cc O	 
		!3!D!D
x''
($*;*;"h Or   r)   Nr  )r>   r?   r@   rA   rB   r  rC   r   r   r   r  r   rF   r)   r   r   r  r  (  s-     )T!,!2!24!H,Hr   r  )r   rJ   r   r$   r   r$   r1  rJ   )r   r   r   r$   r   r$   r1  r   )TrB   
__future__r   r   r   r   r   rD   collections.abcr   r	   r
   r   typingr   cloudsdk.google.protobufr   
google.apir   googlecloudsdk.callioper   googlecloudsdk.command_lib.runr   r   r   r   r   r  !googlecloudsdk.command_lib.run.v2r   r  ;googlecloudsdk.generated_clients.gapic_clients.run_v2.typesr   r   r   worker_pool_objectsr   	dataclassTemplateConfigChangerr"   NonTemplateConfigChangerrH   rT   r[   r`   re   rq   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r"  r3  r8  ConfigChangerrB  rR  ri  r{  r  r  rJ   r  r  r  r  r  r  r  r)   r   r   <module>r     s"   I & "  % ' 
 7 7   1 ' ( 9 5 0 C A R V O W j" d#P^AA P $Ph d#.AA  $  d#^DD  $  d#."F"F  $  d#^%I%I  $  d#>BB  $" d#N$K$K  $& d#>??  $ E$/!( ! 0!" d#B3 B $B( d#@1 @ $@B  		<  	 d##== # $#L d#%N@@ % $%P d#>??  $( d#!== ! $!H   d#==  $2 d#55  $* d#N88  $" d#~CC  $  E$/%3 % 0%" E$/0  0" d#D%1 D% $D%N d#`%1 `% $`%F d#??  $ d# G G  $D d#&... & $&R d#1~;; 1 $1h d#7^99 7 $7t d#==  $2 d#n::  $0 d#4  $0  d#1  $8 d#^AA  $& d#*."F"F * $*b d#U nEE U  $U p d#n==  $( d#.AA  $r   