Skip to content

Commit

Permalink
Add with_attributes paramter to list_s3_objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tim.reichard committed Dec 11, 2020
1 parent 8fede33 commit 5d4e3ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ History
=======


v0.9.4 (2020-12-11)
-----------------------

* Adding the with_attributes parameter to list_s3_objects function.


v0.9.3 (2020-12-03)
-----------------------

Expand Down
9 changes: 7 additions & 2 deletions aioradio/aws/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ async def download_file(bucket: str, filepath: str, s3_key: str) -> None:


@AWS_SERVICE.active
async def list_s3_objects(bucket: str, s3_prefix: str) -> List[str]:
async def list_s3_objects(bucket: str, s3_prefix: str, with_attributes: bool=False) -> List[str]:
'''List objects in s3 path.'''

arr = []
paginator = S3['client']['obj'].get_paginator('list_objects')
async for result in paginator.paginate(Bucket=bucket, Prefix=s3_prefix):
arr = [item['Key'] for item in result.get('Contents', [])]
arr = []
for item in result.get('Contents', []):
if with_attributes:
arr.append(item)
else:
arr.append(item['Key'])

return arr

Expand Down
4 changes: 2 additions & 2 deletions aioradio/tests/pyodbc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ async def test_pyodbc_query_fetchone_and_fetchall(github_action):
emails = [i.strip() for i in row[0].lower().split(';')] if row is not None else []

expected_emails = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]'
'[email protected]'
]
assert sorted(emails) == expected_emails

Expand Down
3 changes: 3 additions & 0 deletions aioradio/tests/s3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ async def test_s3_upload_file(tmpdir_factory):
await upload_file(bucket=S3_BUCKET, filepath=path, s3_key=s3_key)
assert s3_key in await list_s3_objects(bucket=S3_BUCKET, s3_prefix=S3_PREFIX)

result = await list_s3_objects(bucket=S3_BUCKET, s3_prefix=S3_PREFIX, with_attributes=True)
assert 'LastModified' in result[0]


async def test_s3_download_file(tmpdir_factory):
'''Test uploading file to s3.'''
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
long_description = fileobj.read()

setup(name='aioradio',
version='0.9.3',
version='0.9.4',
description='Generic asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 5d4e3ff

Please sign in to comment.