Skip to content

Commit

Permalink
Add support to filter secrets in async_db_wrapper using the argument …
Browse files Browse the repository at this point in the history
…secret_json_key
  • Loading branch information
tim.reichard committed Jan 26, 2023
1 parent 31d2a21 commit f11d670
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ History
=======


v0.17.28 (2023-01-26)

* Add support to filter secrets in async_db_wrapper using the argument secret_json_key.


v0.17.27 (2023-01-20)

* Raise errors instead of printing in file_ingestion function zipfile_to_tsv.
Expand Down
7 changes: 6 additions & 1 deletion aioradio/file_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,12 @@ async def child_wrapper(*args, **kwargs) -> Any:
secret = await get_secret(item['secret'], item['region'], item['aws_creds'])
else:
secret = await get_secret(item['secret'], item['region'])
creds = {**json.loads(secret), **{'database': item.get('database', '')}}

secret = json.loads(secret)
if 'secret_json_key' in item:
secret = secret[item['secret_json_key']]

creds = {**secret, **{'database': item.get('database', '')}}
if item['db'] == 'pyodbc':
# Add import here because it requires extra dependencies many systems
# don't have out of the box so only import when explicitly being used
Expand Down
3 changes: 1 addition & 2 deletions aioradio/tests/aws_secrets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

from aioradio.aws.secrets import get_secret

pytestmark = pytest.mark.asyncio


@mock_secretsmanager
def test_secrets_get_secret():
Expand All @@ -27,6 +25,7 @@ def test_secrets_get_secret():


@pytest.mark.xfail
@pytest.mark.asyncio
async def test_secrets_get_secret_with_bad_key():
"""Test exception raised when using a bad key retrieving from Secrets
Manager."""
Expand Down
36 changes: 15 additions & 21 deletions aioradio/tests/file_ingestion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,36 +200,30 @@ async def func():
assert result == 'Hello World'



def test_async_db_wrapper(user):
@pytest.mark.asyncio
async def test_async_db_wrapper(user):
"""Test async_db_wrapper with database connections."""

if user != 'tim.reichard':
pytest.skip('Skip test_async_db_wrapper since user is not Tim Reichard')

db_info=[
{
'name': 'test1',
'db': 'pyodbc',
'secret': 'production/airflowCluster/sqloltp',
'region': 'us-east-1',
'rollback': True
},
{
'name': 'test2',
'db': 'psycopg2',
'secret': 'datalab/dev/classplanner_db',
'region': 'us-east-1',
'database': 'student',
'is_audit': False,
'rollback': True
}
]
db_info=[{
'db': 'pyodbc',
'name': 'test1',
'database': 'DataStage',
'secret': 'efi/sandbox/all',
'secret_json_key': 'mssql',
'region': 'us-east-1',
'rollback': True,
'trusted_connection': 'no',
'application_intent': 'ReadOnly',
'tds_version': '7.4'
}]

@async_db_wrapper(db_info=db_info)
async def func(**kwargs):
conns = kwargs['conns']
for name, conn in conns.items():
print(f"Connection name: {name}\tConnection object: {conn}")

func()
await func()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = fileobj.read()

setup(name='aioradio',
version='0.17.27',
version='0.17.28',
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 f11d670

Please sign in to comment.