Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e90c44a

Browse filesBrowse files
Aaron Gabriel Neyercojenco
andauthored
fix: update samples for pap, unspecified -> inherited (GoogleCloudPlatform#6757)
* fix: update samples for pap, unspecified->inherited * restore original unspecified while adding new inherited * woops, missed a place * remove test skip GoogleCloudPlatform#6750 * lint fix * oops * Update storage/cloud-client/storage_set_public_access_prevention_inherited.py Co-authored-by: cojenco <cathyo@google.com> * add top level comment * move comment above regionalization tag * update version * change over unspecified test to inherited * this one too * skip inconsistent tests Co-authored-by: cojenco <cathyo@google.com>
1 parent ecae6ea commit e90c44a
Copy full SHA for e90c44a

File tree

Expand file treeCollapse file tree

4 files changed

+69
-25
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+69
-25
lines changed

‎storage/cloud-client/public_access_prevention_test.py

Copy file name to clipboardExpand all lines: storage/cloud-client/public_access_prevention_test.py
+16-22Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,35 @@
1616

1717
import storage_get_public_access_prevention
1818
import storage_set_public_access_prevention_enforced
19+
import storage_set_public_access_prevention_inherited
1920
import storage_set_public_access_prevention_unspecified
2021

2122

22-
@pytest.mark.skip(reason="Unspecified PAP is changing to inherited")
23+
@pytest.mark.skip(reason="Inconsistent due to unspecified->inherited change")
2324
def test_get_public_access_prevention(bucket, capsys):
2425
short_name = storage_get_public_access_prevention
25-
short_name.get_public_access_prevention(
26-
bucket.name
27-
)
26+
short_name.get_public_access_prevention(bucket.name)
2827
out, _ = capsys.readouterr()
29-
assert (
30-
f"Public access prevention is unspecified for {bucket.name}."
31-
in out
32-
)
28+
assert f"Public access prevention is inherited for {bucket.name}." in out
3329

3430

3531
def test_set_public_access_prevention_enforced(bucket, capsys):
3632
short_name = storage_set_public_access_prevention_enforced
37-
short_name.set_public_access_prevention_enforced(
38-
bucket.name
39-
)
33+
short_name.set_public_access_prevention_enforced(bucket.name)
4034
out, _ = capsys.readouterr()
41-
assert (
42-
f"Public access prevention is set to enforced for {bucket.name}."
43-
in out
44-
)
35+
assert f"Public access prevention is set to enforced for {bucket.name}." in out
4536

4637

38+
@pytest.mark.skip(reason="Inconsistent due to unspecified->inherited change")
4739
def test_set_public_access_prevention_unspecified(bucket, capsys):
4840
short_name = storage_set_public_access_prevention_unspecified
49-
short_name.set_public_access_prevention_unspecified(
50-
bucket.name
51-
)
41+
short_name.set_public_access_prevention_unspecified(bucket.name)
5242
out, _ = capsys.readouterr()
53-
assert (
54-
f"Public access prevention is 'unspecified' for {bucket.name}."
55-
in out
56-
)
43+
assert f"Public access prevention is 'unspecified' for {bucket.name}." in out
44+
45+
46+
def test_set_public_access_prevention_inherited(bucket, capsys):
47+
short_name = storage_set_public_access_prevention_inherited
48+
short_name.set_public_access_prevention_inherited(bucket.name)
49+
out, _ = capsys.readouterr()
50+
assert f"Public access prevention is 'inherited' for {bucket.name}." in out

‎storage/cloud-client/requirements.txt

Copy file name to clipboard
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
google-cloud-pubsub==2.8.0
2-
google-cloud-storage==1.42.2
3-
google-api-python-client==2.23.0
2+
google-cloud-storage==1.42.3
3+
google-api-python-client==2.23.0

‎storage/cloud-client/storage_get_public_access_prevention.py

Copy file name to clipboardExpand all lines: storage/cloud-client/storage_get_public_access_prevention.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
def get_public_access_prevention(bucket_name):
24-
"""Gets the public access prevention setting (either 'unspecified' or 'enforced') for a bucket."""
24+
"""Gets the public access prevention setting (either 'inherited' or 'enforced') for a bucket."""
2525
# The ID of your GCS bucket
2626
# bucket_name = "my-bucket"
2727

+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2021 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the 'License');
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import sys
18+
19+
"""Sample that sets public access prevention to inherited.
20+
This sample is used on this page:
21+
https://cloud.google.com/storage/docs/using-public-access-prevention
22+
For more information, see README.md.
23+
"""
24+
25+
# [START storage_set_public_access_prevention_inherited]
26+
27+
from google.cloud import storage
28+
from google.cloud.storage.constants import PUBLIC_ACCESS_PREVENTION_INHERITED
29+
30+
31+
def set_public_access_prevention_inherited(bucket_name):
32+
"""Sets the public access prevention status to inherited, so that the bucket inherits its setting from its parent project."""
33+
# The ID of your GCS bucket
34+
# bucket_name = "my-bucket"
35+
36+
storage_client = storage.Client()
37+
bucket = storage_client.get_bucket(bucket_name)
38+
39+
bucket.iam_configuration.public_access_prevention = (
40+
PUBLIC_ACCESS_PREVENTION_INHERITED
41+
)
42+
bucket.patch()
43+
44+
print(f"Public access prevention is 'inherited' for {bucket.name}.")
45+
46+
47+
# [END storage_set_public_access_prevention_inherited]
48+
49+
if __name__ == "__main__":
50+
set_public_access_prevention_inherited(bucket_name=sys.argv[1])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.