Skip to content

Commit 283a419

Browse files
Aaron Gabriel Neyertseavercojenco
authored
fix: changeover unspecified to inherited (#603)
* fix: changeover unspecified to inherited * Update google/cloud/storage/bucket.py Co-authored-by: Tres Seaver <[email protected]> * Apply suggestions from code review Co-authored-by: Tres Seaver <[email protected]> * remove dup line * Apply suggestions from code review Co-authored-by: Tres Seaver <[email protected]> * Update tests/unit/test_bucket.py Co-authored-by: cojenco <[email protected]> * lint fix * one more lint fix * line Co-authored-by: Tres Seaver <[email protected]> Co-authored-by: cojenco <[email protected]>
1 parent 6da06f9 commit 283a419

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

google/cloud/storage/bucket.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from google.cloud.storage.constants import MULTI_REGIONAL_LEGACY_STORAGE_CLASS
5252
from google.cloud.storage.constants import MULTI_REGION_LOCATION_TYPE
5353
from google.cloud.storage.constants import NEARLINE_STORAGE_CLASS
54-
from google.cloud.storage.constants import PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
54+
from google.cloud.storage.constants import PUBLIC_ACCESS_PREVENTION_INHERITED
5555
from google.cloud.storage.constants import REGIONAL_LEGACY_STORAGE_CLASS
5656
from google.cloud.storage.constants import REGION_LOCATION_TYPE
5757
from google.cloud.storage.constants import STANDARD_STORAGE_CLASS
@@ -387,8 +387,7 @@ class IAMConfiguration(dict):
387387
388388
:type public_access_prevention: str
389389
:params public_access_prevention:
390-
(Optional) Whether the public access prevention policy is 'unspecified' (default) or 'enforced'
391-
See: https://cloud.google.com/storage/docs/public-access-prevention
390+
(Optional) Whether the public access prevention policy is 'inherited' (default) or 'enforced'
392391
See: https://cloud.google.com/storage/docs/public-access-prevention
393392
394393
:type uniform_bucket_level_access_enabled: bool
@@ -438,7 +437,7 @@ def __init__(
438437
uniform_bucket_level_access_enabled = False
439438

440439
if public_access_prevention is _default:
441-
public_access_prevention = PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
440+
public_access_prevention = PUBLIC_ACCESS_PREVENTION_INHERITED
442441

443442
data = {
444443
"uniformBucketLevelAccess": {
@@ -481,11 +480,12 @@ def bucket(self):
481480

482481
@property
483482
def public_access_prevention(self):
484-
"""Setting for public access prevention policy. Options are 'unspecified' (default) or 'enforced'.
485-
More information can be found at https://cloud.google.com/storage/docs/public-access-prevention
483+
"""Setting for public access prevention policy. Options are 'inherited' (default) or 'enforced'.
484+
485+
See: https://cloud.google.com/storage/docs/public-access-prevention
486486
487487
:rtype: string
488-
:returns: the public access prevention status, either 'enforced' or 'unspecified'.
488+
:returns: the public access prevention status, either 'enforced' or 'inherited'.
489489
"""
490490
return self["publicAccessPrevention"]
491491

google/cloud/storage/constants.py

+8
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,13 @@
107107
PUBLIC_ACCESS_PREVENTION_UNSPECIFIED = "unspecified"
108108
"""Unspecified public access prevention value.
109109
110+
DEPRECATED: Use 'PUBLIC_ACCESS_PREVENTION_INHERITED' instead.
111+
112+
See: https://cloud.google.com/storage/docs/public-access-prevention
113+
"""
114+
115+
PUBLIC_ACCESS_PREVENTION_INHERITED = "inherited"
116+
"""Inherited public access prevention value.
117+
110118
See: https://cloud.google.com/storage/docs/public-access-prevention
111119
"""

tests/system/test_bucket.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -806,22 +806,22 @@ def test_ubla_set_unset_preserves_acls(
806806
assert blob_acl_before == blob_acl_after
807807

808808

809-
@pytest.mark.skip(reason="Unspecified PAP is changing to inherited")
810-
def test_new_bucket_created_w_unspecified_pap(
809+
def test_new_bucket_created_w_inherited_pap(
811810
storage_client, buckets_to_delete, blobs_to_delete,
812811
):
813812
from google.cloud.storage import constants
814813

815-
bucket_name = _helpers.unique_name("new-w-pap-unspecified")
814+
bucket_name = _helpers.unique_name("new-w-pap-inherited")
816815
bucket = storage_client.bucket(bucket_name)
817816
bucket.iam_configuration.uniform_bucket_level_access_enabled = True
818817
bucket.create()
819818
buckets_to_delete.append(bucket)
820819

821-
assert (
822-
bucket.iam_configuration.public_access_prevention
823-
== constants.PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
824-
)
820+
# TODO: Remove unspecified after changeover is complete
821+
assert bucket.iam_configuration.public_access_prevention in [
822+
constants.PUBLIC_ACCESS_PREVENTION_UNSPECIFIED,
823+
constants.PUBLIC_ACCESS_PREVENTION_INHERITED,
824+
]
825825

826826
bucket.iam_configuration.public_access_prevention = (
827827
constants.PUBLIC_ACCESS_PREVENTION_ENFORCED
@@ -876,12 +876,13 @@ def test_new_bucket_created_w_enforced_pap(
876876
)
877877

878878
bucket.iam_configuration.public_access_prevention = (
879-
constants.PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
879+
constants.PUBLIC_ACCESS_PREVENTION_INHERITED
880880
)
881881
bucket.patch()
882882

883-
assert (
884-
bucket.iam_configuration.public_access_prevention
885-
== constants.PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
886-
)
883+
# TODO: Remove unspecified after changeover is complete
884+
assert bucket.iam_configuration.public_access_prevention in [
885+
constants.PUBLIC_ACCESS_PREVENTION_UNSPECIFIED,
886+
constants.PUBLIC_ACCESS_PREVENTION_INHERITED,
887+
]
887888
assert not bucket.iam_configuration.uniform_bucket_level_access_enabled

tests/unit/test_bucket.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from google.cloud.storage.retry import DEFAULT_RETRY_IF_GENERATION_SPECIFIED
2424
from google.cloud.storage.retry import DEFAULT_RETRY_IF_METAGENERATION_SPECIFIED
2525
from google.cloud.storage.constants import PUBLIC_ACCESS_PREVENTION_ENFORCED
26+
from google.cloud.storage.constants import PUBLIC_ACCESS_PREVENTION_INHERITED
2627
from google.cloud.storage.constants import PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
2728

2829

@@ -358,8 +359,10 @@ def test_ctor_defaults(self):
358359
self.assertIs(config.bucket, bucket)
359360
self.assertFalse(config.uniform_bucket_level_access_enabled)
360361
self.assertIsNone(config.uniform_bucket_level_access_locked_time)
361-
self.assertEqual(
362-
config.public_access_prevention, PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
362+
# TODO: Remove unspecified after changeover is complete
363+
self.assertIn(
364+
config.public_access_prevention,
365+
[PUBLIC_ACCESS_PREVENTION_UNSPECIFIED, PUBLIC_ACCESS_PREVENTION_INHERITED],
363366
)
364367
self.assertFalse(config.bucket_policy_only_enabled)
365368
self.assertIsNone(config.bucket_policy_only_locked_time)
@@ -396,9 +399,11 @@ def test_ctor_explicit_pap(self):
396399
config.public_access_prevention, PUBLIC_ACCESS_PREVENTION_ENFORCED
397400
)
398401

399-
config.public_access_prevention = PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
400-
self.assertEqual(
401-
config.public_access_prevention, PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
402+
config.public_access_prevention = PUBLIC_ACCESS_PREVENTION_INHERITED
403+
# TODO: Remove unspecified after changeover is complete
404+
self.assertIn(
405+
config.public_access_prevention,
406+
[PUBLIC_ACCESS_PREVENTION_UNSPECIFIED, PUBLIC_ACCESS_PREVENTION_INHERITED],
402407
)
403408

404409
def test_ctor_explicit_bpo(self):

0 commit comments

Comments
 (0)