
                         t    S r SSKJr  SSKJr  SSKJr  SSKJr  S rS r SS	 jr	S
 r
S r SS jr SS jrg)zGUseful commands for interacting with the Cloud Firestore Databases API.    )absolute_import)division)unicode_literals)	api_utilsc                  @    [         R                  " 5       R                  $ )zEReturns the service for interacting with the Firestore admin service.)r   	GetClientprojects_databases     1lib/googlecloudsdk/api_lib/firestore/databases.py_GetDatabaseServicer      s    					1	11r   c                     [         R                  " 5       n[        5       R                  UR	                  SR                  X5      S95      $ )zPerforms a Firestore Admin v1 Database Get.

Args:
  project: the project id to get, a string.
  database: the database id to get, a string.

Returns:
  a database.
projects/{}/databases/{})name)r   GetMessagesr   Get$FirestoreProjectsDatabasesGetRequestformat)projectdatabasemessagess      r   GetDatabaser      sI     ""$(			"	"33)00C 4 
 r   Nc                    [         R                  " 5       n[         R                  " XR                  R                  5      n[        5       R                  UR                  SR                  U 5      UUR                  UUUUUUUU	U
US9
S95      $ )a  Performs a Firestore Admin v1 Database Creation.

Args:
  project: the project id to create, a string.
  location: the database location to create, a string.
  database: the database id to create, a string.
  database_type: the database type, an Enum.
  database_edition: the database edition, an Enum.
  delete_protection_state: the value for deleteProtectionState, an Enum.
  pitr_state: the value for PitrState, an Enum.
  cmek_config: the CMEK config used to encrypt the database, an object.
  mongodb_compatible_data_access_mode: The MongoDB compatible API data access
    mode to use for this database, an Enum.
  firestore_data_access_mode: The Firestore API data access mode to use for
    this database, an Enum.
  realtime_updates_mode: The Realtime Updates mode to use for this database,
    an Enum.
  tags: the tags to attach to the database, a key-value dictionary, or None.

Returns:
  an Operation.
projects/{})
typedatabaseEdition
locationIddeleteProtectionStatepointInTimeRecoveryEnablement
cmekConfigmongodbCompatibleDataAccessModefirestoreDataAccessModerealtimeUpdatesModetags)parent
databaseIdgoogleFirestoreAdminV1Database)	r   r   ParseTagsForTagsValueGoogleFirestoreAdminV1Database	TagsValuer   Create'FirestoreProjectsDatabasesCreateRequestr   )r   locationr   database_typedatabase_editiondelete_protection_state
pitr_statecmek_config#mongodb_compatible_data_access_modefirestore_data_access_moderealtime_updates_moder$   r   
tags_values                 r   CreateDatabaser7   /   s    H ""$(..
33==* 
		%	%66%%g.)1)P)P .!$;,6$.Q&@"7 *Q * 7 
 r   c                     [         R                  " 5       n[        5       R                  UR	                  SR                  X5      US95      $ )zPerforms a Firestore Admin v1 Database Deletion.

Args:
  project: the project of the database to delete, a string.
  database: the database id to delete, a string.
  etag: the current etag of the Database, a string.

Returns:
  an Operation.
r   )r   etag)r   r   r   Delete'FirestoreProjectsDatabasesDeleteRequestr   )r   r   r9   r   s       r   DeleteDatabaser<   k   sL     ""$(			%	%66)00C 7 
 r   c           	          [         R                  " 5       n[        [        5       R	                  UR                  SR                  U 5      U(       a  SOSS95      R                  5      $ )zLists all Firestore databases under the project.

Args:
  project: the project ID to list databases, a string.
  show_deleted: if true, also returns deleted resources, a boolean.

Returns:
  a List of Databases.
r   TN)r%   showDeleted)r   r   listr   List%FirestoreProjectsDatabasesListRequestr   	databases)r   show_deletedr   s      r   ListDatabasesrD      s^     ""$(	t

8
8"))'2".$D 9  y	
 	r   c                    [         R                  " 5       n[         R                  " XER                  R                  5      nUR                  UUUUS9n[        5       R                  UR                  SR                  U 5      US95      $ )a  Restores a Firestore database from a backup.

Args:
  project: the project ID to list databases, a string.
  source_backup: the backup to restore from, a string.
  destination_database: the database to restore to, a string.
  encryption_config: the encryption config to use for the restored database,
    an optional object.
  tags: the tags to attach to the database, a key-value dictionary.

Returns:
  an Operation.
)backupr&   encryptionConfigr$   r   )r%   ,googleFirestoreAdminV1RestoreDatabaseRequest)	r   r   r(   ,GoogleFirestoreAdminV1RestoreDatabaseRequestr*   r   Restore(FirestoreProjectsDatabasesRestoreRequestr   )r   source_backupdestination_databaseencryption_configr$   r   r6   restore_requests           r   RestoreDatabaserP      s    ( ""$(..
AAKK* II%(	 J / 
		&	&77%%g.7F 8 
 r   c                 ,   [         R                  " 5       n[         R                  " XVR                  R                  5      nUR                  UR                  UUS9UUUS9n[        5       R                  UR                  SR                  U 5      US95      $ )a  Clones one Firestore database from another.

Args:
  project: the project ID containing the source database, a string.
  source_database: the resource name of the database to clone, a string.
  snapshot_time: the timestamp at which to clone, a DateTime.
  destination_database: the database to clone to, a string.
  encryption_config: the encryption config to use for the cloned database, an
    optional object.
  tags: the tags to attach to the database, a key-value dictionary, or None.

Returns:
  an Operation.
)r   snapshotTime)pitrSnapshotr&   rG   r$   r   )r%   *googleFirestoreAdminV1CloneDatabaseRequest)
r   r   r(   *GoogleFirestoreAdminV1CloneDatabaseRequestr*   "GoogleFirestoreAdminV1PitrSnapshotr   Clone&FirestoreProjectsDatabasesCloneRequestr   )	r   source_databasesnapshot_timerM   rN   r$   r   r6   clone_requests	            r   CloneDatabaser\      s    , ""$(..
??II* EE>>"$ ?  &( F - 
		$	$55%%g.5B 6 
 r   )N)__doc__
__future__r   r   r    googlecloudsdk.api_lib.firestorer   r   r   r7   r<   rD   rP   r\   r
   r   r   <module>r`      sK    N &  ' 62
< 
9x(8 
$Z 
)r   