@@ -272,82 +272,6 @@ def from_api_repr(cls, resource):
272272 return instance
273273
274274
275- class IAMConfiguration (dict ):
276- """Map a bucket's IAM configuration.
277-
278- :type bucket: :class:`Bucket`
279- :params bucket: Bucket for which this instance is the policy.
280-
281- :type enabled: bool
282- :params enabled: (optional) whether the IAM-only policy is enabled for the bucket.
283-
284- :type locked_time: :class:`datetime.datetime`
285- :params locked_time: (optional) When the bucket's IAM-only policy was ehabled. This value should normally only be set by the back-end API.
286- """
287-
288- def __init__ (self , bucket , enabled = False , locked_time = None ):
289- data = {"bucketPolicyOnly" : {"enabled" : enabled }}
290- if locked_time is not None :
291- data ["bucketPolicyOnly" ]["lockedTime" ] = _datetime_to_rfc3339 (locked_time )
292- super (IAMConfiguration , self ).__init__ (data )
293- self ._bucket = bucket
294-
295- @classmethod
296- def from_api_repr (cls , resource , bucket ):
297- """Factory: construct instance from resource.
298-
299- :type bucket: :class:`Bucket`
300- :params bucket: Bucket for which this instance is the policy.
301-
302- :type resource: dict
303- :param resource: mapping as returned from API call.
304-
305- :rtype: :class:`IAMConfiguration`
306- :returns: Instance created from resource.
307- """
308- instance = cls (bucket )
309- instance .update (resource )
310- return instance
311-
312- @property
313- def bucket (self ):
314- """Bucket for which this instance is the policy.
315-
316- :rtype: :class:`Bucket`
317- :returns: the instance's bucket.
318- """
319- return self ._bucket
320-
321- @property
322- def bucket_policy_only (self ):
323- """Is the bucket configured to allow only IAM policy?
324-
325- :rtype: bool
326- :returns: whether the bucket is configured to allow only IAM.
327- """
328- bpo = self .get ("bucketPolicyOnly" , {})
329- return bpo .get ("enabled" , False )
330-
331- @bucket_policy_only .setter
332- def bucket_policy_only (self , value ):
333- bpo = self .setdefault ("bucketPolicyOnly" , {})
334- bpo ["enabled" ] = bool (value )
335- self .bucket ._patch_property ("iamConfiguration" , self )
336-
337- @property
338- def locked_time (self ):
339- """When was the bucket configured to allow only IAM policy?
340-
341- :rtype: Union[:class:`datetime.datetime`, None]
342- :returns: (readonly) the time the bucket's IAM-only policy was set.
343- """
344- bpo = self .get ("bucketPolicyOnly" , {})
345- stamp = bpo .get ("lockedTime" )
346- if stamp is not None :
347- stamp = _rfc3339_to_datetime (stamp )
348- return stamp
349-
350-
351275class Bucket (_PropertyMixin ):
352276 """A class representing a Bucket on Cloud Storage.
353277
@@ -1210,16 +1134,6 @@ def id(self):
12101134 """
12111135 return self ._properties .get ("id" )
12121136
1213- @property
1214- def iam_configuration (self ):
1215- """Retrieve IAM configuration for this bucket.
1216-
1217- :rtype: :class:`IAMConfiguration`
1218- :returns: an instance for managing the bucket's IAM configuration.
1219- """
1220- info = self ._properties .get ("iamConfiguration" , {})
1221- return IAMConfiguration .from_api_repr (info , self )
1222-
12231137 @property
12241138 def lifecycle_rules (self ):
12251139 """Retrieve or set lifecycle rules configured for this bucket.
@@ -1482,6 +1396,48 @@ def retention_period(self, value):
14821396 policy = None
14831397 self ._patch_property ("retentionPolicy" , policy )
14841398
1399+ @property
1400+ def iam_configuration_bucket_policy_only (self ):
1401+ """Get/set whether the bucket is configured to allow only bucket IAM.
1402+
1403+ If set, then ACLs are no longer in effect for the bucket or its
1404+ blobs.
1405+
1406+ :rtype: bool
1407+ :returns: True if the bucket allows only IAM, else false.
1408+ """
1409+ iam_config = self ._properties .get ("iamConfiguration" , {})
1410+ bpo = iam_config .get ("bucketPolicyOnly" , {})
1411+ return bpo .get ("enabled" )
1412+
1413+ @iam_configuration_bucket_policy_only .setter
1414+ def iam_configuration_bucket_policy_only (self , value ):
1415+ """Set whether the bucket is configured to allow only bucket IAM.
1416+
1417+ :type value: bool
1418+ :param value:
1419+ If true, the bucket will allow only IAM; if false, then the
1420+ ACLs for the bucket and its blobs will be effective.
1421+ """
1422+ iam_config = self ._properties .setdefault ("iamConfiguration" , {})
1423+ iam_config ["bucketPolicyOnly" ] = {"enabled" : bool (value )}
1424+ self ._patch_property ("iamConfiguration" , iam_config )
1425+
1426+ @property
1427+ def iam_configuration_locked_time (self ):
1428+ """Time when the bucket was configured to allow only bucket IAM.
1429+
1430+ :rtype: datetime.datetime or None
1431+ :returns:
1432+ point in time when the bucket was configured to allow only IAM.
1433+ """
1434+ iam_config = self ._properties .get ("iamConfiguration" , {})
1435+ bpo = iam_config .get ("bucketPolicyOnly" , {})
1436+ stamp = bpo .get ('lockedTime' )
1437+ if stamp is not None :
1438+ stamp = _rfc3339_to_datetime (stamp )
1439+ return stamp
1440+
14851441 @property
14861442 def self_link (self ):
14871443 """Retrieve the URI for the bucket.
0 commit comments