
    >                        S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJrJ	r	  SSK
Jr   \R                  r\R                  S-   rS	rS
rSrSrSrSrSrSrSrSrSrSrSrSrSr " S S\R@                  5      r! " S S\"5      r# " S S\RH                  5      r% " S S\RL                  5      r' " S  S!\RL                  5      r( " S" S#\RL                  5      r) " S$ S%\RT                  5      r+g! \ a    \r Nf = f)&zCWraps a resource message with a container with convenience methods.    )absolute_import)division)unicode_literalsN)MappingSequence)
k8s_objectz/cloudsql-instancesz'run.googleapis.com/vpc-access-connectorz(run.googleapis.com/execution-environmentz!run.googleapis.com/encryption-keyz2run.googleapis.com/post-key-revocation-action-typez0run.googleapis.com/encryption-key-shutdown-hourszrun.googleapis.com/secretsz!run.googleapis.com/cpu-throttlingz$run.googleapis.com/startup-cpu-boostz(run.googleapis.com/health-check-disabledz'run.googleapis.com/invoker-iam-disabledz'run.googleapis.com/default-url-disabledz$run.googleapis.com/vpc-access-egressallzall-trafficzprivate-ranges-onlyc                      \ rS rSrSr\S 5       r\S 5       r\R                  S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S\\\\   4   4S j5       r\R                  S\\\\   4   4S j5       rSrg)ContainerResource8   a  Wraps a resource message with a container, making fields more convenient.

Provides convience fields for Cloud Run resources that contain a container.
These resources also typically have other overlapping fields such as volumes
which are also handled by this wrapper.
c                 .    U R                   R                  $ zReturns a mutable, dict-like object to manage env vars.

The returned object can be used like a dictionary, and any modifications to
the returned object (i.e. setting and deleting keys) modify the underlying
nested env vars fields.
)	containerenv_varsselfs    4lib/googlecloudsdk/api_lib/run/container_resource.pyr   ContainerResource.env_vars@   s     >>"""    c                 .    U R                   R                  $ )zURL to container.r   imager   s    r   r   ContainerResource.imageJ   s     >>r   c                 $    XR                   l        g Nr   )r   values     r   r   r   O   s     NNr   c                 .    U R                   R                  $ )z#command to be invoked by container.)r   commandr   s    r   r   ContainerResource.commandS   s     >>!!!r   c                 0   U R                   R                  5       nU(       d  U R                   S   $ [        U5      S:X  a  [        [	        U5      5      $ U R
                  S:X  a  [        S5      eU H  nUR                  (       d  M  Us  $    [        S5      e)z&The container in the revisionTemplate.    TaskTemplateSpecz_the target job has multiple containers, a container name must be specified via --container flagzmissing ingress container)
containersvalueslennextiterKIND
ValueErrorports)r   r$   r   s      r   r   ContainerResource.containerX   s     '')J__R  
:!$z"##yy&&, 
  		   0
11r   c                 l    [        U R                  R                  U R                  U R                  5      $ )z'The containers in the revisionTemplate.)ContainersAsDictionaryWrapperspecr$   volumes	_messagesr   s    r   r$   ContainerResource.containersn   s*     )		dllDNN r   c                 .    U R                   R                  $ )<The resource limits as a dictionary { resource name: limit}.)r   resource_limitsr   s    r   r5   !ContainerResource.resource_limitsu   s     >>)))r   c                 j    [        U R                  R                  U R                  R                  5      $ )aQ  Returns a dict-like object to manage volumes.

There are additional properties on the object (e.g. `.secrets`) that can
be used to access a mutable, dict-like object for managing volumes of a
given type. Any modifications to the returned object for these properties
(i.e. setting and deleting keys) modify the underlying nested volumes.
)VolumesAsDictionaryWrapperr/   r0   r1   Volumer   s    r   r0   ContainerResource.volumesz   s%     &dii&7&79N9NOOr   returnc                     0 n[         R                  U R                  ;   a1  [        R                  " U R                  [         R                     5      nU$ )al  Returns a dictionary of container dependencies.

Container dependencies are stored in the
'run.googleapis.com/container-dependencies' annotation. The returned
dictionary maps containers to a list of their dependencies by name. Note
that updates to the returned dictionary do not update the resource's
container dependencies unless the dependencies setter is used.
)r   !CONTAINER_DEPENDENCIES_ANNOTATIONannotationsjsonloads)r   dependenciess     r   rA   ContainerResource.dependencies   sG     L33t7G7GGZZ


:GG
Hl r   rA   c           
      P   U(       a_  [         R                  " UR                  5        VVs0 s H  u  p#U[        U5      _M     snn5      U R                  [
        R                  '   g[
        R                  U R                  ;   a  U R                  [
        R                  	 ggs  snnf )a;  Sets the resource's container dependencies.

Args:
  dependencies: A dictionary mapping containers to a list of their
    dependencies by name.

Container dependencies are stored in the
'run.googleapis.com/container-dependencies' annotation as json. Setting an
empty set of dependencies will clear this annotation.
N)r?   dumpsitemslistr>   r   r=   )r   rA   kvs       r   rA   rB      s     
**\-?-?-AB-ATQaaj-AB
C zCCD 
	5	59I9I	I


:GG
H 
J Cs   B"
 N)__name__
__module____qualname____firstlineno____doc__propertyr   r   setterr   r   r$   r5   r0   r   strr   rA   __static_attributes__rI   r   r   r   r   8   s    # #     	<<! ! " " 2 2*   * * P P GC#$67    IwsHSM/A'B I Ir   r   c                   ~    \ rS rSrSrSS jr\S 5       r\S 5       rS r	\S 5       r
S	 rS
 rS rSS jrSS jrSrg)	Container   zWraps a container message with dict-like wrappers for env_vars, volume_mounts, and resource_limits.

All other properties are delegated to the underlying container message.
Nc                     U(       d  UR                   " S0 UD6n[        R                  U SU5        [        R                  U SU5        [        R                  U SU5        g )N_volumesr1   _mrI   )rT   object__setattr__)r   r0   messages_modr   kwargss        r   __init__Container.__init__   sN    ((262i
tZ1
t[,7
tT9-r   c                 j    [        U R                  R                  U R                  R                  5      $ r   )EnvVarsAsDictionaryWrapperrX   envr1   EnvVarr   s    r   r   Container.env_vars   s#     &dggkk4>>3H3HIIr   c                     [        U R                  U R                  R                  U R                  R
                  5      $ )a  Returns a mutable, dict-like object to manage volume mounts.

The returned object can be used like a dictionary, and any modifications to
the returned object (i.e. setting and deleting keys) modify the underlying
nested volume mounts. There are additional properties on the object
(e.g. `.secrets` that can be used to access a mutable dict-like object for
a volume mounts that mount volumes of a given type.
)VolumeMountsAsDictionaryWrapperrW   rX   volumeMountsr1   VolumeMountr   s    r   volume_mountsContainer.volume_mounts   s0     +tww++T^^-G-G r   c                 8   U R                   R                  R                  nU R                  b>  U R                  R                  c&  [
        R                  " U5      U R                  l        g g [
        R                  " U R                   R                  5      U l        g r   )r1   ResourceRequirementsLimitsValue	resourceslimitsr   InitializedInstance)r   
limits_clss     r   _EnsureResourcesContainer._EnsureResources   sn    44@@J~~!				& * > >z J 
' "55
..
-
-dnr   c                     U R                  5         [        R                  " U R                  R                  R
                  U R                  R                  R                  R                  SSS9$ )r4   keyr   	key_fieldvalue_field)
rq   r   KeyValueListAsDictionaryWrapperrm   rn   additionalPropertiesr1   rk   rl   AdditionalPropertyr   s    r   r5   Container.resource_limits   sU     	5522++77JJ	 r   c                     U R                   $ r   )rX   r   s    r   MakeSerializableContainer.MakeSerializable   s    77Nr   c                 .    [        U R                  U5      $ r   )getattrrX   )r   names     r   __getattr__Container.__getattr__   s    477D!!r   c                 0    [        U R                  X5        g r   )setattrrX   )r   r   r   s      r   rZ   Container.__setattr__   s    DGGT!r   c                     U R                   nU R                  nU(       a  [        X!5      n[        X15      nUR                  5        VVs0 s H  u  pEXBR	                  U5      _M     snn$ s  snnf r   rW   rh   r   rE   getr   subgroupvolsmountspathvols         r   MountedVolumeJoinContainer.MountedVolumeJoin   sX    ==DFT$dv(f17@IDD((3-@@@s   	A*c           	          U R                   nU R                  nU(       a  [        X!5      n[        X15      nUR                  5        VVs0 s H  u  pEXEUR	                  U5      4_M     snn$ s  snnf r   r   r   s         r   NamedMountedVolumeJoin Container.NamedMountedVolumeJoin   s]    ==DFT$dv(f8>G94D&&GGGs   	A,)rm   r   )rJ   rK   rL   rM   rN   r]   rO   r   rh   rq   r5   r}   r   rZ   r   r   rR   rI   r   r   rT   rT      sj    
. J J    ""AHr   rT   c                   P   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rS
rU =r$ )ContainerSequenceWrapper   zRWraps a list of containers wrapping each element with the Container wrapper class.c                 N   > [         [        U ]  5         Xl        X l        X0l        g r   )superr   r]   _containersrW   r1   r   containers_to_wrapr0   r[   	__class__s       r   r]   !ContainerSequenceWrapper.__init__  s!    	
"D24)M!Nr   c                 ^    [        U R                  U R                  U R                  U   5      $ r   )rT   rW   r1   r   r   indexs     r   __getitem__$ContainerSequenceWrapper.__getitem__  s$    T]]DNND4D4DU4KLLr   c                 ,    [        U R                  5      $ r   )r&   r   r   s    r   __len__ ContainerSequenceWrapper.__len__
  s    t  r   c                 >    UR                  5       U R                  U'   g r   )r}   r   )r   r   r   s      r   __setitem__$ContainerSequenceWrapper.__setitem__  s    '88:DUr   c                     U R                   U	 g r   r   r   s     r   __delitem__$ContainerSequenceWrapper.__delitem__  s    r   c                 V    U R                   R                  XR                  5       5        g r   )r   insertr}   )r   r   r   s      r   r   ContainerSequenceWrapper.insert  s    E#9#9#;<r   c                     U R                   $ r   r   r   s    r   r}   )ContainerSequenceWrapper.MakeSerializable  s    r   )r   r1   rW   )rJ   rK   rL   rM   rN   r]   r   r   r   r   r   r}   rR   __classcell__r   s   @r   r   r      s/    Z"M!; = r   r   c                   D   ^  \ rS rSrSrU 4S jrU 4S jrU 4S jrSrU =r	$ )r.   i  zWraps a list of containers in a mutable dict-like object mapping containers by name.

Accessing a container name that does not exist will automatically add a new
container with the specified name to the underlying list.
c                 X   > X l         X0l        [        [        U ]  [        XU5      5        g)a  Wraps a list of containers in a mutable dict-like object.

Args:
  containers_to_wrap: list[Container], list of containers to treat as a
    dict.
  volumes: the volumes defined in the containing resource used to classify
    volume mounts
  messages_mod: the messages module
N)rW   r1   r   r.   r]   r   r   s       r   r]   &ContainersAsDictionaryWrapper.__init__!  s*     M!N	
'7 !3lKr   c                    >  [         [        U ]  U5      $ ! [         a?    [	        U R
                  U R                  US9nU R                  R                  U5        Us $ f = f)N)r   )	r   r.   r   KeyErrorrT   rW   r1   rX   append)r   rt   r   r   s      r   r   )ContainersAsDictionaryWrapper.__getitem__1  sV    0$CCHH DMM4>>Di
ggnnYs    AAAc                 D   > [         [        U ]  5       R                  5       $ r   )r   r.   r}   )r   r   s    r   r}   .ContainersAsDictionaryWrapper.MakeSerializable9  s!    +T 					r   )r1   rW   )
rJ   rK   rL   rM   rN   r]   r   r}   rR   r   r   s   @r   r.   r.     s      r   r.   c                   \   ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r\S 5       r	Sr
U =r$ )r`   iA  zWraps a list of env vars in a dict-like object.

Additionally provides properties to access env vars of specific type in a
mutable dict-like object.
c                 D   > [         [        U ]  U5        Xl        X l        g)zWraps a list of env vars in a dict-like object.

Args:
  env_vars_to_wrap: list[EnvVar], list of env vars to treat as a dict.
  env_var_class: type of the underlying EnvVar objects.
N)r   r`   r]   	_env_vars_env_var_class)r   env_vars_to_wrapenv_var_classr   s      r   r]   #EnvVarsAsDictionaryWrapper.__init__H  s!     

$d45EF%N'r   c                 X    [         R                  " U R                  U R                  S S9$ )zMutable dict-like object for env vars with a string literal.

Note that if neither value nor valueFrom is specified, the list entry will
be treated as a literal empty string.

Returns:
  A mutable, dict-like object for managing string literal env vars.
c                     U R                   S L $ r   )	valueFromenv_vars    r   <lambda>5EnvVarsAsDictionaryWrapper.literals.<locals>.<lambda>`  s    G$5$5$=r   )filter_funcr   rx   r   r   r   s    r   literals#EnvVarsAsDictionaryWrapper.literalsS  s*     55= r   c                 ^    S n[         R                  " U R                  U R                  SUS9$ )z<Mutable dict-like object for vars with a secret source type.c                 \    U R                   S L=(       a    U R                   R                  S L$ r   )r   secretKeyRefr   s    r   _FilterSecretEnvVars@EnvVarsAsDictionaryWrapper.secrets.<locals>._FilterSecretEnvVarsg  s.    


4
' 9,,D8r   r   rw   r   r   )r   r   s     r   secrets"EnvVarsAsDictionaryWrapper.secretsc  s2     55(	 r   c                 ^    S n[         R                  " U R                  U R                  SUS9$ )z@Mutable dict-like object for vars with a config map source type.c                 \    U R                   S L=(       a    U R                   R                  S L$ r   )r   configMapKeyRefr   s    r   _FilterConfigMapEnvVarsGEnvVarsAsDictionaryWrapper.config_maps.<locals>._FilterConfigMapEnvVarsx  s.    


4
' <//t;r   r   r   r   )r   r   s     r   config_maps&EnvVarsAsDictionaryWrapper.config_mapst  s2     55+	 r   )r   r   )rJ   rK   rL   rM   rN   r]   rO   r   r   r   rR   r   r   s   @r   r`   r`   A  sI    	(       r   r`   c                   L   ^  \ rS rSrSrU 4S jr\S 5       r\S 5       rSr	U =r
$ )r8   i  zWraps a list of volumes in a dict-like object.

Additionally provides properties to access volumes of specific type in a
mutable dict-like object.
c                 D   > [         [        U ]  U5        Xl        X l        g)zWraps a list of volumes in a dict-like object.

Args:
  volumes_to_wrap: list[Volume], list of volumes to treat as a dict.
  volume_class: type of the underlying Volume objects.
N)r   r8   r]   rW   _volume_class)r   volumes_to_wrapvolume_classr   s      r   r]   #VolumesAsDictionaryWrapper.__init__  s      

$d4_E#M%r   c                 Z    [         R                  " U R                  U R                  SS S9$ )z?Mutable dict-like object for volumes with a secret source type.secretc                     U R                   S L$ r   )r   volumes    r   r   4VolumesAsDictionaryWrapper.secrets.<locals>.<lambda>  s    6==#<r   r   r   rx   rW   r   r   s    r   r   "VolumesAsDictionaryWrapper.secrets  s-     55<	 r   c                 Z    [         R                  " U R                  U R                  SS S9$ )zCMutable dict-like object for volumes with a config map source type.	configMapc                     U R                   S L$ r   )r   r   s    r   r   8VolumesAsDictionaryWrapper.config_maps.<locals>.<lambda>  s    6#3#34#?r   r   r   r   s    r   r   &VolumesAsDictionaryWrapper.config_maps  s-     55?	 r   )r   rW   rJ   rK   rL   rM   rN   r]   rO   r   r   rR   r   r   s   @r   r8   r8     s5    	&    r   r8   c                   L   ^  \ rS rSrSrU 4S jr\S 5       r\S 5       rSr	U =r
$ )re   i  zWraps a list of volume mounts in a mutable dict-like object.

Additionally provides properties to access mounts that are mounting volumes
of specific type in a mutable dict-like object.
c                 :   > [         [        U ]  UUSSS9  Xl        g)zWraps a list of volume mounts in a mutable dict-like object.

Args:
  volumes: associated VolumesAsDictionaryWrapper obj
  mounts_to_wrap: list[VolumeMount], list of mounts to treat as a dict.
  mount_class: type of the underlying VolumeMount objects.
	mountPathr   ru   N)r   re   r]   rW   )r   r0   mounts_to_wrapmount_classr   s       r   r]   (VolumeMountsAsDictionaryWrapper.__init__  s-     

)49	 :  Mr   c                    ^  [         R                  " T R                  T R                  T R                  T R
                  U 4S jS9$ )zLMutable dict-like object for mounts whose volumes have a secret source type.c                 J   > U R                   TR                  R                  ;   $ r   )r   rW   r   mountr   s    r   r   9VolumeMountsAsDictionaryWrapper.secrets.<locals>.<lambda>  s    %**0E0E"Er   rv   rw   r   r   rx   rX   _item_class
_key_field_value_fieldr   s   `r   r   'VolumeMountsAsDictionaryWrapper.secrets  s;     55//%%E r   c                    ^  [         R                  " T R                  T R                  T R                  T R
                  U 4S jS9$ )zPMutable dict-like object for mounts whose volumes have a config map source type.c                 J   > U R                   TR                  R                  ;   $ r   )r   rW   r   r   s    r   r   =VolumeMountsAsDictionaryWrapper.config_maps.<locals>.<lambda>  s    %**0I0I"Ir   r   r   r   s   `r   r   +VolumeMountsAsDictionaryWrapper.config_maps  s;     55//%%I r   )rW   r   r   s   @r   re   re     s5         r   re   ),rN   
__future__r   r   r   collectionsr?   typingr   r   googlecloudsdk.api_lib.runr   abccollections_abcAttributeError	RUN_GROUPCLOUDSQL_ANNOTATIONVPC_ACCESS_ANNOTATIONSANDBOX_ANNOTATIONCMEK_KEY_ANNOTATION/POST_CMEK_KEY_REVOCATION_ACTION_TYPE_ANNOTATION(ENCRYPTION_KEY_SHUTDOWN_HOURS_ANNOTATIONSECRETS_ANNOTATIONCPU_THROTTLE_ANNOTATIONCOLD_START_BOOST_ANNOTATIONDISABLE_HEALTH_CHECK_ANNOTATIONDISABLE_IAM_ANNOTATIONDISABLE_URL_ANNOTATIONEGRESS_SETTINGS_ANNOTATIONEGRESS_SETTINGS_ALLEGRESS_SETTINGS_ALL_TRAFFIC#EGRESS_SETTINGS_PRIVATE_RANGES_ONLYKubernetesObjectr   rY   rT   MutableSequencer   ListAsDictionaryWrapperr.   r`   r8   rx   re   rI   r   r   <module>r#     sC   J &  '   $ 1 OO/ !**-BB A ? 9 8 0 7 ) 2 = D "L B B C  + &; #oI
33 oIdQH QHh>> 8$J$F$F $NB!C!C BJ$!C!C $N-..-_   / s   C/ /C:9C: