
    v                    (   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlm	Z	m
Z
mZ ddlZdd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z# d Z$ ejJ                  d       G d dejL                               Z' ejJ                  d       G d dejP                               Z) ejJ                  d       G d dejP                               Z* ejJ                  d       G d d ejL                               Z+ ejJ                  d       G d! d"ejL                               Z, ejJ                  d       G d# d$ejP                               Z- ejJ                  d       G d% d&ejP                               Z. ejJ                  d       G d' d(ejL                               Z/ ejJ                  d)d*       G d+ d,e'             Z0 ejJ                  d       G d- d.e'             Z1 ejJ                  d       G d/ d0e'             Z2d1 Z3	 	 	 	 	 	 	 	 dkd2Z4	 	 	 	 	 	 	 	 dld3Z5 ejJ                  d       G d4 d5ejL                               Z6 ejJ                  d       G d6 d7ejL                               Z7 ejJ                  d       G d8 d9ejL                               Z8 ejJ                  d       G d: d;ejL                               Z9d<Z: ejJ                  d       G d= d>ejL                               Z; ejJ                  d       G d? d@ejL                               Z< ejJ                  d       G dA dBejL                               Z= ejJ                  d       G dC dDejL                               Z> ejJ                  d)d*       G dE dFe'             Z? ejJ                  d)d*       G dG dHe'             Z@ ejJ                  d       G dI dJe'             ZA ejJ                  d       G dK dLe'             ZB ejJ                  d       G dM dNejP                               ZC ejJ                  d       G dO dPejP                               ZD ejJ                  d       G dQ dRej                               ZF ejJ                  d       G dS dTejL                               ZG ejJ                  d       G dU dVejL                               ZH ejJ                  d       G dW dXejL                               ZI ejJ                  d       G dY dZejL                               ZJ ejJ                  d       G d[ d\e'             ZK ed]eLeLd^      ZM ejJ                  d       G d_ d`e'             ZN ejJ                  d       G da dbejL                               ZO ejJ                  d       G dc ddejL                               ZP ejJ                  d       G de dfejP                               ZQ ejJ                  d       G dg dhejP                               ZR ejJ                  d       G di djejP                               ZSy)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                6    |D ]  }|j                  |       }  | S )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                  d    e Zd ZU dZdZded<   dZded<   ej                  	 	 dd       Z	d	 Z
d
 Zy)ContainerConfigChangerzAn 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                     y)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   AdjustContainerz&ContainerConfigChanger.AdjustContainerH   s    r   c                J    | j                  |      }| j                  |       |S )aN  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   zContainerConfigChanger.AdjustV   s'     ##H-I#Or   c                   |j                   j                  }| j                  X|D ]  }|j                  | j                  k(  s|c S  |j	                  t        j                  | j                               |d   S |s't        j                  d      }|j	                  |       | j                  r|d   S |D ]  }|j                  s|c S  |d   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$   r0   appendr   	Containerr&   ports)r*   r   r4   cr+   s        r   r.   z%ContainerConfigChanger._FindContainerd   s    " ""--J &!66T((((  ))t/B/BCD^%%2.	)$ 
		!}AWWH  !}r   r+   zk8s_min.Container)__name__
__module____qualname____doc__r$   __annotations__r&   abcabstractmethodr,   r   r.   r(   r   r   r"   r"   <   sH      $.*# D " )r   r"   c                  ,    e Zd ZU dZded<   ded<   d Zy)SetAnnotationChangezRepresents the user intent to set an annotation.

  Attributes:
    key: Annotation to set.
    value: Annotation value to set.
  strkeyvaluec                L    | j                   |j                  | j                  <   |S N)rE   r   rD   r*   r   s     r   r   zSetAnnotationChange.Adjust   s    %)ZZH"Or   Nr:   r;   r<   r=   r>   r   r(   r   r   rB   rB           (	*r   rB   c                  "    e Zd ZU dZded<   d Zy)DeleteAnnotationChangezdRepresents the user intent to delete an annotation.

  Attributes:
    key: Annotation to delete.
  rC   rD   c                T    |j                   }| j                  |v r|| j                  = |S rG   )r   rD   r*   r   r   s      r   r   zDeleteAnnotationChange.Adjust   s*    &&Kxx;
dhh
Or   NrI   r(   r   r   rL   rL           (r   rL   c                  ,    e Zd ZU dZded<   ded<   d Zy)SetTemplateAnnotationChangezRepresents the user intent to set a template annotation.

  Attributes:
    key: Template annotation to set.
    value: Annotation value to set.
  rC   rD   rE   c                `    | j                   |j                  j                  | j                  <   |S rG   )rE   r3   r   rD   rH   s     r   r   z"SetTemplateAnnotationChange.Adjust   s%    .2jjH!!$((+Or   NrI   r(   r   r   rQ   rQ      rJ   r   rQ   c                  "    e Zd ZU dZded<   d Zy)DeleteTemplateAnnotationChangezuRepresents the user intent to delete a template annotation.

  Attributes:
    key: Template annotation to delete.
  rC   rD   c                h    |j                   j                  }| j                  |v r|| j                  = |S rG   )r3   r   rD   rN   s      r   r   z%DeleteTemplateAnnotationChange.Adjust   s0    ##//Kxx;
dhh
Or   NrI   r(   r   r   rT   rT      rO   r   rT   c                  "    e Zd ZU dZded<   d Zy)SetLaunchStageChangez]Sets launch stage on a resource.

  Attributes:
    launch_stage: The launch stage to set.
  base.ReleaseTracklaunch_stagec                    | j                   t        j                  j                  k7  r8t        j
                  j                  | j                   j                        |_         |S rG   )rY   r   ReleaseTrackGAr   LaunchStageValueidrH   s     r   r   zSetLaunchStageChange.Adjust   sK    D--000.::@@




h Or   NrI   r(   r   r   rW   rW      s     "!r   rW   c                  ,    e Zd ZU dZded<   ded<   d Zy)SetClientNameAndVersionChangezSets the client name and version.

  Attributes:
    client_name: Client name to set.
    client_version: Client version to set.
  rC   client_nameclient_versionc                z    | j                   | j                   |_        | j                  | j                  |_        |S rG   )rb   clientrc   rH   s     r   r   z$SetClientNameAndVersionChange.Adjust   s:    #((ho& $ 3 3hOr   NrI   r(   r   r   ra   ra      s     r   ra   c                  "    e Zd ZU dZded<   d Zy)ServiceAccountChangezRepresents the user intent to change service account for the revision.

  Attributes:
    service_account: The service account to set.
  rC   service_accountc                <    | j                   |j                  _         |S )zCMutates the given config's service account to match what's desired.)rh   r3   rH   s     r   r   zServiceAccountChange.Adjust  s    (,(<(<H%Or   NrI   r(   r   r   rg   rg      s     r   rg   F)initr    c                  6     e Zd ZU dZded<    fdZddZ xZS )ImageChangezjA Cloud Run container deployment.

  Attributes:
    image: The image to set in the adjusted container.
  rC   imagec                R    t        |   di | t        j                  | d|       y )Nrm   r(   super__init__object__setattr__)r*   rm   kwargs	__class__s      r   rq   zImageChange.__init__  s%    	Gv
tWe,r   c                &    | j                   |_         y rG   )rm   r)   s     r   r,   zImageChange.AdjustContainer  s    jjIOr   r9   r:   r;   r<   r=   r>   rq   r,   __classcell__ru   s   @r   rl   rl     s     
*-!r   rl   c                  .    e Zd ZU dZdZded<   d ZddZy)AddDigestToImageChangezAdd image digest that comes from source build.

  Attributes:
    image_digest: The image digest to set in the adjusted container.
  Nr#   image_digestc                
    d|v S )z0Return true if the given image url is by-digest.z@sha256:r(   )r*   urls     r   	_IsDigestz AddDigestToImageChange._IsDigest'  s    r   c                    | j                  |j                        ry | j                  r"|j                  dz   | j                  z   |_        y y )N@)r   rm   r|   r)   s     r   r,   z&AddDigestToImageChange.AdjustContainer+  s>    ~~ioo&!#-0A0AAio r   r9   )r:   r;   r<   r=   r|   r>   r   r,   r(   r   r   r{   r{     s     ",
!Br   r{   c                  X     e Zd ZU dZdZded<   dZded<   dZded<   d	 fd	Zd
dZ	 xZ
S )ResourceLimitsChangea\  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        |   di | t        j                  | d|       t        j                  | d|       t        j                  | d|       y )Nr   r   r   r(   ro   )r*   r   r   r   rt   ru   s        r   rq   zResourceLimitsChange.__init__A  sI    	Gv
tXv.
tUC(
tUC(r   c                   | j                   #| j                   |j                  j                  d<   | j                  #| j                  |j                  j                  d<   | j                  Z| j                  dk(  r'|j                  j                  j                  dd       y| j                  |j                  j                  d<   yy)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,   z$ResourceLimitsChange.AdjustContainerG  s    {{-1[[i  *xx*.((i  'xx	S""&&'7>7;xx	""#34	 r   )NNNr9   )r:   r;   r<   r=   r   r>   r   r   rq   r,   rx   ry   s   @r   r   r   2  s3     &*#z#z)
@r   r   c                z    | j                   j                  D ]"  }|j                  dk(  s|j                  s |c S  y)z7Returns the Cloud SQL volume for the given worker pool.cloudsqlN)r3   r   r0   cloud_sql_instance)r   volumes     r   _GetCloudSQLVolumer   T  s6    !!))f{{j V%>%>m * 
r   c                   | j                  d      }t        |      dk(  r| S t        |      dk(  r8|st        j                  d      |st        j                  d      | d| d|  S t        j                  dj	                  |             )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                B    | D cg c]  }t        |||       c}S c c}w )z[Validates and augments the given Cloud SQL instances with the project and region if needed.)r   )	instancesr   r   r   s       r   _AugmentSQLInstancesr   z  s1     FO
EN(GV4Y
  
s   c                  d    e Zd ZU dZdZded<   dZded<    ej                  e	      Z
ded<   d	 Zy)
AddCloudSQLChangesaA  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           
        t        |      }|{t        j                  dt        j                  t	        | j
                  | j                  | j                                    }|j                  j                  j                  |       |S |j                  j                  j                  t	        | j
                  | j                  | j                               |S Nr   )r   )r0   r   )r   r   VolumeCloudSqlInstancer   r   r   r   r3   r   r5   r   r   extendr*   r   cloud_sql_volumes      r   r   zAddCloudSQLChanges.Adjust  s    )(3 $55,--t||T[[ &&'78 O ))33::
))4<<
 Or   )r:   r;   r<   r=   r   r>   r   dataclassesfieldlistr   r   r(   r   r   r   r     s?     ':&**;+*;*;+- r   r   c                  d    e Zd ZU dZdZded<   dZded<    ej                  e	      Z
ded<   d	 Zy)
RemoveCloudSQLChangesaF  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                   t        |      }|t        t        | j                  | j                  | j
                              }|j                  j                  D cg c]  }||vr|
 c}|j                  _        |j                  j                  sB|j                  j                  D cg c]  }|j                  dk7  r| c}|j                  _	        |S c c}w c c}w Nr   )r   setr   r   r   r   r   r   r3   r   r0   )r*   r   r   instances_to_remover   r   s         r   r   zRemoveCloudSQLChanges.Adjust  s    )(3 #
,,dllDKK +==GG7Gh00 G7))3 00:: #++33%
3{{j( 3%
!
 O7%
s   C'C)r:   r;   r<   r=   r   r>   r   r   r   r   r   r   r(   r   r   r   r     s?     ':&*->[->->.] r   r   c                      e Zd ZdZd Zy)ClearCloudSQLChangesa;  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                    |j                   j                  D cg c]  }|j                  dk7  r| c}|j                   _        |S c c}w r   )r3   r   r0   )r*   r   r   s      r   r   zClearCloudSQLChanges.Adjust  sN    
 ''//!/F;;*$ 	/!H
 O!s   ANr:   r;   r<   r=   r   r(   r   r   r   r     s    r   r   c                  d    e Zd ZU dZdZded<   dZded<    ej                  e	      Z
ded<   d	 Zy)
SetCloudSQLChangesaI  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           
        t        |      }|{t        j                  dt        j                  t	        | j
                  | j                  | j                                    }|j                  j                  j                  |       |S t	        | j
                  | j                  | j                        |j                  _        |S r   )r   r   r   r   r   r   r   r   r3   r   r5   r   r   r   s      r   r   zSetCloudSQLChanges.Adjust  s    )(3 $55,--t||T[[ &&'78 O 7K

%
%t||T[[7))3 Or   )r:   r;   r<   r=   r   r>   r   r   r   r   r   r   r(   r   r   r   r     s?     ':&**;+*;*;+- r   r   ?   c                  "    e Zd ZU dZded<   d Zy)RevisionNameChangezRepresents the user intent to change revision name.

  Attributes:
    revision_suffix: Suffix to append to the revision name.
  rC   revision_suffixc                "   | j                   sd|j                  _        |S t        t	        | j                         z
  dz
  }t        j                  |j                        ^ }}dj                  |d| | j                         |j                  _        |S )zAMutates the given config's revision name to match what's desired.r2   r   z{}-{}N)	r   r3   revision_MAX_RESOURCE_NAME_LENGTHr   r   GetInfoFromFullNamer0   r   )r*   r   max_prefix_length_r0   s        r   r   zRevisionNameChange.Adjust  s    #%h o 	"C(<(<$==A  (;;HMMJHQ!( $"6"6"H Or   NrI   r(   r   r   r   r     s     r   r   c                  ,    e Zd ZU dZded<   ded<   d Zy)
MeshChangea  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.
  rC   r   	mesh_namec                    | j                   rd| j                   v r| j                   nd| j                   d| j                    |j                  j                  _        |S )N/z	projects/z/locations/global/meshes/)r   r   r3   service_meshmeshrH   s     r   r   zMeshChange.Adjust9  sT     ~~!6 	&??OP ""'
 Or   NrI   r(   r   r   r   r   ,  s     ,.r   r   c                  "    e Zd ZU dZded<   d Zy)GpuTypeChangezfSets the gpu-type on the resource template.

  Attributes:
    gpu_type: The gpu_type value to set.
  rC   gpu_typec                    | j                   r'| j                   |j                  j                  _        |S d |j                  j                  _        |S rG   )r   r3   node_selectoracceleratorrH   s     r   r   zGpuTypeChange.AdjustL  sC    }}48MMh%%1 O 59h%%1Or   NrI   r(   r   r   r   r   B  s     -r   r   c                  "    e Zd ZU dZded<   d Zy)GpuZonalRedundancyChangezSets 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                >    | j                    |j                  _        |S rG   )r   r3   gpu_zonal_redundancy_disabledrH   s     r   r   zGpuZonalRedundancyChange.Adjust^  s#    %%% 3 Or   NrI   r(   r   r   r   r   T  s     r   r   c                  6     e Zd ZU dZded<    fdZddZ xZS )ContainerCommandChangezRepresents the user intent to change the 'command' for the container.

  Attributes:
    command: The command to set in the adjusted container.
  rC   commandc                R    t        |   di | t        j                  | d|       y )Nr   r(   ro   )r*   r   rt   ru   s      r   rq   zContainerCommandChange.__init__o  s%    	Gv
tY0r   c                &    | j                   |_         y rG   )r   r)   s     r   r,   z&ContainerCommandChange.AdjustContainers  s    Ir   r9   rw   ry   s   @r   r   r   e  s     ,1%r   r   c                  6     e Zd ZU dZded<    fdZddZ xZS )ContainerArgsChangezRepresents the user intent to change the 'args' for the container.

  Attributes:
    args: The args to set in the adjusted container.
  	list[str]argsc                R    t        |   di | t        j                  | d|       y )Nr   r(   ro   )r*   r   rt   ru   s      r   rq   zContainerArgsChange.__init__  s%    	Gv
tVT*r   c                &    | j                   |_         y rG   )r   r)   s     r   r,   z#ContainerArgsChange.AdjustContainer  s    YYINr   r9   rw   ry   s   @r   r   r   w  s     	/+r   r   c                      e Zd ZU dZ ej
                  e      Zded<    ej
                  e	      Z
ded<   dZded	<   dd
Zy)EnvVarLiteralChangeszRepresents 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                   t        |j                        }| j                  r+|D cg c]   }d|v s|j                  | j                  v r|" }}g }|D ]  }d|v rX|j                  | j                  v r.t        j                  dj                  |j                              |j                  |       _|j                  | j                  v rx|j                  | j                  v rC| j                  |j                     |_
        | j                  j                  |j                         |j                  |        | j                  j                         D ]+  \  }}|j                  t        j                  ||             - ||_        yc c}w )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.)r0   rE   N)r   envr   r0   r   r   ConfigurationErrorr   r5   r   rE   r   itemsr   EnvVar)r*   r+   current_env_varsenv_varupdated_env_varsenv_var_nameenv_var_values          r   r,   z$EnvVarLiteralChanges.AdjustContainer  sc     IMM* *)gw&',,$,,*F )   #	7	"<<4<<'--HHN,,I  	(		% 
	%W\\2&g&- $2 (,||'9'9';#m
..l-
@ (< %IMIs   %FNr9   )r:   r;   r<   r=   r   r   dictr   r>   r   r   r   r,   r(   r   r   r   r     sF     .K--dC'>C({((>'9>,7%r   r   c                      e Zd ZU dZ ej
                  e      Zded<    ej
                  e	      Z
ded<   dZded	<   dd
ZddZy)SecretsEnvVarChangeszRepresents 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                P   |j                  d      }t        |      dk(  r%t        j                  dj	                  |            t        |      dk(  r|\  }}n$t        j                  dj	                  |            t        j                  t        j                  ||            S )	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   _BuildSecretEnvVarSourcez-SecretsEnvVarChanges._BuildSecretEnvVarSource  s    LLE
5zQ))AAG BH B  
Uq$)!k>))
/
6
6v
>  00"
 r   c           	     T   t        |j                        }| j                  r+|D cg c]   }d|vs|j                  | j                  v r|" }}g }|D ]  }d|vrX|j                  | j                  v r.t        j                  dj                  |j                              |j                  |       _|j                  | j                  v rx|j                  | j                  v rR| j                  | j                  |j                           |_        | j                  j                  |j                         |j                  |        | j                  j                         D ]:  \  }}|j                  t        j                  || j                  |                   < ||_        yc c}w )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.)r0   r   N)r   r   r   r0   r   r   r   r   r5   r   r  r   r   r   r   r   )r*   r+   r   r   r   r   r   s          r   r,   z$SecretsEnvVarChanges.AdjustContainer  s     IMM* *)g7*glldll.J )   #	w	&<<4<<'--HHN,,I  	(		% 
	%#<<LL& 
 	&g&1 $6 !% 2 2 4f
..88@ !5 %IMSs   %F%N)r   rC   returnzk8s_min.EnvVarSourcer9   )r:   r;   r<   r=   r   r   r   r   r>   r   r   r   r  r,   r(   r   r   r   r     sK     .K--dC'>C({((>'9>,.<%r   r   c                  "    e Zd ZU dZded<   d Zy)DescriptionChangezuRepresents the user intent to change resource description.

  Attributes:
    description: The description to set.
  rC   descriptionc                (    | j                   |_         |S )zAMutates the given resource's description to match what's desired.)r  rH   s     r   r   zDescriptionChange.Adjust?  s    ++HOr   NrI   r(   r   r   r
  r
  5  s     r   r
  c                  B    e Zd ZU dZdZded<   dZded<   dZded<   d	 Zy)
BinaryAuthorizationChangezRepresents 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                   | j                   r5d|j                  _        d|j                  _        d|j                  _        |S | j                  dk(  rd|j                  _        n8| j                  r,d|j                  _        | j                  |j                  _        | j                  r| j                  |j                  _        |S )z<Mutates the given resource's policy to match what's desired.Fr2   defaultT)r  binary_authorizationuse_defaultr  r  rH   s     r   r   z BinaryAuthorizationChange.AdjustS  s     &&27h##/-/h##*?Ah##<o{{i26h##/	27h##/-1[[h##*$$

'
' ##< Or   )	r:   r;   r<   r=   r  r>   r  r  r   r(   r   r   r  r  E  s.     &*)-J-%*d*r   r  c                      e Zd ZU dZ ej
                  e      Zded<    ej
                  e	      Z
ded<   dZded	<   ed
        Zd Zy)LabelChangeaG  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                     y)NTr(   )r*   s    r   adjusts_templatezLabelChange.adjusts_templatey  s    r   c                .   | j                   r| j                  rt        d      | j                  r>|j                  j	                          |j
                  j                  j	                          |j                  j                  | j                         |j
                  j                  j                  | j                         | j                   D ]D  }|j                  j                  |d        |j
                  j                  j                  |d        F |S )NzCCannot specify both subtractions and clear_labels at the same time.)	r  r  
ValueErrorlabelsclearr3   updater  r   )r*   r   	label_keys      r   r   zLabelChange.Adjust}  s    T..
O  oo$$&OO4>>*##DNN3&&	oo)T*""9d3 ' Or   N)r:   r;   r<   r=   r   r   r   r  r>   r   r  r  propertyr  r   r(   r   r   r  r  h  sX    	 0k//E)^E-K--dC,	C, r   r  c                      e Zd ZU dZdZded<   dZded<   dZded<    ej                  e
      Zded	<   d
Zded<   d
Zded<   d Zy)VpcAccessChangesa  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                   | j                   rZd |j                  j                  _        t        j
                  j                  j                  |j                  j                  _        |S |j                  j                  j                  sK|j                  j                  j                  j                  t        j
                  j                                |j                  j                  j                  d   }| j                  r| j                  |_        | j                  r| j                  |_        | j                  r| j                  |_        | j                   rg |_        | j"                  dk(  s| j"                  dk(  r?t        j
                  j                  j$                  |j                  j                  _        |S | j"                  dk(  r=t        j
                  j                  j&                  |j                  j                  _        |S )Nr   allzall-trafficzprivate-ranges-only)r*  r3   
vpc_accessnetwork_interfacesr   	VpcAccess	VpcEgressVPC_EGRESS_UNSPECIFIEDegressr5   NetworkInterfacer'  r(  
subnetworkr)  tagsr+  r&  ALL_TRAFFICPRIVATE_RANGES_ONLY)r*   r   network_interfaces      r   r   z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=   r&  r>   r'  r(  r   r   r   r)  r*  r+  r   r(   r   r   r%  r%    sX    	  *j':&*-K--dC,	C-"d"r   r%  c                  l    e Zd ZU dZdZded<   dZded<   dZded<   dZd	ed
<   dZ	d	ed<   dZ
d	ed<   d Zy)CmekKeyChangesa  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#   rD   post_key_revocation_action_typez
int | Noneencryption_key_shutdown_hoursFr%   	clear_key%clear_post_key_revocation_action_type#clear_encryption_key_shutdown_hoursc                    | j                   | j                   |j                  _        | j                  rR| j                  dk(  rt        j
                  j                  nt        j
                  j                  |j                  _        | j                  2t        j                  | j                  dz        |j                  _        | j                  rKd |j                  _        t        j
                  j                  |j                  _        d |j                  _        | j                  r:t        j
                  j                  |j                  _        d |j                  _        | j                   rd |j                  _        |S )Nzprevent-newi  )seconds)rD   r3   encryption_keyr<  r   EncryptionKeyRevocationActionPREVENT_NEWSHUTDOWN encryption_key_revocation_actionr=  r   Duration encryption_key_shutdown_durationr>  ,ENCRYPTION_KEY_REVOCATION_ACTION_UNSPECIFIEDr?  r@  rH   s     r   r   z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=   rD   r>   r<  r=  r>  r?  r@  r   r(   r   r   r;  r;    sN     #z04!:4.22)T05'5.3%t3!r   r;  c                  ,    e Zd ZU dZded<   ded<   d Zy)RemoveVolumeChangezxRemoves volumes from the service/job/worker-pool template.

  Attributes:
    removed_volumes: The volumes to remove.
  Iterable[str]removed_volumesr%   clear_volumesc                j   | j                   r&|j                  j                  j                          |S | j                  ro|j                  j                  D ci c]  }|j
                  | }}| j                  D ]
  }||v s||=  t        |j                               |j                  _        |S c c}w rG   )rO  r3   r   r   rN  r0   r   values)r*   r   r   current_volumes	to_removes        r   r   zRemoveVolumeChange.Adjust  s    %%' O 
		,4,=,=,E,E,E&&++v
,E   ++)'i( , #''='='?"@hOs   B0NrI   r(   r   r   rL  rL    s     ! r   rL  c                  X    e Zd ZU dZded<   ej                  j                  Zded<   d Z	y)AddVolumeChangezUpdates 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_volumesrX   release_trackc                <   |j                   j                  D ci c]  }|j                  | }}| j                  D ]1  }t	        j
                  || j                        }|||j                  <   3 t        |j                               |j                   _        |S c c}w rG   )	r3   r   r0   rV  volumes_libcreate_volume_v2rW  r   rQ  )r*   r   r   rR  
new_volumes        r   r   zAddVolumeChange.Adjust)  s     +3*;*;*C*C*CV*C   ""//8J8JKj)3ojoo& # !%_%;%;%= >HOs   BN)
r:   r;   r<   r=   r>   r   r[   ALPHArW  r   r(   r   r   rU  rU    s+     0/%)%6%6%<%<-"<	r   rU  c                  V    e Zd ZU dZ ej
                  e      Zded<   dZ	ded<   d Z
y	)
RemoveVolumeMountChangezRemoves 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   rM  removed_mountsFr%   clear_mountsc                    | j                   r|j                  j                          |S t        | j                        }|j                  D cg c]  }|j
                  |vr| c}|_        |S c c}w rG   )r`  volume_mountsr   r   r_  
mount_path)r*   r+   r_  volume_mounts       r   r,   z'RemoveVolumeMountChange.AdjustContainerA  sz    ##%  4../n (55!5l$$N: 5!i
 !s   A-N)r:   r;   r<   r=   r   r   r   r_  r>   r`  r,   r(   r   r   r^  r^  5  s/     #4+"3"3D"I.-I,
r   r^  VolumeMountDict)r   
mount-pathc                  J    e Zd ZU dZ ej
                  e      Zded<   ddZ	y)AddVolumeMountChangezvUpdates Volume Mounts set on the container.

  Attributes:
    new_mounts: Mounts to add to the adjusted container.
  r   zIterable[VolumeMountDict]
new_mountsc                6   |j                   D ci c]  }|j                  | }}| j                  D ]B  }d|vsd|vrt        j                  d      t        j                  |d   |d         ||d   <   D t        |j                               |_         |S c c}w )Nr   rf  z<Added Volume mounts must have a `volume` and a `mount-path`.)r0   rc  )	rb  rc  ri  r   r   r   VolumeMountr   rQ  )r*   r+   rd  current_mountsmounts        r   r,   z$AddVolumeMountChange.AdjustContainerc  s     &333L 	-3   		,e";++J
 	
 -4,?,?X5+>-nU<() ! #>#8#8#:;Is   BNr9   )
r:   r;   r<   r=   r   r   r   ri  r>   r,   r(   r   r   rh  rh  W  s+     +<+*;*;+*' r   rh  c                  "    e Zd ZU dZded<   d Zy)RemoveContainersChangezcRemoves the specified containers.

  Attributes:
    containers_to_remove: Containers to remove.
  rM  containers_to_removec                    t        | j                        }|j                  j                  D cg c]  }|j                  |vr| c}|j                  _        |S c c}w rG   )r   rp  r3   r4   r0   )r*   r   rp  r+   s       r   r   zRemoveContainersChange.Adjust~  s`    t889 "**55$5I>>!55 	5$H 
 O$s   ANrI   r(   r   r   ro  ro  t  s     &%r   ro  c                  H    e Zd ZU dZ ej
                  e      Zded<   d Z	y)ContainerDependenciesChangeaF  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           
        t        |j                  j                  D cg c]  }|j                   c}      }|j                  j                  D ci c],  }|j                  |j                  D cg c]	  }||v s| c}. }}}| j
                  j                         D ]V  \  }}t        |      }||z
  x}r+t        j                  d| ddj                  |       d      |rt        |      ||<   T||= X |j                  j                  D ]#  }|j                  |j                  g       |_        % |S c c}w c c}w c c}}w )zUpdates container dependencies.z--depends_on for container z$ references nonexistent containers: ,.)r   r3   r4   r0   
depends_onrt  r   	frozensetr   r   joinsortedget)	r*   r   r+   current_containersr8   current_dependenciesr$   rx  missings	            r   r   z"ContainerDependenciesChange.Adjust  sg   )1):):)E)EF)EI)EF "**55	 6I 	 ++
+!q4F/FA+
 	
 6	   '+&;&;&A&A&C"
Z(j!33	3	3++).)9 :((+(9':!=
 	
 
/5j/A^, 0 'D &&11	155innbIi 2O/ 	G
s#   D6E /	D;9D;=E ;E N)
r:   r;   r<   r=   r   r   r   rt  r>   r   r(   r   r   rs  rs    s-    	 3D+2C2C3/ r   rs  c                  D    e Zd ZU dZdZded<   dZded<   dZded<   d	dZy)
WorkerPoolScalingChangea0  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                   |j                   j                  }| j                  s| j                  rH| j                   s<|t        j
                  j                  j                  k(  rt        j                  d      | j                  r| j                   r+| j                   j                  st        j                  d      | j                  j                  rd|j                   _        n%| j                  j                  |j                   _        | j                  r| j                   r+| j                   j                  st        j                  d      | j                  j                  rd|j                   _        n%| j                  j                  |j                   _        | j                   r| j                   j                  rFd|j                   _        t        j
                  j                  j                  |j                   _        |S d|j                   _        d|j                   _        t        j
                  j                  j                  |j                   _        | j                   j                  |j                   _        |S )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   z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  worker_pool_objects.WorkerPool)	r:   r;   r<   r=   r  r>   r  r  r   r(   r   r   r  r    s2     15-404-4'+'$+G r   r  c                      e Zd ZdZddZy)NoPromoteChangezRRepresents the user intent to block instance assignment for a new worker revision.c                    |j                   st        j                  d      t        j                  |j
                        }t        j                  t        |j                        |      |_	        |S )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   zNoPromoteChange.Adjust  sl    ))
G  	!99**	
 
  2FFX%%&(B H Or   Nr   r  r   r(   r   r   r  r    s
    Zr   r  c                  X    e Zd ZU dZdZded<    ej                  e      Z	ded<   d
dZ
y	)InstanceSplitChangezRepresents 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                n   | j                   rd|j                  j                          |j                  j                  t	        j
                  t        j                  j                  d             |S | j                  r8t        j                  t        |j                        | j                        |_        |S )Nr  )typepercent)r  r  r   r5   r   InstanceSplitInstanceSplitAllocationType%INSTANCE_SPLIT_ALLOCATION_TYPE_LATESTr  r  GetUpdatedSplitsr   rH   s     r   r   zInstanceSplitChange.Adjust4  s    ~~$$&%%

&
&!==cc O	 
		!3!D!D
x''
($*;*;"h Or   Nr  )r:   r;   r<   r=   r  r>   r   r   r   r  r   r(   r   r   r  r  (  s/     )T!2!2!24!H,Hr   r  )r   rC   r   r#   r   r#   r  rC   )r   r   r   r#   r   r#   r  r   )Tr=   
__future__r   r   r   r   r   r?   collections.abcr   r	   r
   r   typingr   cloudsdk.google.protobufr   
google.apir   googlecloudsdk.callioper   googlecloudsdk.command_lib.runr   r   r   r   r   rY  !googlecloudsdk.command_lib.run.v2r   r  ;googlecloudsdk.generated_clients.gapic_clients.run_v2.typesr   r   r   worker_pool_objectsr   	dataclassTemplateConfigChangerr"   NonTemplateConfigChangerrB   rL   rQ   rT   rW   ra   rg   rl   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r  ConfigChangerr  r%  r;  rL  rU  r^  rC   re  rh  ro  rs  r  r  r  r(   r   r   <module>r     sl   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   