Skip to content

Commit

Permalink
fix: replace get_object_acl with head_object (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermef committed Dec 16, 2022
1 parent 9ec4536 commit 0f49cf2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion thumbor_aws/result_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async def last_updated( # pylint: disable=invalid-overridden-method
file_abspath = self.normalize_path(path)
logger.debug("[RESULT_STORAGE] getting from %s", file_abspath)

response = await self.get_object_acl(file_abspath)
response = await self.get_object_metadata(file_abspath)
return datetime.strptime(
response["ResponseMetadata"]["HTTPHeaders"]["last-modified"],
"%a, %d %b %Y %H:%M:%S %Z",
Expand Down
11 changes: 8 additions & 3 deletions thumbor_aws/s3_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,23 @@ async def object_exists(self, filepath: str):

async with self.get_client() as client:
try:
await client.get_object_acl(
await client.head_object(
Bucket=self.bucket_name, Key=filepath
)
return True
except client.exceptions.NoSuchKey:
return False
except client.exceptions.ClientError as err:
# NOTE: This case is required because of https://github.com/boto/boto3/issues/2442
if err.response["Error"]["Code"] == "404":
return False
raise

async def get_object_acl(self, filepath: str):
async def get_object_metadata(self, filepath: str):
"""Gets an object's metadata"""

async with self.get_client() as client:
return await client.get_object_acl(
return await client.head_object(
Bucket=self.bucket_name, Key=filepath
)

Expand Down

0 comments on commit 0f49cf2

Please sign in to comment.