Skip to content

Commit

Permalink
S3: get_object_attributes() now also works for Glacier objects (#8315)
Browse files Browse the repository at this point in the history
  • Loading branch information
bblommers authored Nov 15, 2024
1 parent f30e0fa commit 962d367
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions moto/s3/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,8 @@ def get_object(self) -> TYPE_RESPONSE:
return 200, response_headers, key.value

def get_object_attributes(self) -> TYPE_RESPONSE:
key, not_modified = self._get_key()
# Get the Key, but do not validate StorageClass - we can retrieve the attributes of Glacier-objects
key, not_modified = self._get_key(validate_storage_class=False)
response_headers = self._get_cors_headers_other()
if not_modified:
return 304, response_headers, "Not Modified"
Expand Down Expand Up @@ -1608,7 +1609,7 @@ def list_parts(self) -> TYPE_RESPONSE:
),
)

def _get_key(self) -> Tuple[FakeKey, bool]:
def _get_key(self, validate_storage_class: bool = True) -> Tuple[FakeKey, bool]:
key_name = self.parse_key_name()
version_id = self.querystring.get("versionId", [None])[0]
if_modified_since = self.headers.get("If-Modified-Since")
Expand All @@ -1621,7 +1622,7 @@ def _get_key(self) -> Tuple[FakeKey, bool]:
raise MissingKey(key=key_name)
elif key is None:
raise MissingVersion()
if key.storage_class in ARCHIVE_STORAGE_CLASSES:
if validate_storage_class and key.storage_class in ARCHIVE_STORAGE_CLASSES:
if 'ongoing-request="false"' not in key.response_dict.get(
"x-amz-restore", ""
):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_s3/test_s3_storageclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,9 @@ def test_s3_get_object_from_glacier():
"The operation is not valid for the object's storage class"
)
assert err["StorageClass"] == "GLACIER"

# Note that get_object_attributes should work
resp = s3_client.get_object_attributes(
Bucket=bucket_name, Key="test.txt", ObjectAttributes=["StorageClass"]
)
assert resp["StorageClass"] == "GLACIER"

0 comments on commit 962d367

Please sign in to comment.