
    ,`                        S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r
  0 r\" S\\\\\\\\\\\\S.S	S
9rS rS rS r\R"                  R$                  4S\S\R"                  4S jjrS r " S S\R*                  5      r\ " S S\5      5       r\ " S S\5      5       r\ " S S\5      5       r\ " S S\5      5       r\ " S S\5      5       r\ " S S\5      5       rS  rS! rg)"z#Utilities for working with volumes.    N)	TypedDict)arg_parsers)base)
exceptions
VolumeDict)nametypez	read-onlybucketlocation
size-limitdynamic-mountingmount-optionssecretversionpath	instancesF)totalc                  Z     SSK Jn   U $ ! [         a    [        R                  " 5       ef = f)aA  Imports types from the v2 gapic client, handling potential gRPC import errors.

Not all gCloud distributions have the gRPC library. Since only
workerpools use the gapic client (which requires gRPC), we import it here
so only workerpool commands are affected if gRPC is not installed.

Returns:
  The run_v2 types module.
r   types)5googlecloudsdk.generated_clients.gapic_clients.run_v2r   ImportErrorserverless_exceptionsNoGrpcInstalledErrorr   s    -lib/googlecloudsdk/command_lib/run/volumes.pyimport_gapic_client_typesr   /   s-    7KL	 7

4
4
667s   
  *c                 4    U [         U R                  5       '   U $ )zdecorator for registering VolumeTypes.

Only VolumeTypes with this decorator will be supported in add_volume

Args:
  cls: the decorated class

Returns:
  cls
)_supported_volume_typesr   clss    r   _registered_volume_typer!   B   s     ),#((*%	*    c                     [        X5        UR                  U S   S9n[        U S      nUR                  X5        UR	                  X5        UR                  XU5        XAU S   '   g)zBAdd the volume described by the given volume dict to the resource.r   )r   r	   N)_validate_volume_name_and_typeVolumer   validate_volume_addvalidate_fieldsfill_volume)volumevolumesmessagesrelease_tracknew_volvol_types         r   
add_volumer/   Q   sd     7OOO0'$VF^4(
v5
61
v1#&.r"   r)   r,   c                     [        5       n[        X5        [        U S      nUR                  X5        UR	                  X5        UR                  X5      $ )zECreate the volume described by the given volume dict to the resource.r	   )r   r$   r   r&   r'   create_volume_v2)r)   r,   r   r.   s       r   r1   r1   ]   sO    
 $
%% 7$VF^4(
v5
61		"	"6	11r"   c                     / n[        [        R                  5       S S9 H:  u  p#XR                  5       ;   d  M  UR	                  UR                  U 5      5        M<     SR                  U5      $ )z8Generates the help text for all registered volume types.c                     U S   $ )Nr    )ts    r   <lambda>volume_help.<locals>.<lambda>o   s    QqTr"   )keyz

)sortedr   itemsrelease_tracksappendgenerate_helpjoin)r,   hlp_volume_types       r   volume_helprB   k   s_    
###%>na 2244	jj**=9:	 
S	r"   c                      \ rS rSrSr\\R                  S 5       5       r\\R                  S 5       5       r	\S 5       r
\\R                  S 5       5       r\\R                  S 5       5       r\\R                  S 5       5       r\\R                  S	 5       5       r\\R                  S
 5       5       r\\R"                  R$                  4S j5       r\S 5       rSrg)_VolumeTypew   zBase class for supported volume types.

To add a new supported volume type, create a subclass of this type,
implement all the abstract methods, and annotate the class with
@_registered_volume_type.
c                     g)zThe name of this Volume type.

This is the string that will need to be provided as the `type` value in the
add volumes flag to use this type of volume.
Nr4   r   s    r   r   _VolumeType.name   s     	r"   c                     g)zHelp text for this volume type.Nr4   r   s    r   help_VolumeType.help        	r"   c                 >    [         R                  R                  5       $ )zThe list of release tracks that this volume type should be present in.

Used to progressively roll out types of volumes.

Returns:
  A list of base.ReleaseTrack
r   ReleaseTrack	AllValuesr   s    r   r;   _VolumeType.release_tracks   s     &&((r"   c                     0 $ )zDA dict of field_name: help text for all fields that must be present.r4   r    r,   s     r   required_fields_VolumeType.required_fields   	     Ir"   c                     0 $ )zAA dict of field_name: help text for all fields that are optional.r4   rR   s     r   optional_fields_VolumeType.optional_fields   rU   r"   c                     g)z?Fills in the Volume message (V1) from the provided volume dict.Nr4   )r    r)   r-   r+   s       r   r(   _VolumeType.fill_volume   rK   r"   c                     g)z6Creates the volume (V2) from the provided volume dict.Nr4   )r    r)   s     r   r1   _VolumeType.create_volume_v2   rK   r"   c                     g)z7Validate any additional constraints on the volume type.Nr4   )r    r)   r,   s      r   r'   _VolumeType.validate_fields   rK   r"   c                 l   [        U R                  U5      R                  5       5      n[        U R                  U5      R                  5       5      nU H  nUS:X  a  M  US:X  aN  X   U R	                  5       :w  a6  [
        R                  " SR                  U R	                  5       X   5      5      eM_  XS;  d  Mf  XT;  d  Mm  [
        R                  " SR                  US   US   U5      5      e   X1R                  5       -
  nU(       a-  [
        R                  " SR                  US   US   U5      5      eg)zFValidate that the volume dict has all needed parameters for this type.r   r	   z%expected volume of type {} but got {}z0Volume {} of type {} had unexpected parameter {}z:Volume {} of type {} requires the following parameters: {}N)setrS   keysrW   r   r   ConfigurationErrorformat)r    r)   r,   required_keysoptional_keysr8   missings          r   r&   _VolumeType.validate_volume_add   s#    ++M:??ABM++M:??ABM	&=;#((*$%885<<((*fk  % #(@#66>EEvv
 	
   kkm+G!44
F
M
MVnfVng  r"   c                    SR                  S U R                  U5      R                  5        5       5      nUR                  5       (       a  SU S3OSnSR                  S U R	                  U5      R                  5        5       5      nUR                  5       (       a  SU S3OSnSR                  U R                  5       U R                  5       UUS9$ )z(Generate help text for this volume type.
c              3   H   #    U  H  u  pS R                  X5      v   M     g7f)z* {}: (required) {}  Nrc   .0r   r?   s      r   	<genexpr>,_VolumeType.generate_help.<locals>.<genexpr>   s'       CID 	 &&t11Cs    "z   c              3   X   #    U  H   u  pUS :w  d  M  SR                  X5      v   M"     g7f)r   z* {}: (optional) {}  Nrk   rl   s      r   rn   ro      s1       CID6> 	2&&t11Cs   **z:*{name}*: {hlp}
  Additional keys:  {required}{optional}  )r   r?   requiredoptional)r>   rS   r:   striprW   rc   r   rI   )r    r,   rS   rr   rW   rs   s         r   r=   _VolumeType.generate_help   s     ii  ,,];AAC  O ,;+@+@+B+BO$B'Hii  ,,];AAC  O
 ,;+@+@+B+BO$B'HHOOXXZHHJ	 P  r"   r4   N)__name__
__module____qualname____firstlineno____doc__classmethodabcabstractmethodr   rI   r;   rS   rW   r(   r1   r'   r   rN   GAr&   r=   __static_attributes__r4   r"   r   rD   rD   w   s@    	  	 	  	 ) )       	  	 	  	 	  	 595F5F5I5I  8  r"   rD   c                       \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       rS
rg)_InMemoryVolume   z/Volume Type representing an in-memory emptydir.c                     g)Nz	in-memoryr4   r   s    r   r   _InMemoryVolume.name   s    r"   c                      g)NzAn ephemeral volume that stores data in the instance's memory. With this type of volume, data is not shared between instances and all data will be lost when the instance it is on is terminated.r4   r   s    r   rI   _InMemoryVolume.help       	Jr"   c                 >    [         R                  R                  5       $ NrM   r   s    r   r;   _InMemoryVolume.release_tracks   s    &&((r"   c                     0 $ r   r4   rR   s     r   rS   _InMemoryVolume.required_fields       Ir"   c                 R    U[         R                  R                  :X  a  SSSS.$ SS0$ )NThe name of the volume. A name will be generated if the `mount-path` flag is specified. A name is required if `mount-path` is not specified.  The path at which the volume should be mounted. The `mount-path` parameter is only supported for single container services which do not make use of the --container flag. For multi-container services, specify the `mount-path` parameter under the --add-volume-mount flag.a7  A quantity representing the maximum amount of memory allocated to this volume, such as "512Mi" or "3G". Data stored in an in-memory volume consumes the memory allocation of the container that wrote the data. If size-limit is not specified, the maximum size will be half the total memory limit of all containers.)r   
mount-pathr   r   r   rN   ALPHArR   s     r   rW   _InMemoryVolume.optional_fields  sD    ))///0
* . 	A r"   c                 b    SU;   a  UR                  SUS   S9nOUR                  SS9nXBl        g )Nr   Memorymedium	sizeLimitr   EmptyDirVolumeSourceemptyDirr    r)   r-   r+   srcs        r   r(   _InMemoryVolume.fill_volume&  sD    v))VL%9 * c ))):cr"   c                     UR                  UR                   R                  R                  S9nSU;   a
  US   Ul        UR	                  US   US9$ )Nr   r   r   )r   	empty_dir)r   MediumMEMORY
size_limitr%   )r    r)   r   sources       r   r1    _InMemoryVolume.create_volume_v20  sc    ''))0077 ( F v .f<<F^   r"   r4   N)rv   rw   rx   ry   rz   r{   r   rI   r;   rS   rW   r(   r1   r   r4   r"   r   r   r      s    7    ) )      D   	 	r"   r   c                   x    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       rS	rg
)_TempDiskVolumei=  z0Volume Type representing a disk-backed emptydir.c                     g)Nzephemeral-diskr4   r   s    r   r   _TempDiskVolume.nameA  s    r"   c                      g)NzA volume that stores data on a temporary disk. With this type of volume, data is not shared between instances and all data will be lost when the instance it is on is terminated.r4   r   s    r   rI   _TempDiskVolume.helpE  r   r"   c                 8    [         R                  R                  /$ r   r   r   s    r   r;   _TempDiskVolume.release_tracksM      ##$$r"   c                     0 $ r   r4   rR   s     r   rS   _TempDiskVolume.required_fieldsQ  r   r"   c                     SSSS.$ )Nr   r   zcA quantity representing the amount of disk space allocated to this volume, such as "512Mi" or "3G".)r   r   sizer4   rR   s     r   rW   _TempDiskVolume.optional_fieldsU  s    .
(5 r"   c                 b    SU;   a  UR                  SUS   S9nOUR                  SS9nXBl        g )Nr   Diskr   r   r   r   s        r   r(   _TempDiskVolume.fill_volumej  sC    ))6&> * c )))8cr"   r4   N)rv   rw   rx   ry   rz   r{   r   rI   r;   rS   rW   r(   r   r4   r"   r   r   r   =  s{    8    % %    (  r"   r   c                       \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       rS
rg)
_NfsVolumeiu  z'Volume Type representing an NFS volume.c                     g)Nnfsr4   r   s    r   r   _NfsVolume.namey  s    r"   c                     g)Nz,Represents a volume backed by an NFS server.r4   r   s    r   rI   _NfsVolume.help}      9r"   c                 
    SS0$ )Nr   z8The location of the NFS Server, in the form SERVER:/PATHr4   rR   s     r   rS   _NfsVolume.required_fields  s     	N r"   c                 R    U[         R                  R                  :X  a  SSSS.$ SS0$ )Nr   r   BA boolean. If true, this volume will be read-only from all mounts.)r   r   readonlyr   r   rR   s     r   rW   _NfsVolume.optional_fields  sA    ))///0
* & 	P r"   c                 j    US   nSU;  a(  [         R                  " SR                  US   5      5      eg )Nr   :/zEVolume {}: field 'location' must be of the form IP_ADDRESS:/DIRECTORYr   )r   rb   rc   )r    r)   r,   r   s       r   r'   _NfsVolume.validate_fields  s?    j!H8!44##)6&.#9  r"   c                 ~    [        U5      nUS   R                  SS5      u  pVSU-   nUR                  XVUS9nXrl        g )Nr   r      /)serverr   readOnly)_is_readonlysplitNFSVolumeSourcer   )r    r)   r-   r+   r   r   r   r   s           r   r(   _NfsVolume.fill_volume  sH    F#H*%++D!4LF:D

"
"&h
"
OCKr"   c           	          [        U5      nUS   n[        U5      R                  SS5      u  pVSU-   nUR                  US   UR	                  UUUS9S9$ )Nr   r   r   r   r   )r   r   	read_only)r   r   )r   strr   r%   r   )r    r)   r   r   r   r   r   s          r   r1   _NfsVolume.create_volume_v2  sp    F#Hj!Hx=&&tQ/LF:D<<F^!! " 
   r"   r4   N)rv   rw   rx   ry   rz   r{   r   rI   rS   rW   r'   r(   r1   r   r4   r"   r   r   r   u  s    /  : :  
  4      r"   r   c                       \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       rS
rg)
_GcsVolumei  z&Volume Type representing a GCS volume.c                     g)Nzcloud-storager4   r   s    r   r   _GcsVolume.name  s    r"   c                      g)NzA volume representing a Cloud Storage bucket. This volume type is mounted using Cloud Storage FUSE. See https://cloud.google.com/storage/docs/gcs-fuse for the details and limitations of this filesystem.r4   r   s    r   rI   _GcsVolume.help  s    	.r"   c                 \   U[         R                  R                  :X  a`   [        R                  " 5       nU" UR                  SS5      5      nU(       a  SU;   d  U(       d  SU;  a  [        R                  " S5      eg g g ! [        R                   a    [        R                  " S5      ef = f)Nr   falsez.dynamic-mounting must be set to true or false.r
   z7Either set bucket or enable dynamic-mounting, not both.)
r   rN   r   r   
ArgBooleangetargparseArgumentTypeErrorr   rb   )r    r)   r,   bool_parserdynamic_mountings        r   r'   _GcsVolume.validate_fields  s    ))///
!,,.&vzz2Dg'NO
 x6186#9#66E
 	
 $: 0 '' 
#66<
 	

s   -B   +B+c                 J    U[         R                  R                  :X  a  0 $ SS0$ )Nr
   z:the name of the bucket to use as the source of this volumer   rR   s     r   rS   _GcsVolume.required_fields  s+    ))///iN r"   c                 t    SSS.nU[         R                  R                  :X  a  SUS'   SUS'   SUS	'   S
US'   U$ )Nr   zqA list of flags to pass to GCSFuse. Flags should be specified without leading dashes and separated by semicolons.)r   r   z;the name of the bucket to use as the source of this volume.r
   zA boolean. If true, the volume will be mounted dynamically. Note: You will either need to specify a bucket or set dynamic-mounting to true, but not both.r   r   r   r   r   r   )r    r,   fieldss      r   rW   _GcsVolume.optional_fields  sk     Q	F ))///
G X6  , Vn& \ Mr"   c           	         UR                  S[        U5      S9nUR                   R                  5       Ul        SU;   aJ  UR                  R                  R                  UR                   R                  R                  SUS   S95        SU;   aZ  UR                  R                  R                  UR                   R                  R                  SUS   R                  SS	5      S95        S
U;   aQ  US
   (       aG  UR                  R                  R                  UR                   R                  R                  SSS95        XBl        g )Nzgcsfuse.run.googleapis.com)driverr   r
   
bucketNamer8   valuer   mountOptions;,r   r@   )	CSIVolumeSourcer   VolumeAttributesValuevolumeAttributesadditionalPropertiesr<   AdditionalPropertyreplacecsir   s        r   r(   _GcsVolume.fill_volume  s:   

"
"+l66J # C $33IIKC6	//66

"
"
8
8
K
KfX&6 L 
 & 	//66

"
"
8
8
K
K ?+33C= L  V#/A(B	//66

"
"
8
8
K
Kc L 
 Kr"   c                     SU;   a  US   R                  S5      nO/ nUR                  [        U5      US9nSU;   a  US   (       a  SUl        O
US   Ul        UR	                  US   US9$ )	Nr   r   )r   mount_optionsr   r@   r
   r   )r   gcs)r   GCSVolumeSourcer   r
   r%   )r    r)   r   r   r   s        r   r1   _GcsVolume.create_volume_v2.  s    & _-33C8mm""v&# # F V#/A(BfmX&fm<<F^   r"   r4   N)rv   rw   rx   ry   rz   r{   r   rI   r'   rS   rW   r(   r1   r   r4   r"   r   r   r     s    .    
 
    ! !F  4  r"   r   c                       \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       rS
rg)SecretVolumeiD  z Represents a secret as a volume.c                 8    [         R                  R                  /$ r   r   r   s    r   r;   SecretVolume.release_tracksH  r   r"   c                     g)Nr   r4   r   s    r   r   SecretVolume.nameL  s    r"   c                     g)Nz9Represents a secret stored in Secret Manager as a volume.r4   r   s    r   rI   SecretVolume.helpP  s    Fr"   c                     SSSS.$ )NzThe name of the secret in Secret Manager. Must be a secret in the same project being deployed or be an alias mapped in the `run.googleapis.com/secrets` annotation.z:The version of the secret to make available in the volume.z:The relative path within the volume to mount that version.)r   r   r   r4   rR   s     r   rS   SecretVolume.required_fieldsT  s    8 PL r"   c                     SSS.$ Nr   r   )r   r   r4   rR   s     r   rW   SecretVolume.optional_fields`  s    .
( r"   c                     UR                  US   S9nUR                  US   US   S9nUR                  R                  U5        XBl        g )Nr   )
secretNamer   r   )r   r8   )SecretVolumeSource	KeyToPathr:   r<   r   )r    r)   r-   r+   r   items         r   r(   SecretVolume.fill_volumeq  sO    

%
%1A
%
BC6&>vi7HIDIITNr"   c                 t    UR                  US   UR                  US   UR                  US   US   S9/S9S9$ )Nr   r   r   r   )r   r   )r   r:   )r   r   )r%   r  VersionToPath)r    r)   r   s      r   r1   SecretVolume.create_volume_v2x  s`    <<F^''(###"9-F6N $  ( 
  
 
r"   r4   N)rv   rw   rx   ry   rz   r{   r;   r   rI   rS   rW   r(   r1   r   r4   r"   r   r  r  D  s    (% %   G G 	 	       r"   r  c                       \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       rSrg)CloudSqlInstancei  ,Represents a Cloud SQL instance as a volume.c                 8    [         R                  R                  /$ r   r   r   s    r   r;   CloudSqlInstance.release_tracks  r   r"   c                     g)Ncloudsqlr4   r   s    r   r   CloudSqlInstance.name  s    r"   c                     g)Nr  r4   r   s    r   rI   CloudSqlInstance.help  r   r"   c                     US   R                  S5       HG  nUR                  5       R                  S5      n[        U5      S:w  d  M3  [        R                  " S5      e   g )Nr   r   :   zECloud SQL instances must be in the form project_id:region:instance_id)r   rt   lenr   rb   )r    r)   r,   instances       r   r'    CloudSqlInstance.validate_fields  sW    ;'--c2!'',h	X!	#66-
 	
 3r"   c                 
    SS0$ )Nr   z|The name of the Cloud SQL instances to mount. Must be in the form project_id:region:instance_id and separated by semicolons.r4   rR   s     r   rS    CloudSqlInstance.required_fields  s     	J r"   c                 L    U[         R                  R                  :X  a  SSS.$ 0 $ r  r   rR   s     r   rW    CloudSqlInstance.optional_fields  s1    ))///0
*  Ir"   c           	      ,   UR                  SS9nUR                   R                  5       Ul        SU;   aZ  UR                  R                  R	                  UR                   R                  R                  SUS   R                  SS5      S95        XBl        g )Nzcloudsql.run.googleapis.com)r   r   r   r   r   )r   r   r   r   r<   r   r   r   r   s        r   r(   CloudSqlInstance.fill_volume  s    

"
"*G
"
HC#33IIKCf	//66

"
"
8
8
K
K;'//S9 L  Kr"   c           
          UR                  US   UR                  US   R                  S5       Vs/ s H  o3R                  5       PM     snS9S9$ s  snf )Nr   r   r   )r   )r   cloud_sql_instance)r%   r  r   rt   )r    r)   r   r$  s       r   r1   !CloudSqlInstance.create_volume_v2  sd    <<F^ 11171D1J1J31O1OX 1O 2 
   s   Ar4   N)rv   rw   rx   ry   rz   r{   r;   r   rI   r'   rS   rW   r(   r1   r   r4   r"   r   r  r    s    4% %   : : 
 
    $ 
 
  r"   r  c                 F    SU ;   =(       a    U S   R                  5       S:H  $ )Nr   true)lower)r)   s    r   r   r     s%    	v		F&"4":":"<"FFr"   c                    U[         R                  R                  :X  a9  SU ;  a  [        R                  " S5      eSU ;  a  [        R                  " S5      eO"SU ;  d  SU ;  a  [        R                  " S5      eU S   [
        ;  a(  [        R                  " SR                  U S   5      5      e[
        U S      nXR                  5       ;  a(  [        R                  " SR                  U S   5      5      eg)z#Validates the volume name and type.r	   z"All added volumes must have a typer   zAVolume "name" must be specified if "mount-path" is not specified.z+All added volumes must have a name and typezVolume type {} not supportedN)r   rN   r   r   rb   r   rc   r;   )r)   r,   r.   s      r   r$   r$     s    d''---V!44
. 
 V!44
M  
 VvV3!44
7  F^22

2
2&--fVn=  %VF^4(1133

2
2&--fVn=  4r"   )rz   r|   r   typingr   googlecloudsdk.callioper   r   googlecloudsdk.command_lib.runr   r   r   r   r   r   r!   r/   rN   r   r1   rB   ABCrD   r   r   r   r   r  r  r   r$   r4   r"   r   <module>r7     so   * 
   / ( N  !
(7&	$ (,'8'8'>'>22$$2	q#'' qh Nk N Nb 4k 4 4n L L L^ { { {| ?; ? ?D K{ K K\Gr"   