Skip to content

Commit

Permalink
feat: Add ListDatabaseRoles API to support role based access control (#…
Browse files Browse the repository at this point in the history
…774)

* feat: Add ListDatabaseRoles API to support role based access control

PiperOrigin-RevId: 462086058

Source-Link: googleapis/googleapis@4f072bf

Source-Link: googleapis/googleapis-gen@06f699d
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMDZmNjk5ZGE2NmY3YTA3Yjk1NDFlNTdhN2QwMzg2M2I0ZGY0OTcxYyJ9

* 🦉 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 Jul 20, 2022
1 parent 12854d5 commit 3867882
Show file tree
Hide file tree
Showing 15 changed files with 1,323 additions and 15 deletions.
6 changes: 6 additions & 0 deletions google/cloud/spanner_admin_database_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@
from .types.spanner_database_admin import CreateDatabaseMetadata
from .types.spanner_database_admin import CreateDatabaseRequest
from .types.spanner_database_admin import Database
from .types.spanner_database_admin import DatabaseRole
from .types.spanner_database_admin import DropDatabaseRequest
from .types.spanner_database_admin import GetDatabaseDdlRequest
from .types.spanner_database_admin import GetDatabaseDdlResponse
from .types.spanner_database_admin import GetDatabaseRequest
from .types.spanner_database_admin import ListDatabaseOperationsRequest
from .types.spanner_database_admin import ListDatabaseOperationsResponse
from .types.spanner_database_admin import ListDatabaseRolesRequest
from .types.spanner_database_admin import ListDatabaseRolesResponse
from .types.spanner_database_admin import ListDatabasesRequest
from .types.spanner_database_admin import ListDatabasesResponse
from .types.spanner_database_admin import OptimizeRestoredDatabaseMetadata
Expand All @@ -71,6 +74,7 @@
"Database",
"DatabaseAdminClient",
"DatabaseDialect",
"DatabaseRole",
"DeleteBackupRequest",
"DropDatabaseRequest",
"EncryptionConfig",
Expand All @@ -85,6 +89,8 @@
"ListBackupsResponse",
"ListDatabaseOperationsRequest",
"ListDatabaseOperationsResponse",
"ListDatabaseRolesRequest",
"ListDatabaseRolesResponse",
"ListDatabasesRequest",
"ListDatabasesResponse",
"OperationProgress",
Expand Down
10 changes: 10 additions & 0 deletions google/cloud/spanner_admin_database_v1/gapic_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
"list_database_operations"
]
},
"ListDatabaseRoles": {
"methods": [
"list_database_roles"
]
},
"ListDatabases": {
"methods": [
"list_databases"
Expand Down Expand Up @@ -165,6 +170,11 @@
"list_database_operations"
]
},
"ListDatabaseRoles": {
"methods": [
"list_database_roles"
]
},
"ListDatabases": {
"methods": [
"list_databases"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class DatabaseAdminAsyncClient:
)
database_path = staticmethod(DatabaseAdminClient.database_path)
parse_database_path = staticmethod(DatabaseAdminClient.parse_database_path)
database_role_path = staticmethod(DatabaseAdminClient.database_role_path)
parse_database_role_path = staticmethod(
DatabaseAdminClient.parse_database_role_path
)
instance_path = staticmethod(DatabaseAdminClient.instance_path)
parse_instance_path = staticmethod(DatabaseAdminClient.parse_instance_path)
common_billing_account_path = staticmethod(
Expand Down Expand Up @@ -2595,6 +2599,125 @@ async def sample_list_backup_operations():
# Done; return the response.
return response

async def list_database_roles(
self,
request: Union[spanner_database_admin.ListDatabaseRolesRequest, dict] = None,
*,
parent: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListDatabaseRolesAsyncPager:
r"""Lists Cloud Spanner database roles.
.. code-block:: python
from google.cloud import spanner_admin_database_v1
async def sample_list_database_roles():
# Create a client
client = spanner_admin_database_v1.DatabaseAdminAsyncClient()
# Initialize request argument(s)
request = spanner_admin_database_v1.ListDatabaseRolesRequest(
parent="parent_value",
)
# Make the request
page_result = client.list_database_roles(request=request)
# Handle the response
async for response in page_result:
print(response)
Args:
request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest, dict]):
The request object. The request for
[ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles].
parent (:class:`str`):
Required. The database whose roles should be listed.
Values are of the form
``projects/<project>/instances/<instance>/databases/<database>/databaseRoles``.
This corresponds to the ``parent`` 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.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesAsyncPager:
The response for
[ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles].
Iterating over this object will yield results and
resolve additional pages automatically.
"""
# 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])
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 = spanner_database_admin.ListDatabaseRolesRequest(request)

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

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.list_database_roles,
default_retry=retries.Retry(
initial=1.0,
maximum=32.0,
multiplier=1.3,
predicate=retries.if_exception_type(
core_exceptions.DeadlineExceeded,
core_exceptions.ServiceUnavailable,
),
deadline=3600.0,
),
default_timeout=3600.0,
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,
)

# This method is paged; wrap the response in a pager, which provides
# an `__aiter__` convenience method.
response = pagers.ListDatabaseRolesAsyncPager(
method=rpc,
request=request,
response=response,
metadata=metadata,
)

# Done; return the response.
return response

async def __aenter__(self):
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,30 @@ def parse_database_path(path: str) -> Dict[str, str]:
)
return m.groupdict() if m else {}

@staticmethod
def database_role_path(
project: str,
instance: str,
database: str,
role: str,
) -> str:
"""Returns a fully-qualified database_role string."""
return "projects/{project}/instances/{instance}/databases/{database}/databaseRoles/{role}".format(
project=project,
instance=instance,
database=database,
role=role,
)

@staticmethod
def parse_database_role_path(path: str) -> Dict[str, str]:
"""Parses a database_role path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/instances/(?P<instance>.+?)/databases/(?P<database>.+?)/databaseRoles/(?P<role>.+?)$",
path,
)
return m.groupdict() if m else {}

@staticmethod
def instance_path(
project: str,
Expand Down Expand Up @@ -2771,6 +2795,115 @@ def sample_list_backup_operations():
# Done; return the response.
return response

def list_database_roles(
self,
request: Union[spanner_database_admin.ListDatabaseRolesRequest, dict] = None,
*,
parent: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListDatabaseRolesPager:
r"""Lists Cloud Spanner database roles.
.. code-block:: python
from google.cloud import spanner_admin_database_v1
def sample_list_database_roles():
# Create a client
client = spanner_admin_database_v1.DatabaseAdminClient()
# Initialize request argument(s)
request = spanner_admin_database_v1.ListDatabaseRolesRequest(
parent="parent_value",
)
# Make the request
page_result = client.list_database_roles(request=request)
# Handle the response
for response in page_result:
print(response)
Args:
request (Union[google.cloud.spanner_admin_database_v1.types.ListDatabaseRolesRequest, dict]):
The request object. The request for
[ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles].
parent (str):
Required. The database whose roles should be listed.
Values are of the form
``projects/<project>/instances/<instance>/databases/<database>/databaseRoles``.
This corresponds to the ``parent`` 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.cloud.spanner_admin_database_v1.services.database_admin.pagers.ListDatabaseRolesPager:
The response for
[ListDatabaseRoles][google.spanner.admin.database.v1.DatabaseAdmin.ListDatabaseRoles].
Iterating over this object will yield results and
resolve additional pages automatically.
"""
# 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])
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 spanner_database_admin.ListDatabaseRolesRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, spanner_database_admin.ListDatabaseRolesRequest):
request = spanner_database_admin.ListDatabaseRolesRequest(request)
# If we have keyword arguments corresponding to fields on the
# request, apply these.
if parent is not None:
request.parent = parent

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

# 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,
)

# This method is paged; wrap the response in a pager, which provides
# an `__iter__` convenience method.
response = pagers.ListDatabaseRolesPager(
method=rpc,
request=request,
response=response,
metadata=metadata,
)

# Done; return the response.
return response

def __enter__(self):
return self

Expand Down
Loading

0 comments on commit 3867882

Please sign in to comment.