Skip to content

Commit

Permalink
feat: add CreateDatabase API (#724)
Browse files Browse the repository at this point in the history
* feat: add CreateDatabase API

PiperOrigin-RevId: 537397252

Source-Link: googleapis/googleapis@b4481e1

Source-Link: googleapis/googleapis-gen@6b4b12a
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNmI0YjEyYWJlOWVjZTYzODJlYThkNmZmZDVjNTBlMzZiMzI5MDVmOCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Jun 3, 2023
1 parent b7eed8e commit 64e4404
Show file tree
Hide file tree
Showing 11 changed files with 1,106 additions and 4 deletions.
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 @@ -10,6 +10,11 @@
"grpc": {
"libraryClient": "FirestoreAdminClient",
"rpcs": {
"CreateDatabase": {
"methods": [
"create_database"
]
},
"CreateIndex": {
"methods": [
"create_index"
Expand Down Expand Up @@ -75,6 +80,11 @@
"grpc-async": {
"libraryClient": "FirestoreAdminAsyncClient",
"rpcs": {
"CreateDatabase": {
"methods": [
"create_database"
]
},
"CreateIndex": {
"methods": [
"create_index"
Expand Down Expand Up @@ -140,6 +150,11 @@
"rest": {
"libraryClient": "FirestoreAdminClient",
"rpcs": {
"CreateDatabase": {
"methods": [
"create_database"
]
},
"CreateIndex": {
"methods": [
"create_index"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ async def sample_list_indexes():
Returns:
google.cloud.firestore_admin_v1.services.firestore_admin.pagers.ListIndexesAsyncPager:
The response for
[FirestoreAdmin.ListIndexes][google.firestore.admin.v1.FirestoreAdmin.ListIndexes].
[FirestoreAdmin.ListIndexes][google.firestore.admin.v1.FirestoreAdmin.ListIndexes].
Iterating over this object will yield results and
resolve additional pages automatically.
Expand Down Expand Up @@ -1057,7 +1057,7 @@ async def sample_list_fields():
Returns:
google.cloud.firestore_admin_v1.services.firestore_admin.pagers.ListFieldsAsyncPager:
The response for
[FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields].
[FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields].
Iterating over this object will yield results and
resolve additional pages automatically.
Expand Down Expand Up @@ -1387,6 +1387,146 @@ async def sample_import_documents():
# Done; return the response.
return response

async def create_database(
self,
request: Optional[Union[firestore_admin.CreateDatabaseRequest, dict]] = None,
*,
parent: Optional[str] = None,
database: Optional[gfa_database.Database] = None,
database_id: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation_async.AsyncOperation:
r"""Create a database.
.. 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_create_database():
# Create a client
client = firestore_admin_v1.FirestoreAdminAsyncClient()
# Initialize request argument(s)
request = firestore_admin_v1.CreateDatabaseRequest(
parent="parent_value",
database_id="database_id_value",
)
# Make the request
operation = client.create_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.CreateDatabaseRequest, dict]]):
The request object. The request for
[FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.FirestoreAdmin.CreateDatabase].
parent (:class:`str`):
Required. A parent name of the form
``projects/{project_id}``
This corresponds to the ``parent`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
database (:class:`google.cloud.firestore_admin_v1.types.Database`):
Required. The Database to create.
This corresponds to the ``database`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
database_id (:class:`str`):
Required. The ID to use for the
database, which will become the final
component of the database's resource
name.
The value must be set to "(default)".
This corresponds to the ``database_id`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
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, str]]): Strings which should be
sent along with the request as metadata.
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.
Currently only one database is allowed per cloud
project; this database must have a database_id of
'(default)'.
"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent, database, database_id])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

request = firestore_admin.CreateDatabaseRequest(request)

# If we have keyword arguments corresponding to fields on the
# request, apply these.
if parent is not None:
request.parent = parent
if database is not None:
request.database = database
if database_id is not None:
request.database_id = database_id

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.create_database,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# 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,
gfa_database.Database,
metadata_type=firestore_admin.CreateDatabaseMetadata,
)

# Done; return the response.
return response

async def get_database(
self,
request: Optional[Union[firestore_admin.GetDatabaseRequest, dict]] = None,
Expand Down
144 changes: 142 additions & 2 deletions google/cloud/firestore_admin_v1/services/firestore_admin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def sample_list_indexes():
Returns:
google.cloud.firestore_admin_v1.services.firestore_admin.pagers.ListIndexesPager:
The response for
[FirestoreAdmin.ListIndexes][google.firestore.admin.v1.FirestoreAdmin.ListIndexes].
[FirestoreAdmin.ListIndexes][google.firestore.admin.v1.FirestoreAdmin.ListIndexes].
Iterating over this object will yield results and
resolve additional pages automatically.
Expand Down Expand Up @@ -1299,7 +1299,7 @@ def sample_list_fields():
Returns:
google.cloud.firestore_admin_v1.services.firestore_admin.pagers.ListFieldsPager:
The response for
[FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields].
[FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields].
Iterating over this object will yield results and
resolve additional pages automatically.
Expand Down Expand Up @@ -1618,6 +1618,146 @@ def sample_import_documents():
# Done; return the response.
return response

def create_database(
self,
request: Optional[Union[firestore_admin.CreateDatabaseRequest, dict]] = None,
*,
parent: Optional[str] = None,
database: Optional[gfa_database.Database] = None,
database_id: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> gac_operation.Operation:
r"""Create a database.
.. 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_create_database():
# Create a client
client = firestore_admin_v1.FirestoreAdminClient()
# Initialize request argument(s)
request = firestore_admin_v1.CreateDatabaseRequest(
parent="parent_value",
database_id="database_id_value",
)
# Make the request
operation = client.create_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.CreateDatabaseRequest, dict]):
The request object. The request for
[FirestoreAdmin.CreateDatabase][google.firestore.admin.v1.FirestoreAdmin.CreateDatabase].
parent (str):
Required. A parent name of the form
``projects/{project_id}``
This corresponds to the ``parent`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
database (google.cloud.firestore_admin_v1.types.Database):
Required. The Database to create.
This corresponds to the ``database`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
database_id (str):
Required. The ID to use for the
database, which will become the final
component of the database's resource
name.
The value must be set to "(default)".
This corresponds to the ``database_id`` field
on the ``request`` instance; if ``request`` is provided, this
should not be set.
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, str]]): Strings which should be
sent along with the request as metadata.
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.
Currently only one database is allowed per cloud
project; this database must have a database_id of
'(default)'.
"""
# Create or coerce a protobuf request object.
# Quick check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
has_flattened_params = any([parent, database, database_id])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
)

# Minor optimization to avoid making a copy if the user passes
# in a firestore_admin.CreateDatabaseRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, firestore_admin.CreateDatabaseRequest):
request = firestore_admin.CreateDatabaseRequest(request)
# If we have keyword arguments corresponding to fields on the
# request, apply these.
if parent is not None:
request.parent = parent
if database is not None:
request.database = database
if database_id is not None:
request.database_id = database_id

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

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# 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,
gfa_database.Database,
metadata_type=firestore_admin.CreateDatabaseMetadata,
)

# Done; return the response.
return response

def get_database(
self,
request: Optional[Union[firestore_admin.GetDatabaseRequest, dict]] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.create_database: gapic_v1.method.wrap_method(
self.create_database,
default_timeout=None,
client_info=client_info,
),
self.get_database: gapic_v1.method.wrap_method(
self.get_database,
default_timeout=None,
Expand Down Expand Up @@ -350,6 +355,15 @@ def import_documents(
]:
raise NotImplementedError()

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

@property
def get_database(
self,
Expand Down
Loading

0 comments on commit 64e4404

Please sign in to comment.