Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] feat: support authorized views #1034

Draft
wants to merge 24 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f9c7dc8
add authorized view field to TableAsync
daniel-sanche Oct 28, 2024
f143377
add AuthorizedView as Table subclass
daniel-sanche Oct 28, 2024
ce4351a
ran blacken
daniel-sanche Oct 28, 2024
6a679e0
simplified authorized view defaults
daniel-sanche Oct 28, 2024
cd9df24
use protos to pass in authroized view name
daniel-sanche Oct 29, 2024
8296471
fixed existing tests
daniel-sanche Oct 29, 2024
ec5f462
create authorized view on client instead of table
daniel-sanche Oct 31, 2024
9b6cadf
made base class for table and authorized_view
daniel-sanche Oct 31, 2024
5bbf56c
added docs file
daniel-sanche Nov 7, 2024
7c02dc0
Merge branch 'main' into authorized_views
daniel-sanche Nov 12, 2024
d739797
fixed merge error
daniel-sanche Nov 12, 2024
77de052
Merge branch 'main' into authorized_views
daniel-sanche Nov 22, 2024
7831dc8
made async agnostic
daniel-sanche Nov 22, 2024
a8b93cf
fixed indentation
daniel-sanche Nov 22, 2024
6e38d43
fixed merge loss
daniel-sanche Nov 22, 2024
908a3ab
ran black
daniel-sanche Nov 22, 2024
6f81541
removed union
daniel-sanche Nov 22, 2024
3139eb9
use _request_path for either view or table
daniel-sanche Nov 23, 2024
d199a88
run system tests against both table and view
daniel-sanche Nov 23, 2024
d362892
added docs page for authorized views
daniel-sanche Nov 28, 2024
c710d5a
fixed authorized view permissions in system test
daniel-sanche Dec 3, 2024
0bc88b9
added system test for auth denied
daniel-sanche Dec 4, 2024
e95ba0d
added TestAuthorizedView unit test class
daniel-sanche Dec 4, 2024
f46e6ef
run tests with both table and view
daniel-sanche Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/async_data_client/async_data_authorized_view.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Authorized View Async
~~~~~~~~~~~~~~~~~~~~~

.. note::

It is generally not recommended to use the async client in an otherwise synchronous codebase. To make use of asyncio's
performance benefits, the codebase should be designed to be async from the ground up.

.. autoclass:: google.cloud.bigtable.data._async.client.AuthorizedViewAsync
:members:
:inherited-members:
2 changes: 1 addition & 1 deletion docs/async_data_client/async_data_table.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Table Async

.. autoclass:: google.cloud.bigtable.data._async.client.TableAsync
:members:
:show-inheritance:
:inherited-members:
1 change: 1 addition & 0 deletions docs/async_data_client/async_data_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Async Data Client

async_data_client
async_data_table
async_data_authorized_view
async_data_mutations_batcher
async_data_read_rows_query
async_data_row
Expand Down
25 changes: 15 additions & 10 deletions google/cloud/bigtable/data/_async/_mutate_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from __future__ import annotations

from typing import Sequence, TYPE_CHECKING
import functools

from google.api_core import exceptions as core_exceptions
from google.api_core import retry as retries
import google.cloud.bigtable_v2.types.bigtable as types_pb
import google.cloud.bigtable.data.exceptions as bt_exceptions
from google.cloud.bigtable.data._helpers import _attempt_timeout_generator
from google.cloud.bigtable.data._helpers import _retry_exception_factory
Expand All @@ -36,11 +36,17 @@
from google.cloud.bigtable_v2.services.bigtable.async_client import (
BigtableAsyncClient as GapicClientType,
)
from google.cloud.bigtable_v2.services.bigtable.client import ( # type: ignore
_ApiSurfaceAsync as ApiSurfaceType,
)
from google.cloud.bigtable.data._async.client import TableAsync as TableType
else:
from google.cloud.bigtable_v2.services.bigtable.client import ( # type: ignore
BigtableClient as GapicClientType,
)
from google.cloud.bigtable_v2.services.bigtable.client import ( # type: ignore
_ApiSurface as ApiSurfaceType,
)
from google.cloud.bigtable.data._sync_autogen.client import Table as TableType # type: ignore

__CROSS_SYNC_OUTPUT__ = "google.cloud.bigtable.data._sync_autogen._mutate_rows"
Expand Down Expand Up @@ -70,7 +76,7 @@ class _MutateRowsOperationAsync:
def __init__(
self,
gapic_client: GapicClientType,
table: TableType,
table: ApiSurfaceType,
mutation_entries: list["RowMutationEntry"],
operation_timeout: float,
attempt_timeout: float | None,
Expand All @@ -84,13 +90,8 @@ def __init__(
f"{_MUTATE_ROWS_REQUEST_MUTATION_LIMIT} mutations across "
f"all entries. Found {total_mutations}."
)
# create partial function to pass to trigger rpc call
self._gapic_fn = functools.partial(
gapic_client.mutate_rows,
table_name=table.table_name,
app_profile_id=table.app_profile_id,
retry=None,
)
self._table = table
self._gapic_fn = gapic_client.mutate_rows
# create predicate for determining which errors are retryable
self.is_retryable = retries.if_exception_type(
# RPC level errors
Expand Down Expand Up @@ -173,8 +174,12 @@ async def _run_attempt(self):
# make gapic request
try:
result_generator = await self._gapic_fn(
request=types_pb.MutateRowsRequest(
entries=request_entries,
app_profile_id=self._table.app_profile_id,
**self._table._request_path,
),
timeout=next(self.timeout_generator),
entries=request_entries,
retry=None,
)
async for result_list in result_generator:
Expand Down
10 changes: 6 additions & 4 deletions google/cloud/bigtable/data/_async/_read_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@

if TYPE_CHECKING:
if CrossSync.is_async:
from google.cloud.bigtable.data._async.client import TableAsync as TableType
from google.cloud.bigtable.data._async.client import (
_ApiSurfaceAsync as ApiSurfaceType,
)
else:
from google.cloud.bigtable.data._sync_autogen.client import Table as TableType # type: ignore
from google.cloud.bigtable.data._sync_autogen.client import _ApiSurface as ApiSurfaceType # type: ignore

__CROSS_SYNC_OUTPUT__ = "google.cloud.bigtable.data._sync_autogen._read_rows"

Expand Down Expand Up @@ -78,7 +80,7 @@ class _ReadRowsOperationAsync:
def __init__(
self,
query: ReadRowsQuery,
table: TableType,
table: ApiSurfaceType,
operation_timeout: float,
attempt_timeout: float,
retryable_exceptions: Sequence[type[Exception]] = (),
Expand All @@ -90,7 +92,7 @@ def __init__(
if isinstance(query, dict):
self.request = ReadRowsRequestPB(
**query,
table_name=table.table_name,
**table._request_path,
app_profile_id=table.app_profile_id,
)
else:
Expand Down
Loading
Loading