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

feat: support authorized views #1034

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 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
dd337be
Merge branch 'main' into authorized_views
daniel-sanche Jan 10, 2025
39b7e44
added authorized view to docs
daniel-sanche Jan 10, 2025
362e070
fixed cross sync generation
daniel-sanche Jan 10, 2025
1f7a185
updated async code for sync generator
daniel-sanche Jan 10, 2025
81a3530
updated generated sync code
daniel-sanche Jan 10, 2025
e2136d1
fixed lint issues
daniel-sanche Jan 10, 2025
6cca1e9
fixed unit tests
daniel-sanche Jan 11, 2025
1779a79
added docs file for sync authorized views
daniel-sanche Jan 11, 2025
ba9dda4
fixed mypy issue
daniel-sanche Jan 11, 2025
b3ac6bb
add authorized view to __init__.py
daniel-sanche Jan 13, 2025
131c3c7
fixed typo
daniel-sanche Jan 13, 2025
7ba0f50
fixed duplicate import
daniel-sanche Jan 13, 2025
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
6 changes: 5 additions & 1 deletion .cross_sync/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ def visit_FunctionDef(self, node):

def visit_Constant(self, node):
"""Replace string type annotations"""
node.s = self.replacements.get(node.s, node.s)
try:
node.s = self.replacements.get(node.s, node.s)
except TypeError:
# ignore unhashable types (e.g. list)
pass
return node


Expand Down
11 changes: 11 additions & 0 deletions docs/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/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:
2 changes: 2 additions & 0 deletions docs/data_client/data_client_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Sync Surface

sync_data_client
sync_data_table
sync_data_authorized_view
sync_data_mutations_batcher
sync_data_execute_query_iterator

Expand All @@ -20,6 +21,7 @@ Async Surface

async_data_client
async_data_table
async_data_authorized_view
async_data_mutations_batcher
async_data_execute_query_iterator

Expand Down
6 changes: 6 additions & 0 deletions docs/data_client/sync_data_authorized_view.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Authorized View
~~~~~~~~~~~~~~~

.. autoclass:: google.cloud.bigtable.data._sync_autogen.client.AuthorizedView
:members:
:inherited-members:
4 changes: 4 additions & 0 deletions google/cloud/bigtable/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

from google.cloud.bigtable.data._async.client import BigtableDataClientAsync
from google.cloud.bigtable.data._async.client import TableAsync
from google.cloud.bigtable.data._async.client import AuthorizedViewAsync
from google.cloud.bigtable.data._async.mutations_batcher import MutationsBatcherAsync
from google.cloud.bigtable.data._sync_autogen.client import BigtableDataClient
from google.cloud.bigtable.data._sync_autogen.client import Table
from google.cloud.bigtable.data._sync_autogen.client import AuthorizedView
from google.cloud.bigtable.data._sync_autogen.mutations_batcher import MutationsBatcher

from google.cloud.bigtable.data.read_rows_query import ReadRowsQuery
Expand Down Expand Up @@ -76,9 +78,11 @@
__all__ = (
"BigtableDataClientAsync",
"TableAsync",
"AuthorizedViewAsync",
"MutationsBatcherAsync",
"BigtableDataClient",
"Table",
"AuthorizedView",
"MutationsBatcher",
"RowKeySamples",
"ReadRowsQuery",
Expand Down
27 changes: 15 additions & 12 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,12 +36,16 @@
from google.cloud.bigtable_v2.services.bigtable.async_client import (
BigtableAsyncClient as GapicClientType,
)
from google.cloud.bigtable.data._async.client import TableAsync as TableType
from google.cloud.bigtable.data._async.client import ( # type: ignore
_ApiSurfaceAsync as ApiSurfaceType,
)
else:
from google.cloud.bigtable_v2.services.bigtable.client import ( # type: ignore
BigtableClient as GapicClientType,
)
from google.cloud.bigtable.data._sync_autogen.client import Table as TableType # type: ignore
from google.cloud.bigtable.data._sync_autogen.client import ( # type: ignore
_ApiSurface as ApiSurfaceType,
)

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

Expand Down Expand Up @@ -70,7 +74,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 +88,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 +172,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