Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(storage): support optionsRequestedPolicyVersion#9989
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
583ca42
iam proposal #3
jkwlui 7a9bc44
feat(storage): support requested_policy_version for get_iam_policy
jkwlui 33898d7
add system-test
jkwlui 2dd85e1
add ref doc sample to get_iam_policy
jkwlui 4077045
add requested_policy_version to blob
jkwlui c210d29
fix tests
jkwlui cc717bd
nit: typo
jkwlui bc2f40a
Merge branch 'master' into storage-policy-version
jkwlui 62b003a
blacken
jkwlui 70a1886
fix docs build
jkwlui 27c3e6a
format docs
jkwlui a17cbc1
remove unused variables
jkwlui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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 |
|---|---|---|
| @@ -262,6 +262,66 @@ def test_bucket_update_labels(self): | ||
| bucket.update() | ||
| self.assertEqual(bucket.labels, {}) | ||
| def test_get_set_iam_policy(self): | ||
| import pytest | ||
| from google.cloud.storage.iam import STORAGE_OBJECT_VIEWER_ROLE | ||
| from google.api_core.exceptions import BadRequest, PreconditionFailed | ||
| bucket_name = "iam-policy" + unique_resource_id("-") | ||
| bucket = retry_429_503(Config.CLIENT.create_bucket)(bucket_name) | ||
| self.case_buckets_to_delete.append(bucket_name) | ||
| self.assertTrue(bucket.exists()) | ||
| policy_no_version = bucket.get_iam_policy() | ||
| self.assertEqual(policy_no_version.version, 1) | ||
| policy = bucket.get_iam_policy(requested_policy_version=3) | ||
| self.assertEqual(policy, policy_no_version) | ||
| member = "serviceAccount:{}".format(Config.CLIENT.get_service_account_email()) | ||
| BINDING_W_CONDITION = { | ||
| "role": STORAGE_OBJECT_VIEWER_ROLE, | ||
| "members": {member}, | ||
jkwlui marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| "condition": { | ||
| "title": "always-true", | ||
| "description": "test condition always-true", | ||
| "expression": "true", | ||
| }, | ||
| } | ||
| policy.bindings.append(BINDING_W_CONDITION) | ||
| with pytest.raises( | ||
| PreconditionFailed, match="enable uniform bucket-level access" | ||
| ): | ||
| bucket.set_iam_policy(policy) | ||
| bucket.iam_configuration.uniform_bucket_level_access_enabled = True | ||
| bucket.patch() | ||
| policy = bucket.get_iam_policy(requested_policy_version=3) | ||
| policy.bindings.append(BINDING_W_CONDITION) | ||
| with pytest.raises(BadRequest, match="at least 3"): | ||
| bucket.set_iam_policy(policy) | ||
| policy.version = 3 | ||
| returned_policy = bucket.set_iam_policy(policy) | ||
| self.assertEqual(returned_policy.version, 3) | ||
| self.assertEqual(returned_policy.bindings, policy.bindings) | ||
| with pytest.raises( | ||
| BadRequest, match="cannot be less than the existing policy version" | ||
| ): | ||
| bucket.get_iam_policy() | ||
| with pytest.raises( | ||
| BadRequest, match="cannot be less than the existing policy version" | ||
| ): | ||
| bucket.get_iam_policy(requested_policy_version=2) | ||
| fetched_policy = bucket.get_iam_policy(requested_policy_version=3) | ||
| self.assertEqual(fetched_policy.bindings, returned_policy.bindings) | ||
| @unittest.skipUnless(USER_PROJECT, "USER_PROJECT not set in environment.") | ||
| def test_crud_bucket_with_requester_pays(self): | ||
| new_bucket_name = "w-requester-pays" + unique_resource_id("-") | ||
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 |
|---|---|---|
| @@ -2023,7 +2023,7 @@ def test_get_iam_policy(self): | ||
| NAME = "name" | ||
| PATH = "/b/%s" % (NAME,) | ||
| ETAG = "DEADBEEF" | ||
| VERSION = 17 | ||
| VERSION = 1 | ||
| OWNER1 = "user:phred@example.com" | ||
| OWNER2 = "group:cloud-logs@google.com" | ||
| EDITOR1 = "domain:google.com" | ||
| @@ -2067,7 +2067,7 @@ def test_get_iam_policy_w_user_project(self): | ||
| USER_PROJECT = "user-project-123" | ||
| PATH = "/b/%s" % (NAME,) | ||
| ETAG = "DEADBEEF" | ||
| VERSION = 17 | ||
| VERSION = 1 | ||
| RETURNED = { | ||
| "resourceId": PATH, | ||
| "etag": ETAG, | ||
| @@ -2092,6 +2092,35 @@ def test_get_iam_policy_w_user_project(self): | ||
| self.assertEqual(kw[0]["path"], "%s/iam" % (PATH,)) | ||
| self.assertEqual(kw[0]["query_params"], {"userProject": USER_PROJECT}) | ||
| def test_get_iam_policy_w_requested_policy_version(self): | ||
| from google.cloud.storage.iam import STORAGE_OWNER_ROLE | ||
| NAME = "name" | ||
| PATH = "/b/%s" % (NAME,) | ||
| ETAG = "DEADBEEF" | ||
| VERSION = 1 | ||
| OWNER1 = "user:phred@example.com" | ||
| OWNER2 = "group:cloud-logs@google.com" | ||
| RETURNED = { | ||
| "resourceId": PATH, | ||
| "etag": ETAG, | ||
| "version": VERSION, | ||
| "bindings": [{"role": STORAGE_OWNER_ROLE, "members": [OWNER1, OWNER2]}], | ||
| } | ||
| connection = _Connection(RETURNED) | ||
| client = _Client(connection, None) | ||
| bucket = self._make_one(client=client, name=NAME) | ||
| policy = bucket.get_iam_policy(requested_policy_version=3) | ||
| self.assertEqual(policy.version, VERSION) | ||
| kw = connection._requested | ||
| self.assertEqual(len(kw), 1) | ||
| self.assertEqual(kw[0]["method"], "GET") | ||
| self.assertEqual(kw[0]["path"], "%s/iam" % (PATH,)) | ||
| self.assertEqual(kw[0]["query_params"], {"optionsRequestedPolicyVersion": 3}) | ||
| def test_set_iam_policy(self): | ||
| import operator | ||
| from google.cloud.storage.iam import STORAGE_OWNER_ROLE | ||
| @@ -2102,7 +2131,7 @@ def test_set_iam_policy(self): | ||
| NAME = "name" | ||
| PATH = "/b/%s" % (NAME,) | ||
| ETAG = "DEADBEEF" | ||
| VERSION = 17 | ||
| VERSION = 1 | ||
| OWNER1 = "user:phred@example.com" | ||
| OWNER2 = "group:cloud-logs@google.com" | ||
| EDITOR1 = "domain:google.com" | ||
| @@ -2155,7 +2184,7 @@ def test_set_iam_policy_w_user_project(self): | ||
| USER_PROJECT = "user-project-123" | ||
| PATH = "/b/%s" % (NAME,) | ||
| ETAG = "DEADBEEF" | ||
| VERSION = 17 | ||
| VERSION = 1 | ||
jkwlui marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| OWNER1 = "user:phred@example.com" | ||
| OWNER2 = "group:cloud-logs@google.com" | ||
| EDITOR1 = "domain:google.com" | ||
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.