add get_object_info to return a given object metadata (#2678)
This commit is contained in:
@@ -190,6 +190,12 @@ class AsyncAWSClient:
|
|||||||
LOG.exception("S3 download failed", uri=uri)
|
LOG.exception("S3 download failed", uri=uri)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
async def get_object_info(self, uri: str) -> dict:
|
||||||
|
async with self._s3_client() as client:
|
||||||
|
parsed_uri = S3Uri(uri)
|
||||||
|
# Only get object metadata without the body
|
||||||
|
return await client.head_object(Bucket=parsed_uri.bucket, Key=parsed_uri.key)
|
||||||
|
|
||||||
async def get_file_metadata(
|
async def get_file_metadata(
|
||||||
self,
|
self,
|
||||||
uri: str,
|
uri: str,
|
||||||
@@ -207,12 +213,8 @@ class AsyncAWSClient:
|
|||||||
The metadata dictionary or None if the request fails
|
The metadata dictionary or None if the request fails
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
async with self._s3_client() as client:
|
response = await self.get_object_info(uri)
|
||||||
parsed_uri = S3Uri(uri)
|
return response.get("Metadata", {})
|
||||||
|
|
||||||
# Only get object metadata without the body
|
|
||||||
response = await client.head_object(Bucket=parsed_uri.bucket, Key=parsed_uri.key)
|
|
||||||
return response.get("Metadata", {})
|
|
||||||
except Exception:
|
except Exception:
|
||||||
if log_exception:
|
if log_exception:
|
||||||
LOG.exception("S3 metadata retrieval failed", uri=uri)
|
LOG.exception("S3 metadata retrieval failed", uri=uri)
|
||||||
|
|||||||
Reference in New Issue
Block a user