Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3: get_object_attributes() now also works for Glacier objects #8315

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading