Skip to content

Commit

Permalink
create authorized view on client instead of table
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Oct 31, 2024
1 parent 8296471 commit ec5f462
Showing 1 changed file with 46 additions and 62 deletions.
108 changes: 46 additions & 62 deletions google/cloud/bigtable/data/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,52 @@ def get_table(self, instance_id: str, table_id: str, *args, **kwargs) -> TableAs
"""
return TableAsync(self, instance_id, table_id, *args, **kwargs)

def get_authorized_view(
self, instance_id: str, table_id: str, view_id: str, *args, **kwargs
) -> AuthorizedViewAsync:
"""
Returns an authorized view nstance for making data API requests. All arguments are passed
directly to the AuthorizedViewAsync constructor.
Args:
instance_id: The Bigtable instance ID to associate with this client.
instance_id is combined with the client's project to fully
specify the instance
table_id: The ID of the table. table_id is combined with the
instance_id and the client's project to fully specify the table
view_id: The id for the authorized view to use for requests
app_profile_id: The app profile to associate with requests.
https://cloud.google.com/bigtable/docs/app-profiles
default_read_rows_operation_timeout: The default timeout for read rows
operations, in seconds. If not set, defaults to Table's value
default_read_rows_attempt_timeout: The default timeout for individual
read rows rpc requests, in seconds. If not set, defaults Table's value
default_mutate_rows_operation_timeout: The default timeout for mutate rows
operations, in seconds. If not set, defaults to Table's value
default_mutate_rows_attempt_timeout: The default timeout for individual
mutate rows rpc requests, in seconds. If not set, defaults Table's value
default_operation_timeout: The default timeout for all other operations, in
seconds. If not set, defaults to Table's value
default_attempt_timeout: The default timeout for all other individual rpc
requests, in seconds. If not set, defaults to Table's value
default_read_rows_retryable_errors: a list of errors that will be retried
if encountered during read_rows and related operations. If not set,
defaults to Table's value
default_mutate_rows_retryable_errors: a list of errors that will be retried
if encountered during mutate_rows and related operations. If not set,
defaults to Table's value
default_retryable_errors: a list of errors that will be retried if
encountered during all other operations. If not set, defaults to
Table's value
Returns:
AuthorizedViewAsync: a table instance for making data API requests
Raises:
RuntimeError: If called outside an async context (no running event loop)
"""
return AuthorizedViewAsync(
self, instance_id, table_id, view_id, *args, **kwargs,
)

async def execute_query(
self,
query: str,
Expand Down Expand Up @@ -1382,68 +1428,6 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
"""
await self.close()

def get_authorized_view(
self, view_id: str, app_profile_id: str | None = None, **kwargs
) -> AuthorizedViewAsync:
"""
Returns a table instance for making data API requests. All arguments are passed
directly to the TableAsync constructor.
Args:
view_id: The id for the authorized view to use for requests
app_profile_id: The app profile to associate with requests.
https://cloud.google.com/bigtable/docs/app-profiles
default_read_rows_operation_timeout: The default timeout for read rows
operations, in seconds. If not set, defaults to Table's value
default_read_rows_attempt_timeout: The default timeout for individual
read rows rpc requests, in seconds. If not set, defaults Table's value
default_mutate_rows_operation_timeout: The default timeout for mutate rows
operations, in seconds. If not set, defaults to Table's value
default_mutate_rows_attempt_timeout: The default timeout for individual
mutate rows rpc requests, in seconds. If not set, defaults Table's value
default_operation_timeout: The default timeout for all other operations, in
seconds. If not set, defaults to Table's value
default_attempt_timeout: The default timeout for all other individual rpc
requests, in seconds. If not set, defaults to Table's value
default_read_rows_retryable_errors: a list of errors that will be retried
if encountered during read_rows and related operations. If not set,
defaults to Table's value
default_mutate_rows_retryable_errors: a list of errors that will be retried
if encountered during mutate_rows and related operations. If not set,
defaults to Table's value
default_retryable_errors: a list of errors that will be retried if
encountered during all other operations. If not set, defaults to
Table's value
Returns:
AuthorizedViewAsync: a table instance for making data API requests
Raises:
RuntimeError: If called outside an async context (no running event loop)
"""
# pull out default values from table if not passed
defaults = [
"default_read_rows_operation_timeout",
"default_read_rows_attempt_timeout",
"default_read_rows_retryable_errors",
"default_mutate_rows_operation_timeout",
"default_mutate_rows_attempt_timeout",
"default_mutate_rows_retryable_errors",
"default_operation_timeout",
"default_attempt_timeout",
"default_retryable_errors",
]
for arg_name in defaults:
if arg_name not in kwargs:
kwargs[arg_name] = getattr(self, arg_name)

return AuthorizedViewAsync(
self.client,
self.instance_id,
self.table_id,
view_id,
self.app_profile_id,
**kwargs,
)


class AuthorizedViewAsync(TableAsync):
def __init__(
Expand Down

0 comments on commit ec5f462

Please sign in to comment.