Skip to content
15 changes: 15 additions & 0 deletions google/cloud/firestore_admin_v1/gapic_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"bulk_delete_documents"
]
},
"CloneDatabase": {
"methods": [
"clone_database"
]
},
"CreateBackupSchedule": {
"methods": [
"create_backup_schedule"
Expand Down Expand Up @@ -175,6 +180,11 @@
"bulk_delete_documents"
]
},
"CloneDatabase": {
"methods": [
"clone_database"
]
},
"CreateBackupSchedule": {
"methods": [
"create_backup_schedule"
Expand Down Expand Up @@ -335,6 +345,11 @@
"bulk_delete_documents"
]
},
"CloneDatabase": {
"methods": [
"clone_database"
]
},
"CreateBackupSchedule": {
"methods": [
"create_backup_schedule"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4111,6 +4111,143 @@ async def sample_delete_backup_schedule():
metadata=metadata,
)

async def clone_database(
self,
request: Optional[Union[firestore_admin.CloneDatabaseRequest, dict]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
) -> operation_async.AsyncOperation:
r"""Creates a new database by cloning an existing one.

The new database must be in the same cloud region or
multi-region location as the existing database. This behaves
similar to
[FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.FirestoreAdmin.CreateDatabase]
except instead of creating a new empty database, a new database
is created with the database type, index configuration, and
documents from an existing database.

The [long-running operation][google.longrunning.Operation] can
be used to track the progress of the clone, with the Operation's
[metadata][google.longrunning.Operation.metadata] field type
being the
[CloneDatabaseMetadata][google.firestore.admin.v1.CloneDatabaseMetadata].
The [response][google.longrunning.Operation.response] type is
the [Database][google.firestore.admin.v1.Database] if the clone
was successful. The new database is not readable or writeable
until the LRO has completed.

.. code-block:: python

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import firestore_admin_v1

async def sample_clone_database():
# Create a client
client = firestore_admin_v1.FirestoreAdminAsyncClient()

# Initialize request argument(s)
pitr_snapshot = firestore_admin_v1.PitrSnapshot()
pitr_snapshot.database = "database_value"

request = firestore_admin_v1.CloneDatabaseRequest(
parent="parent_value",
database_id="database_id_value",
pitr_snapshot=pitr_snapshot,
)

# Make the request
operation = client.clone_database(request=request)

print("Waiting for operation to complete...")

response = (await operation).result()

# Handle the response
print(response)

Args:
request (Optional[Union[google.cloud.firestore_admin_v1.types.CloneDatabaseRequest, dict]]):
The request object. The request message for
[FirestoreAdmin.CloneDatabase][google.firestore.admin.v1.FirestoreAdmin.CloneDatabase].
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
sent along with the request as metadata. Normally, each value must be of type `str`,
but for metadata keys ending with the suffix `-bin`, the corresponding values must
be of type `bytes`.

Returns:
google.api_core.operation_async.AsyncOperation:
An object representing a long-running operation.

The result type for the operation will be
:class:`google.cloud.firestore_admin_v1.types.Database`
A Cloud Firestore Database.

"""
# Create or coerce a protobuf request object.
# - Use the request object if provided (there's no risk of modifying the input as
# there are no flattened fields), or create one.
if not isinstance(request, firestore_admin.CloneDatabaseRequest):
request = firestore_admin.CloneDatabaseRequest(request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._client._transport._wrapped_methods[
self._client._transport.clone_database
]

header_params = {}

routing_param_regex = re.compile("^projects/(?P<project_id>[^/]+)(?:/.*)?$")
regex_match = routing_param_regex.match(request.pitr_snapshot.database)
if regex_match and regex_match.group("project_id"):
header_params["project_id"] = regex_match.group("project_id")

routing_param_regex = re.compile(
"^projects/[^/]+/databases/(?P<database_id>[^/]+)(?:/.*)?$"
)
regex_match = routing_param_regex.match(request.pitr_snapshot.database)
if regex_match and regex_match.group("database_id"):
header_params["database_id"] = regex_match.group("database_id")

if header_params:
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata(header_params),
)

# Validate the universe domain.
self._client._validate_universe_domain()

# Send the request.
response = await rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Wrap the response in an operation future.
response = operation_async.from_gapic(
response,
self._client._transport.operations_client,
database.Database,
metadata_type=gfa_operation.CloneDatabaseMetadata,
)

# Done; return the response.
return response

async def list_operations(
self,
request: Optional[operations_pb2.ListOperationsRequest] = None,
Expand Down
135 changes: 135 additions & 0 deletions google/cloud/firestore_admin_v1/services/firestore_admin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4591,6 +4591,141 @@ def sample_delete_backup_schedule():
metadata=metadata,
)

def clone_database(
self,
request: Optional[Union[firestore_admin.CloneDatabaseRequest, dict]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
) -> gac_operation.Operation:
r"""Creates a new database by cloning an existing one.

The new database must be in the same cloud region or
multi-region location as the existing database. This behaves
similar to
[FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.FirestoreAdmin.CreateDatabase]
except instead of creating a new empty database, a new database
is created with the database type, index configuration, and
documents from an existing database.

The [long-running operation][google.longrunning.Operation] can
be used to track the progress of the clone, with the Operation's
[metadata][google.longrunning.Operation.metadata] field type
being the
[CloneDatabaseMetadata][google.firestore.admin.v1.CloneDatabaseMetadata].
The [response][google.longrunning.Operation.response] type is
the [Database][google.firestore.admin.v1.Database] if the clone
was successful. The new database is not readable or writeable
until the LRO has completed.

.. code-block:: python

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import firestore_admin_v1

def sample_clone_database():
# Create a client
client = firestore_admin_v1.FirestoreAdminClient()

# Initialize request argument(s)
pitr_snapshot = firestore_admin_v1.PitrSnapshot()
pitr_snapshot.database = "database_value"

request = firestore_admin_v1.CloneDatabaseRequest(
parent="parent_value",
database_id="database_id_value",
pitr_snapshot=pitr_snapshot,
)

# Make the request
operation = client.clone_database(request=request)

print("Waiting for operation to complete...")

response = operation.result()

# Handle the response
print(response)

Args:
request (Union[google.cloud.firestore_admin_v1.types.CloneDatabaseRequest, dict]):
The request object. The request message for
[FirestoreAdmin.CloneDatabase][google.firestore.admin.v1.FirestoreAdmin.CloneDatabase].
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
sent along with the request as metadata. Normally, each value must be of type `str`,
but for metadata keys ending with the suffix `-bin`, the corresponding values must
be of type `bytes`.

Returns:
google.api_core.operation.Operation:
An object representing a long-running operation.

The result type for the operation will be
:class:`google.cloud.firestore_admin_v1.types.Database`
A Cloud Firestore Database.

"""
# Create or coerce a protobuf request object.
# - Use the request object if provided (there's no risk of modifying the input as
# there are no flattened fields), or create one.
if not isinstance(request, firestore_admin.CloneDatabaseRequest):
request = firestore_admin.CloneDatabaseRequest(request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.clone_database]

header_params = {}

routing_param_regex = re.compile("^projects/(?P<project_id>[^/]+)(?:/.*)?$")
regex_match = routing_param_regex.match(request.pitr_snapshot.database)
if regex_match and regex_match.group("project_id"):
header_params["project_id"] = regex_match.group("project_id")

routing_param_regex = re.compile(
"^projects/[^/]+/databases/(?P<database_id>[^/]+)(?:/.*)?$"
)
regex_match = routing_param_regex.match(request.pitr_snapshot.database)
if regex_match and regex_match.group("database_id"):
header_params["database_id"] = regex_match.group("database_id")

if header_params:
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata(header_params),
)

# Validate the universe domain.
self._validate_universe_domain()

# Send the request.
response = rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Wrap the response in an operation future.
response = gac_operation.from_gapic(
response,
self._transport.operations_client,
database.Database,
metadata_type=gfa_operation.CloneDatabaseMetadata,
)

# Done; return the response.
return response

def __enter__(self) -> "FirestoreAdminClient":
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ def __init__(
credentials identify the application to the service; if none
are specified, the client will attempt to ascertain the
credentials from the environment.
credentials_file (Optional[str]): A file with credentials that can
credentials_file (Optional[str]): Deprecated. A file with credentials that can
be loaded with :func:`google.auth.load_credentials_from_file`.
This argument is mutually exclusive with credentials.
This argument is mutually exclusive with credentials. This argument will be
removed in the next major version of this library.
scopes (Optional[Sequence[str]]): A list of scopes.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
Expand Down Expand Up @@ -357,6 +358,11 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=None,
client_info=client_info,
),
self.clone_database: gapic_v1.method.wrap_method(
self.clone_database,
default_timeout=120.0,
client_info=client_info,
),
self.cancel_operation: gapic_v1.method.wrap_method(
self.cancel_operation,
default_timeout=None,
Expand Down Expand Up @@ -688,6 +694,15 @@ def delete_backup_schedule(
]:
raise NotImplementedError()

@property
def clone_database(
self,
) -> Callable[
[firestore_admin.CloneDatabaseRequest],
Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]],
]:
raise NotImplementedError()

@property
def list_operations(
self,
Expand Down
Loading
Loading