5050from google .cloud .storage .constants import MULTI_REGIONAL_LEGACY_STORAGE_CLASS
5151from google .cloud .storage .constants import MULTI_REGION_LOCATION_TYPE
5252from google .cloud .storage .constants import NEARLINE_STORAGE_CLASS
53+ from google .cloud .storage .constants import PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
5354from google .cloud .storage .constants import REGIONAL_LEGACY_STORAGE_CLASS
5455from google .cloud .storage .constants import REGION_LOCATION_TYPE
5556from google .cloud .storage .constants import STANDARD_STORAGE_CLASS
@@ -383,6 +384,12 @@ class IAMConfiguration(dict):
383384 :type bucket: :class:`Bucket`
384385 :params bucket: Bucket for which this instance is the policy.
385386
387+ :type public_access_prevention: str
388+ :params public_access_prevention:
389+ (Optional) Whether the public access prevention policy is 'unspecified' (default) or 'enforced'
390+ See: https://cloud.google.com/storage/docs/public-access-prevention
391+ See: https://cloud.google.com/storage/docs/public-access-prevention
392+
386393 :type uniform_bucket_level_access_enabled: bool
387394 :params bucket_policy_only_enabled:
388395 (Optional) Whether the IAM-only policy is enabled for the bucket.
@@ -404,6 +411,7 @@ class IAMConfiguration(dict):
404411 def __init__ (
405412 self ,
406413 bucket ,
414+ public_access_prevention = _default ,
407415 uniform_bucket_level_access_enabled = _default ,
408416 uniform_bucket_level_access_locked_time = _default ,
409417 bucket_policy_only_enabled = _default ,
@@ -428,8 +436,14 @@ def __init__(
428436 if uniform_bucket_level_access_enabled is _default :
429437 uniform_bucket_level_access_enabled = False
430438
439+ if public_access_prevention is _default :
440+ public_access_prevention = PUBLIC_ACCESS_PREVENTION_UNSPECIFIED
441+
431442 data = {
432- "uniformBucketLevelAccess" : {"enabled" : uniform_bucket_level_access_enabled }
443+ "uniformBucketLevelAccess" : {
444+ "enabled" : uniform_bucket_level_access_enabled
445+ },
446+ "publicAccessPrevention" : public_access_prevention ,
433447 }
434448 if uniform_bucket_level_access_locked_time is not _default :
435449 data ["uniformBucketLevelAccess" ]["lockedTime" ] = _datetime_to_rfc3339 (
@@ -464,6 +478,21 @@ def bucket(self):
464478 """
465479 return self ._bucket
466480
481+ @property
482+ def public_access_prevention (self ):
483+ """Setting for public access prevention policy. Options are 'unspecified' (default) or 'enforced'.
484+ More information can be found at https://cloud.google.com/storage/docs/public-access-prevention
485+
486+ :rtype: string
487+ :returns: the public access prevention status, either 'enforced' or 'unspecified'.
488+ """
489+ return self ["publicAccessPrevention" ]
490+
491+ @public_access_prevention .setter
492+ def public_access_prevention (self , value ):
493+ self ["publicAccessPrevention" ] = value
494+ self .bucket ._patch_property ("iamConfiguration" , self )
495+
467496 @property
468497 def uniform_bucket_level_access_enabled (self ):
469498 """If set, access checks only use bucket-level IAM policies or above.
0 commit comments