
                         ^   d 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 ddlmZ ddl	m
Z
 dd	lmZ dd
lmZ e
j                   e
j                   e
j"                  j$                  e
j"                  j&                  e
j"                  j(                         G d de
j*                                      Zy)z-Command to create a Cloud Firestore Database.    )absolute_import)division)unicode_literalsN)	api_utils)	databases)base)flags)
propertiesc                   D    e Zd ZdZd Zd Zd Zd Zd Zd Z	e
d        Zy	)
CreateFirestoreAPIa  Create a Google Cloud Firestore database via Firestore API.

  ## EXAMPLES

  To create a Firestore Enterprise database named `foo` in `nam5` for use with
  MongoDB Compatibility.

      $ {command} --database=foo --edition=enterprise --location=nam5

  To create a Firestore Native database in `nam5`.

      $ {command} --location=nam5

  To create a Firestore Native database in `us-central1` with tags.

      $ {command} --location=us-central1 --tags=key1=value1,key2=value2

  To create a Datastore Mode database in `us-east1`.

      $ {command} --location=us-east1 --type=datastore-mode

  To create a Datastore Mode database in `us-east1` with a databaseId `foo`.

      $ {command} --database=foo --location=us-east1 --type=datastore-mode

  To create a Firestore Native database in `nam5` with delete protection
  enabled.

      $ {command} --location=nam5 --delete-protection

  To create a Firestore Native database in `nam5` with Point In Time Recovery
  (PITR) enabled.

      $ {command} --location=nam5 --enable-pitr

  To create a Firestore Native database in `nam5` encrypted by a
  Customer-managed encryption key (CMEK).

      $ {command}
      --location=nam5
      --kms-key-name=projects/PROJECT_ID/locations/us/keyRings/KEY_RING_ID/cryptoKeys/CRYPTO_KEY_ID
  c                    |dk(  r2t        j                         j                  j                  j                  S |dk(  r2t        j                         j                  j                  j
                  S t        dj                  |            )Nfirestore-nativedatastore-modezinvalid database type: {})r   GetMessagesGoogleFirestoreAdminV1DatabaseTypeValueValuesEnumFIRESTORE_NATIVEDATASTORE_MODE
ValueErrorformat)selfdatabase_types     )lib/surface/firestore/databases/create.pyDatabaseTypezCreateFirestoreAPI.DatabaseTypeN   su    **



!
@
@
T
T
e
e 
*	*



!
@
@
T
T
c
c 299-HII    c                    |dk(  r2t        j                         j                  j                  j                  S |dk(  r2t        j                         j                  j                  j
                  S t        dj                  |            )Nstandard
enterprisezinvalid database edition: {})r   r   r   DatabaseEditionValueValuesEnumSTANDARD
ENTERPRISEr   r   )r   database_editions     r   DatabaseEditionz"CreateFirestoreAPI.DatabaseEditionZ   st    :%



!
@
@
_
_
h
h 
\	)



!
@
@
_
_
j
j 5<<=MNOOr   c                     |r2t        j                         j                  j                  j                  S t        j                         j                  j                  j
                  S N)r   r   r   $DeleteProtectionStateValueValuesEnumDELETE_PROTECTION_ENABLEDDELETE_PROTECTION_DISABLED)r   enable_delete_protections     r   DatabaseDeleteProtectionStatez0CreateFirestoreAPI.DatabaseDeleteProtectionStatef   sM    



!
@
@
e
e

 	>>cc~~r   c                 6   |2t        j                         j                  j                  j                  S |r2t        j                         j                  j                  j
                  S t        j                         j                  j                  j                  S r%   )r   r   r   ,PointInTimeRecoveryEnablementValueValuesEnum-POINT_IN_TIME_RECOVERY_ENABLEMENT_UNSPECIFIEDPOINT_IN_TIME_RECOVERY_ENABLEDPOINT_IN_TIME_RECOVERY_DISABLED)r   enable_pitrs     r   DatabasePitrStatez$CreateFirestoreAPI.DatabasePitrStateo   s    



!
@
@
m
m  \  \ 



!
@
@
m
m  M  M 	>>kk  	L  	Lr   c                     |j                   .t        j                         j                  |j                         S t        j                         j                         S )N)
kmsKeyName)kms_key_namer   r    GoogleFirestoreAdminV1CmekConfig)r   argss     r   DatabaseCmekConfigz%CreateFirestoreAPI.DatabaseCmekConfig|   sS    $""$EE&& F     "CCEEr   c                    t         j                  j                  j                  j	                  d      }t        j                  ||j                  |j                  | j                  |j                        | j                  |j                        | j                  |j                        | j                  |j                         | j#                  |      |j$                  	      S )NT)required)r
   VALUEScoreprojectGetr   CreateDatabaselocationdatabaser   typer#   editionr*   delete_protectionr1   r0   r7   tags)r   r6   r<   s      r   RunzCreateFirestoreAPI.Run   s    $$,,00$0?G##$))$T\\***4+A+ABt//0%		
 
r   c                    t        j                  |ddg       |j                  dddddg       |j                  d	d
dddg       |j                  dt        j                  d      t
        d       |j                  dt        j                  d      dd       |j                  dt        j                  d      dd        t        j                  |       t        j                  |d       y )NTz--region)r9   suggestion_aliasesz	--editionzThe edition of the database.r   r   )helpdefaultchoicesz--typezThe type of the database.r   r   z
--databasea              The ID to use for the database, which will become the final
            component of the database's resource name. If database ID is not
            provided, (default) will be used as database ID.

            This value should be 4-63 characters. Valid characters are /[a-z][0-9]-/
            with first character a letter and the last a letter or a number. Must
            not be UUID-like /[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/.

            Using "(default)" database ID is also allowed.
            z	(default))rH   rA   rI   z--delete-protectiona              Whether to enable delete protection on the created database.

            If set to true, delete protection of the new database will be enabled
            and delete operations will fail unless delete protection is disabled.

            Default to false.
            
store_trueF)rH   actionrI   z--enable-pitrz            Whether to enable Point In Time Recovery (PITR) on the created database.

            If set to true, PITR on the new database will be enabled. By default, this feature is not enabled.
            r@   )r	   AddLocationFlagadd_argumenttextwrapdedentstrAddKmsKeyNameFlagAddTags)clsparsers     r   ArgszCreateFirestoreAPI.Args   s   	:, +\*	   ("#%56	   __ 
 
     __      __  
   	 
F#	MM&*%r   N)__name__
__module____qualname____doc__r   r#   r*   r1   r7   rE   classmethodrV    r   r   r   r      s=    
)V
J
PF 8& 8&r   r   )rZ   
__future__r   r   r   rO    googlecloudsdk.api_lib.firestorer   r   googlecloudsdk.callioper   $googlecloudsdk.command_lib.firestorer	   googlecloudsdk.corer
   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHABETAGACommandr   r\   r   r   <module>ri      s    4 &  '  6 6 ( 6 * T..33T5F5F5I5Ih& h& h&r   