-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(bigtable): add table level IAM policy controls #9877
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc2ad55
feat(bigtable): add table level IAM policy controls
emar-kar bf07a3c
remove extra lines
emar-kar 6242d8c
system test
emar-kar 850fcef
black
emar-kar c75e16c
fix system test
emar-kar 7e47443
update system-tests
emar-kar d0baead
chg comment lines
emar-kar 3ad4dfb
comment correction
emar-kar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1048,6 +1048,111 @@ def test_mutations_batcher_factory(self): | |
| self.assertEqual(mutation_batcher.flush_count, flush_count) | ||
| self.assertEqual(mutation_batcher.max_row_bytes, max_row_bytes) | ||
|
|
||
| def test_get_iam_policy(self): | ||
| from google.cloud.bigtable_admin_v2.gapic import bigtable_table_admin_client | ||
| from google.iam.v1 import policy_pb2 | ||
| from google.cloud.bigtable.policy import BIGTABLE_ADMIN_ROLE | ||
|
|
||
| credentials = _make_credentials() | ||
| client = self._make_client( | ||
| project="project-id", credentials=credentials, admin=True | ||
| ) | ||
| instance = client.instance(instance_id=self.INSTANCE_ID) | ||
| table = self._make_one(self.TABLE_ID, instance) | ||
|
|
||
| version = 1 | ||
| etag = b"etag_v1" | ||
| members = ["serviceAccount:[email protected]", "user:[email protected]"] | ||
| bindings = [{"role": BIGTABLE_ADMIN_ROLE, "members": members}] | ||
| iam_policy = policy_pb2.Policy(version=version, etag=etag, bindings=bindings) | ||
|
|
||
| table_api = mock.create_autospec( | ||
| bigtable_table_admin_client.BigtableTableAdminClient | ||
| ) | ||
| client._table_admin_client = table_api | ||
| table_api.get_iam_policy.return_value = iam_policy | ||
|
|
||
| result = table.get_iam_policy() | ||
|
|
||
| table_api.get_iam_policy.assert_called_once_with(resource=table.name) | ||
| self.assertEqual(result.version, version) | ||
| self.assertEqual(result.etag, etag) | ||
| admins = result.bigtable_admins | ||
| self.assertEqual(len(admins), len(members)) | ||
| for found, expected in zip(sorted(admins), sorted(members)): | ||
| self.assertEqual(found, expected) | ||
|
|
||
| def test_set_iam_policy(self): | ||
| from google.cloud.bigtable_admin_v2.gapic import bigtable_table_admin_client | ||
| from google.iam.v1 import policy_pb2 | ||
| from google.cloud.bigtable.policy import Policy | ||
| from google.cloud.bigtable.policy import BIGTABLE_ADMIN_ROLE | ||
|
|
||
| credentials = _make_credentials() | ||
| client = self._make_client( | ||
| project="project-id", credentials=credentials, admin=True | ||
| ) | ||
| instance = client.instance(instance_id=self.INSTANCE_ID) | ||
| table = self._make_one(self.TABLE_ID, instance) | ||
|
|
||
| version = 1 | ||
| etag = b"etag_v1" | ||
| members = ["serviceAccount:[email protected]", "user:[email protected]"] | ||
| bindings = [{"role": BIGTABLE_ADMIN_ROLE, "members": sorted(members)}] | ||
| iam_policy_pb = policy_pb2.Policy(version=version, etag=etag, bindings=bindings) | ||
|
|
||
| table_api = mock.create_autospec( | ||
| bigtable_table_admin_client.BigtableTableAdminClient | ||
| ) | ||
| client._table_admin_client = table_api | ||
| table_api.set_iam_policy.return_value = iam_policy_pb | ||
|
|
||
| iam_policy = Policy(etag=etag, version=version) | ||
| iam_policy[BIGTABLE_ADMIN_ROLE] = [ | ||
| Policy.user("[email protected]"), | ||
| Policy.service_account("[email protected]"), | ||
| ] | ||
|
|
||
| result = table.set_iam_policy(iam_policy) | ||
|
|
||
| table_api.set_iam_policy.assert_called_once_with( | ||
| resource=table.name, policy=iam_policy_pb | ||
| ) | ||
| self.assertEqual(result.version, version) | ||
| self.assertEqual(result.etag, etag) | ||
| admins = result.bigtable_admins | ||
| self.assertEqual(len(admins), len(members)) | ||
| for found, expected in zip(sorted(admins), sorted(members)): | ||
| self.assertEqual(found, expected) | ||
|
|
||
| def test_test_iam_permissions(self): | ||
| from google.cloud.bigtable_admin_v2.gapic import bigtable_table_admin_client | ||
| from google.iam.v1 import iam_policy_pb2 | ||
|
|
||
| credentials = _make_credentials() | ||
| client = self._make_client( | ||
| project="project-id", credentials=credentials, admin=True | ||
| ) | ||
| instance = client.instance(instance_id=self.INSTANCE_ID) | ||
| table = self._make_one(self.TABLE_ID, instance) | ||
|
|
||
| permissions = ["bigtable.tables.mutateRows", "bigtable.tables.readRows"] | ||
|
|
||
| response = iam_policy_pb2.TestIamPermissionsResponse(permissions=permissions) | ||
|
|
||
| table_api = mock.create_autospec( | ||
| bigtable_table_admin_client.BigtableTableAdminClient | ||
| ) | ||
| table_api.test_iam_permissions.return_value = response | ||
| client._table_admin_client = table_api | ||
|
|
||
| result = table.test_iam_permissions(permissions) | ||
|
|
||
| self.assertEqual(result, permissions) | ||
| table_api.test_iam_permissions.assert_called_once_with( | ||
| resource=table.name, permissions=permissions | ||
| ) | ||
|
|
||
|
|
||
| class Test__RetryableMutateRowsWorker(unittest.TestCase): | ||
| from grpc import StatusCode | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.