Permalink
Browse files

Merge pull request #3691 from houglum/develop

Populate storage class from HEAD Object responses.
  • Loading branch information...
mfschwartz committed Mar 2, 2017
2 parents de61c30 + 7f07818 commit 315b76e01e65fb742cbc14170e5207d648bc649a
Showing with 24 additions and 6 deletions.
  1. +1 −1 boto/provider.py
  2. +1 −0 boto/s3/bucket.py
  3. +12 −0 boto/s3/key.py
  4. +10 −5 tests/integration/gs/test_basic.py
@@ -155,7 +155,7 @@ class Provider(object):
# Note that this version header is not to be confused with
# the Google Cloud Storage 'x-goog-api-version' header.
VERSION_ID_HEADER_KEY: GOOG_HEADER_PREFIX + 'version-id',
STORAGE_CLASS_HEADER_KEY: None,
STORAGE_CLASS_HEADER_KEY: GOOG_HEADER_PREFIX + 'storage-class',
MFA_HEADER_KEY: None,
RESTORE_HEADER_KEY: None,
}
@@ -221,6 +221,7 @@ def _get_key_internal(self, key_name, headers, query_args_l):
k.handle_version_headers(response)
k.handle_encryption_headers(response)
k.handle_restore_headers(response)
k.handle_storage_class_header(response)
k.handle_addl_headers(response.getheaders())
return k, response
else:
@@ -230,6 +230,18 @@ def handle_encryption_headers(self, resp):
else:
self.encrypted = None

def handle_storage_class_header(self, resp):
provider = self.bucket.connection.provider
if provider.storage_class_header:
self._storage_class = resp.getheader(
provider.storage_class_header, None)
if (self._storage_class is None and
provider.get_provider_name() == 'aws'):
# S3 docs for HEAD object requests say S3 will return this
# header for all objects except Standard storage class objects.
self._storage_class = 'STANDARD'


def handle_version_headers(self, resp, force=False):
provider = self.bucket.connection.provider
# If the Key object already has a version_id attribute value, it
@@ -75,12 +75,15 @@

# Regexp for matching project-private default object ACL.
PROJECT_PRIVATE_RE = ('\s*<AccessControlList>\s*<Entries>\s*<Entry>'
'\s*<Scope type="GroupById"><ID>[0-9a-fA-F]+</ID></Scope>'
'\s*<Scope type="GroupById">\s*<ID>[0-9a-fA-F]+</ID>'
'\s*(<Name>[^<]+</Name>)?\s*</Scope>'
'\s*<Permission>FULL_CONTROL</Permission>\s*</Entry>\s*<Entry>'
'\s*<Scope type="GroupById"><ID>[0-9a-fA-F]+</ID></Scope>'
'\s*<Scope type="GroupById">\s*<ID>[0-9a-fA-F]+</ID>'
'\s*(<Name>[^<]+</Name>)?\s*</Scope>'
'\s*<Permission>FULL_CONTROL</Permission>\s*</Entry>\s*<Entry>'
'\s*<Scope type="GroupById"><ID>[0-9a-fA-F]+</ID></Scope>'
'\s*<Permission>READ</Permission></Entry>\s*</Entries>'
'\s*<Scope type="GroupById">\s*<ID>[0-9a-fA-F]+</ID>'
'\s*(<Name>[^<]+</Name>)?\s*</Scope>'
'\s*<Permission>READ</Permission>\s*</Entry>\s*</Entries>'
'\s*</AccessControlList>\s*')


@@ -349,7 +352,9 @@ def test_default_object_acls_storage_uri(self):
uri = storage_uri('gs://' + bucket_name)
# get default acl and make sure it's project-private
acl = uri.get_def_acl()
self.assertIsNotNone(re.search(PROJECT_PRIVATE_RE, acl.to_xml()))
self.assertIsNotNone(
re.search(PROJECT_PRIVATE_RE, acl.to_xml()),
'PROJECT_PRIVATE_RE not found in ACL XML:\n' + acl.to_xml())
# set default acl to a canned acl and verify it gets set
uri.set_def_acl('public-read')
acl = uri.get_def_acl()

0 comments on commit 315b76e

Please sign in to comment.