in gslib/boto_translation.py [0:0]
def PatchBucket(self,
bucket_name,
metadata,
canned_acl=None,
canned_def_acl=None,
preconditions=None,
provider=None,
fields=None):
"""See CloudApi class for function doc strings."""
_ = provider
bucket_uri = self._StorageUriForBucket(bucket_name)
headers = self._CreateBaseHeaders()
self._AddPreconditionsToHeaders(preconditions, headers)
try:
if metadata.acl:
boto_acl = AclTranslation.BotoAclFromMessage(metadata.acl)
bucket_uri.set_xml_acl(boto_acl.to_xml(), headers=headers)
if canned_acl:
canned_acls = bucket_uri.canned_acls()
if canned_acl not in canned_acls:
raise CommandException('Invalid canned ACL "%s".' % canned_acl)
bucket_uri.set_acl(canned_acl, bucket_uri.object_name, headers=headers)
if canned_def_acl:
canned_acls = bucket_uri.canned_acls()
if canned_def_acl not in canned_acls:
raise CommandException('Invalid canned ACL "%s".' % canned_def_acl)
bucket_uri.set_def_acl(canned_def_acl,
bucket_uri.object_name,
headers=headers)
if metadata.cors:
if metadata.cors == REMOVE_CORS_CONFIG:
metadata.cors = []
boto_cors = CorsTranslation.BotoCorsFromMessage(metadata.cors)
bucket_uri.set_cors(boto_cors, False, headers=headers)
if metadata.defaultObjectAcl:
boto_acl = AclTranslation.BotoAclFromMessage(metadata.defaultObjectAcl)
bucket_uri.set_def_xml_acl(boto_acl.to_xml(), headers=headers)
if metadata.labels:
boto_tags = LabelTranslation.BotoTagsFromMessage(metadata.labels)
# TODO: Define tags-related methods on storage_uri objects. The set_tags
# method raises an exception if the response differs from the style of
# S3, which uses a 204 response code upon success. That method
# should be okay with a 200 instead of a 204 for GS responses. In the
# meantime, we invoke the underlying bucket's methods directly and
# bypass manually raised exceptions from 200 responses.
try:
bucket_uri.get_bucket().set_tags(boto_tags, headers=headers)
except boto.exception.GSResponseError as e:
if e.status != 200:
raise
if metadata.lifecycle:
boto_lifecycle = LifecycleTranslation.BotoLifecycleFromMessage(
metadata.lifecycle)
bucket_uri.configure_lifecycle(boto_lifecycle, False, headers=headers)
if metadata.logging:
if metadata.logging.logBucket and metadata.logging.logObjectPrefix:
bucket_uri.enable_logging(metadata.logging.logBucket,
metadata.logging.logObjectPrefix,
False,
headers=headers)
else: # Logging field is present and empty. Disable logging.
bucket_uri.disable_logging(False, headers=headers)
if metadata.storageClass:
bucket_uri.set_storage_class(metadata.storageClass, headers=headers)
if metadata.versioning:
bucket_uri.configure_versioning(metadata.versioning.enabled,
headers=headers)
if metadata.website:
main_page_suffix = metadata.website.mainPageSuffix
error_page = metadata.website.notFoundPage
bucket_uri.set_website_config(main_page_suffix,
error_page,
headers=headers)
return self.GetBucket(bucket_name, fields=fields)
except TRANSLATABLE_BOTO_EXCEPTIONS as e:
self._TranslateExceptionAndRaise(e, bucket_name=bucket_name)