From 66eaeb3bfa43d0d289db172dc780a86b1db707c0 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Thu, 14 Nov 2024 19:54:38 -0100 Subject: [PATCH] S3: get_object_attributes() now also works for Glacier objects --- moto/s3/responses.py | 7 ++++--- tests/test_s3/test_s3_storageclass.py | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/moto/s3/responses.py b/moto/s3/responses.py index eb79a3228ac4..d0c82428a953 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -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" @@ -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") @@ -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", "" ): diff --git a/tests/test_s3/test_s3_storageclass.py b/tests/test_s3/test_s3_storageclass.py index f40c97ee66ec..4ba0b321426a 100644 --- a/tests/test_s3/test_s3_storageclass.py +++ b/tests/test_s3/test_s3_storageclass.py @@ -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"