Skip to content

Commit

Permalink
Adding ability to get ftp & s3 file attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tim.reichard committed Dec 3, 2020
1 parent caff235 commit f399cd2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
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.3 (2020-12-03)
-----------------------

* Add functions (get_ftp_file_attributes & get_s3_file_attributes) to retrieve metadata on files in FTP and S3.


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

Expand Down
10 changes: 10 additions & 0 deletions aioradio/aws/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ async def list_s3_objects(bucket: str, s3_prefix: str) -> List[str]:
return arr


@AWS_SERVICE.active
async def get_s3_file_attributes(bucket: str, s3_key: str) -> Dict[str, Any]:
'''Get s3 objects metadata attributes.'''

s3_object = await S3['client']['obj'].get_object(Bucket=bucket, Key=s3_key)
del s3_object['Body']

return s3_object


@AWS_SERVICE.active
async def get_object(bucket: str, s3_key: str) -> bytes:
'''Directly download contents of s3 object.'''
Expand Down
6 changes: 6 additions & 0 deletions aioradio/file_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,10 @@ async def write_file_to_ftp(
await sleep(1)

# return file attributes
return await get_ftp_file_attributes(conn, service_name, ftp_path)


async def get_ftp_file_attributes(conn: SMBConnection, service_name: str, ftp_path: str):
'''GET FTP file attributes.'''

return conn.getAttributes(service_name=service_name, path=ftp_path)
8 changes: 8 additions & 0 deletions aioradio/tests/s3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aioradio.aws.s3 import delete_s3_object
from aioradio.aws.s3 import download_file
from aioradio.aws.s3 import get_object
from aioradio.aws.s3 import get_s3_file_attributes
from aioradio.aws.s3 import list_s3_objects
from aioradio.aws.s3 import upload_file

Expand Down Expand Up @@ -66,3 +67,10 @@ async def test_get_object():

result = await get_object(bucket=S3_BUCKET, s3_key=f'{S3_PREFIX}/hello_world.txt')
assert result is not None


async def test_get_file_attributes():
'''Test retrieving s3 object attributes.'''

result = await get_s3_file_attributes(bucket=S3_BUCKET, s3_key=f'{S3_PREFIX}/hello_world.txt')
assert result['ContentLength'] == 22
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.2',
version='0.9.3',
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 f399cd2

Please sign in to comment.