
    U              
          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	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 ej&                  j(                  j*                  Zej&                  j.                  j0                  Z ej4                  d ej6                  dd      j8                  j:                  dddddd      Z ej4                  d ej6                  dd      j>                  j@                  dddddd      Z! ej4                  d ej6                  dd      jD                  j@                  dddddd      Z# ej4                  d ej6                  dd      jH                  j@                  dddddd      Z% ej4                  d ej6                  dd      jL                  jN                  dddd d!      Z( ej4                  d" ej6                  dd      jL                  jR                  d#dd$d%d&d'(      Z* ej4                  d) ej6                  dd      jV                  jX                  d*dd+d,d-      Z-d. Z.d/ Z/d0 Z0d1 Z1d2 Z2d3 Z3d4 Z4d5 Z5d6 Z6d7 Z7d8 Z8d9 Z9d: Z:d; Z;d< Z<d= Z=d> Z>d[d?Z?d[d@Z@d[dAZAd\dBZBd[dCZCd[dDZDd[dEZEdF ZFdG ZGdH ZHdI ZIdJ ZJdK ZKdL ZLdM ZMdN ZNdO ZO G dP dQ      ZPdRePfdSZQdT ZRdU ZSdV ZTdW ZUdX ZVdY ZWyZ)]z1Shared resource flags for Cloud Spanner commands.    )absolute_import)division)unicode_literals)apis)
exceptions)concepts)deps)	arg_utils)concept_parsers)presentation_specs)
propertiesz--encryption-typespannerv1z"The encryption type of the backup.F)zuse-database-encryptionz6Use the same encryption configuration as the database.)zgoogle-default-encryptionzUse Google default encryption.)customer-managed-encryptionz^Use the provided Cloud KMS key for encryption.If this option is selected, kms-key must be set.)USE_DATABASE_ENCRYPTIONGOOGLE_DEFAULT_ENCRYPTIONCUSTOMER_MANAGED_ENCRYPTION)help_strrequiredcustom_mappings)r   z_Use the provided Cloud KMS key for encryption. If this option is selected, kms-key must be set.z)The encryption type of the copied backup.)'use-config-default-or-backup-encryptionz}Use the default encryption configuration if one exists. otherwise use the same encryption configuration as the source backup.)'USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTIONr   r   z-The encryption type of the restored database.)r   zvUse the default encryption configuration if one exists, otherwise use the same encryption configuration as the backup.z--instance-typez%Specifies the type for this instance.)provisionedzSProvisioned instances have dedicated resources, standard usage limits, and support.)zfree-instancezFree trial instances provide no guarantees for dedicated resources, both node_count and processing_units should be 0. They come with stricter usage limits and limited support.)PROVISIONEDFREE_INSTANCEz--default-storage-typez5Specifies the default storage type for this instance.T)ssdz1Use ssd as default storage type for this instance)hddz1Use hdd as default storage type for this instance)SSDHDD)r   r   hiddenr   z--expire-behaviorz-The expire behavior of a free trial instance.)zfree-to-provisionedzUWhen the free trial instance expires, upgrade the instance to a provisioned instance.)zremove-after-grace-periodzWhen the free trial instance expires, disable the instance, and delete it after the grace period passes if it has not been upgraded to a provisioned instance.)FREE_TO_PROVISIONEDREMOVE_AFTER_GRACE_PERIODc                  b    t        j                  ddt        j                  t              g      S )z3Get instance resource attribute with default value.instancez.The Cloud Spanner instance for the {resource}.)name	help_textfallthroughs)r    ResourceParameterAttributeConfigr	   PropertyFallthrough	_INSTANCE     7lib/googlecloudsdk/command_lib/spanner/resource_args.pyInstanceAttributeConfigr.      s,    		2	2@,,Y78
: :r,   c                  0    t        j                  dd      S )z=Get instance partition resource attribute with default value.instance partitionz2The Spanner instance partition for the {resource}.r%   r&   r   r(   r+   r,   r-    InstancePartitionAttributeConfigr3      s    		2	2D
 r,   c                  0    t        j                  dd      S )z Get database resource attribute.databasez.The Cloud Spanner database for the {resource}.r1   r2   r+   r,   r-   DatabaseAttributeConfigr6      s    		2	2@
B Br,   c                  0    t        j                  dd      S )zGet backup resource attribute.backupz,The Cloud Spanner backup for the {resource}.r1   r2   r+   r,   r-   BackupAttributeConfigr9      s    		2	2>
@ @r,   c                  0    t        j                  dd      S )z'Get backup schedule resource attribute.backup-schedulez5The Cloud Spanner backup schedule for the {resource}.r1   r2   r+   r,   r-   BackupScheduleAttributeConfigr<      s    		2	2G
I Ir,   c                  0    t        j                  dd      S )zGet session resource attribute.sessionz-The Cloud Spanner session for the {resource}.r1   r2   r+   r,   r-   SessionAttributeConfigr?      s    		2	2 O
Q Qr,   c                  .    t        j                  d      S )Nkms-key)r%   r2   r+   r,   r-   KmsKeyAttributeConfigrB      s    		2	2		BBr,   c                  0    t        j                  dd      S )Nkms-keyringz!KMS keyring id of the {resource}.r1   r2   r+   r,   r-   KmsKeyringAttributeConfigrE      s    		2	2$G
I Ir,   c                  0    t        j                  dd      S )Nkms-locationz"Cloud location for the {resource}.r1   r2   r+   r,   r-   KmsLocationAttributeConfigrH      s    		2	2%I
K Kr,   c                  0    t        j                  dd      S )Nkms-projectz$Cloud project id for the {resource}.r1   r2   r+   r,   r-   KmsProjectAttributeConfigrK     s    		2	2$J
L Lr,   c                  `    t        j                  ddt               t         j                        S )Nzspanner.projects.instancesr$   )resource_nameinstancesId
projectsId)r   ResourceSpecr.    DEFAULT_PROJECT_ATTRIBUTE_CONFIGr+   r,   r-   GetInstanceResourceSpecrR   
  s*    			")+::	
< <r,   c                  r    t        j                  ddt               t               t         j                        S )Nz-spanner.projects.instances.instancePartitionsr0   )rM   instancePartitionsIdrN   rO   )r   rP   r3   r.   rQ   r+   r,   r-    GetInstancePartitionResourceSpecrU     s0    			5(;=)+::
 r,   c                  r    t        j                  ddt               t               t         j                        S )Nz$spanner.projects.instances.databasesr5   )rM   databasesIdrN   rO   )r   rP   r6   r.   rQ   r+   r,   r-   GetDatabaseResourceSpecrX     s0    			,)+)+::
< <r,   c            	      x    t        j                  ddt               t               t	               t                     S )Nz/cloudkms.projects.locations.keyRings.cryptoKeyskey)rM   cryptoKeysId
keyRingsIdlocationsIdrO   )r   rP   rB   rE   rH   rK   r+   r,   r-   GetKmsKeyResourceSpecr^   %  s3    			7(**,,.*,
. .r,   c                  r    t        j                  ddt               t               t         j                        S )Nz"spanner.projects.instances.backupsr8   )rM   	backupsIdrN   rO   )r   rP   r9   r.   rQ   r+   r,   r-   GetBackupResourceSpecra   /  s0    			*%')+::
< <r,   c                      t        j                  ddt               t               t	               t         j
                        S )Nz4spanner.projects.instances.databases.backupSchedulesr;   )rM   backupSchedulesIdrW   rN   rO   )r   rP   r<   r6   r.   rQ   r+   r,   r-   GetBackupScheduleResourceSpecrd   8  s6    			<%57)+)+::
< <r,   c                      t        j                  ddt               t               t	               t         j
                        S )Nz-spanner.projects.instances.databases.sessionsr>   )rM   
sessionsIdrW   rN   rO   )r   rP   r?   r6   r.   rQ   r+   r,   r-   GetSessionResourceSpecrg   B  s6    			5'))+)+::
< <r,   c                     |rdnd}t         j                  j                  |t               dj	                  |      d      j                  |        y)af  Add a resource argument for a Cloud Spanner instance.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the argparse parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
    positional: bool, if True, means that the instance ID is a positional rather
      than a flag.
  r$   z
--instancezThe Cloud Spanner instance {}.Tr   N)r   ConceptParserForResourcerR   formatAddToParserparserverb
positionalr%   s       r-   AddInstanceResourceArgrr   L  L     "|$++
&--d3	 ,  ![(r,   c                     |rdnd}t         j                  j                  |t               dj	                  |      d      j                  |        y)aj  Add a resource argument for a Spanner instance partition.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the argparse parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
    positional: bool, if True, means that the instance ID is a positional rather
      than a flag.
  instance_partitionz--instance-partitionz"The Spanner instance partition {}.Tri   N)r   rj   rk   rU   rl   rm   rn   s       r-   AddInstancePartitionResourceArgrv   _  sN     ",	1G$++
&(*11$7	 , 
 Kr,   c                     |rdnd}t         j                  j                  |t               dj	                  |      d      j                  |        y)af  Add a resource argument for a Cloud Spanner database.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the argparse parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
    positional: bool, if True, means that the database ID is a positional rather
      than a flag.
  r5   z
--databasezThe Cloud Spanner database {}.Tri   N)r   rj   rk   rX   rl   rm   rn   s       r-   AddDatabaseResourceArgrx   s  rs   r,   c                 X   |rdnd}|rdnd}| j                  dd      }t        j                  t        j                  |t               dj                  |      d	|
      t        j                  |t               dj                  |      d	dd|dddd      g      j                  |        y)a0  Add a resource argument for a KMS Key used to create a CMEK database.

  Args:
    parser: argparser, the parser for the command.
    verb: str, the verb used to describe the resource, such as 'to create'.
    positional: bool, optional. True if the resource arg is postional rather
      than a flag.
  rA   z	--kms-keykms-keysz
--kms-keyszKMS key name groupT)mutexzCloud KMS key to be used {}.F)r   groupzCloud KMS key(s) to be used {}. )rG   rD   rJ   )r   prefixespluralr|   flag_name_overridesN)	add_groupr   rj   r   ResourcePresentationSpecr^   rl   rm   )ro   rp   rq   kms_key_namekms_key_namesr|   s         r-   AddKmsKeyResourceArgr     s     )k, **-


/t

<%11


!
(
/
/
5 11


!
+
2
24
8 ! , [r,   c                     |rdnd}t         j                  j                  |t               dj	                  |      d      j                  |        y)a[  Add a resource argument for a Cloud Spanner session.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
    positional: bool, if True, means that the session ID is a positional rather
      than a flag.
  r>   z	--sessionzThe Cloud Spanner session {}.Tri   N)r   rj   rk   rg   rl   rm   rn   s       r-   AddSessionResourceArgr     sL     !k$++
%,,T2	 ,  ![(r,   c                     |rdnd}t         j                  j                  |t               dj	                  |      d      j                  |        y)ab  Add a resource argument for a Cloud Spanner backup.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the argparse parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
    positional: bool, if True, means that the backup ID is a positional rather
      than a flag.
  r8   z--backupzThe Cloud Spanner backup {}.Tri   N)r   rj   rk   ra   rl   rm   rn   s       r-   AddBackupResourceArgr     sL      Z$++
$++D1	 ,  ![(r,   c                     |rdnd}t         j                  j                  |t               dj	                  |      d      j                  |        y)au  Add a resource argument for a Cloud Spanner backup schedule.

  NOTE: Must be used only if it's the only resource arg in the command.

  Args:
    parser: the argparse parser for the command.
    verb: str, the verb to describe the resource, such as 'to update'.
    positional: bool, if True, means that the backup schedules ID is a
      positional rather than a flag.
  backup_schedulez--backup-schedulez%The Cloud Spanner backup schedule {}.Tri   N)r   rj   rk   rd   rl   rm   rn   s       r-   AddBackupScheduleResourceArgr     sN     )	.A$++
#%-44T:	 ,  ![(r,   c                 @    t         j                  j                  |       S N)%_CREATE_BACKUP_ENCRYPTION_TYPE_MAPPER
choice_argrm   ro   s    r-    AddCreateBackupEncryptionTypeArgr     s    	.	9	9	E	Ef	MMr,   c                 @    t         j                  | j                        S r   )r   GetEnumForChoiceencryption_typeargss    r-   GetCreateBackupEncryptionTyper     s    	.	?	?

 r,   c                 @    t         j                  j                  |       S r   ),_CREATE_BACKUP_ENCRYPTION_CONFIG_TYPE_MAPPERr   rm   r   s    r-   &AddCreateBackupEncryptionConfigTypeArgr     s    	5	@	@	L	L
 r,   c                 @    t         j                  | j                        S r   )r   r   r   r   s    r-   #GetCreateBackupEncryptionConfigTyper     s    	5	F	F

 r,   c           
          t        j                  dt               ddddd      t        j                  dt               ddd	d
d      g}t        j                  |      j                  |        y)z@Add backup resource args (source, destination) for copy command.--sourceTEXTT--source-instance--source-backupr$   r8   r   r   --destination--destination-instancez--destination-backupN)r   r   ra   r   rj   rm   ro   	arg_specss     r-   AddCopyBackupResourceArgsr     sx     11


!
-) 11


!
2.)* 	*66v>r,   c                 @    t         j                  j                  |       S r   )#_COPY_BACKUP_ENCRYPTION_TYPE_MAPPERr   rm   r   s    r-   AddCopyBackupEncryptionTypeArgr     s    	,	7	7	C	CF	KKr,   c                 @    t         j                  | j                        S r   )r   r   r   r   s    r-   GetCopyBackupEncryptionTyper     s    	,	=	=

 r,   c           
          t        j                  dt               ddddd      t        j                  dt               ddd	d
d      g}t	        j
                  |      j                  |        y)zCAdd backup resource args (source, destination) for restore command.r   r   Tr   r   r   r   r   r   z--destination-database)r$   r5   N)r   r   ra   rX   r   rj   rm   r   s     r-   AddRestoreResourceArgsr     sx     11


!
-) 11

!
#
22)* 	*66v>r,   c                 @    t         j                  j                  |       S r   )"_RESTORE_DB_ENCRYPTION_TYPE_MAPPERr   rm   r   s    r-   AddRestoreDbEncryptionTypeArgr   8  s    	+	6	6	B	B6	JJr,   c                 @    t         j                  | j                        S r   )r   r   r   r   s    r-   GetRestoreDbEncryptionTyper   <  s    	+	<	<

 r,   c                       e Zd ZdZddZy)CloudKmsKeyNamezCloudKmsKeyName to encapsulate `kmsKeyName` and `kmsKeyNames` fields.

  Single `kmsKeyName` and repeated `kmsKeyNames` fields are extracted from user
  input, which are later used in `EncryptionConfig` to pass to Spanner backend.
  Nc                 4    || _         |g | _        y || _        y r   )r   r   )selfr   r   s      r-   __init__zCloudKmsKeyName.__init__H  s     $Dd(dr,   )NN)__name__
__module____qualname____doc__r   r+   r,   r-   r   r   A  s    )r,   r   returnc                    | j                   j                  j                         }| j                   j                  j                         }t	               }|r|j                         |_        |S |r%|D cg c]  }|j                          c}|_        |S dD ]5  }t        | |j                  dd      d      s!t        j                  dd       yc c}w )zParse the KMS key resource arg, make sure the key format is correct.

  Args:
    args: calliope framework gcloud args

  Returns:
    CloudKmsKeyName: if CMEK.
    None: if non-CMEK.
  )rA   rD   rG   rJ   rz   -_NzB--kms-project --kms-location --kms-keyring --kms-key or --kms-keyszFor a single KMS key, specify fully qualified KMS key ID with --kms-key, or use combination of --kms-project, --kms-location, --kms-keyring and --kms-key to specify the key ID in pieces. Or specify fully qualified KMS key ID with --kms-keys.)CONCEPTSkms_keyParsekms_keysr   RelativeNamer   r   getattrreplacer   InvalidArgumentException)r   r   r   cloud_kms_key_namekeywords        r-   GetAndValidateKmsKeyNamer   P  s     &&,,.,--((..0-&(&2&?&?&A#2 
1 8E(8E!!#($. 
% 
wsC0$	7115
 	
" -(s   2Cc                 @    t         j                  j                  |       S r   )_INSTANCE_TYPE_MAPPERr   rm   r   s    r-   AddInstanceTypeArgr   z  s    		)	)	5	5f	==r,   c                 @    t         j                  | j                        S r   )r   r   instance_typer   s    r-   GetInstanceTyper   ~  s    		/	/0B0B	CCr,   c                 @    t         j                  j                  |       S r   )_DEFAULT_STORAGE_TYPE_MAPPERr   rm   r   s    r-   AddDefaultStorageTypeArgr     s    	%	0	0	<	<V	DDr,   c                 @    t         j                  | j                        S r   )r   r   default_storage_typer   s    r-   GetDefaultStorageTypeArgr     s    	%	6	6

 r,   c                 @    t         j                  j                  |       S r   )_EXPIRE_BEHAVIOR_MAPPERr   rm   r   s    r-   AddExpireBehaviorArgr     s    	 	+	+	7	7	??r,   c                 @    t         j                  | j                        S r   )r   r   expire_behaviorr   s    r-   GetExpireBehaviorr     s    	 	1	1$2F2F	GGr,   N)T)F)Xr   
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper    googlecloudsdk.calliope.conceptsr   r	   $googlecloudsdk.command_lib.util.apisr
   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   VALUEScoreproject_PROJECTr   r$   r*   ChoiceEnumMapperGetMessagesModule,SpannerProjectsInstancesBackupsCreateRequest-EncryptionConfigEncryptionTypeValueValuesEnumr   CreateBackupEncryptionConfigEncryptionTypeValueValuesEnumr   CopyBackupEncryptionConfigr   RestoreDatabaseEncryptionConfigr   InstanceInstanceTypeValueValuesEnumr   !DefaultStorageTypeValueValuesEnumr   FreeInstanceMetadataExpireBehaviorValueValuesEnumr   r.   r3   r6   r9   r<   r?   rB   rE   rH   rK   rR   rU   rX   r^   ra   rd   rg   rr   rv   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r+   r,   r-   <module>r      s~   8 &  ' , . 5 1 : D G * !!))%%..	(B	(B(BD4223`3`1$
&
(
) %2 0Jy/I/ID4""#@#@1$
&
(
0 ,4 'Ai&@&@D4  !>!>84
&
(
' #< &@Y%?%?D4%%&C&C<4
&
(
& ": 3	22D4h**4

 4  :y99D4h00DKK   5)44D4--.K.K<(6
 &:B@IQC
I
K
L
<<.<<<)&()&"J)&)()(N
?4L
?4K
) )'o 'T>DE@Hr,   