-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IAM authentication for Postgres (#1168)
* Utility to function to obtain IAM auth token. * Hook IAM auth into engine instantiation. * Return last token if not getting a new one. * Cleanup coding style. * Cleanup coding style. * Cleanup coding style - how deep an indent does it want? * Pass region name in test. * s/region/region_name/ oops. * Pass region name when creating boto3 client. * Fix obtain_new_iam_auth_token() function signature. * Move iam config into config layer. * Make options and env var names more consistent. * Test environment parser. * Removed hard-to-test and unnecessary exception conversion. * Add documentation. * Update whats_new.rst Co-authored-by: phaesler <paul.haesler@data61.csiro.au>
- Loading branch information
1 parent
5076f09
commit 76eb350
Showing
8 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This file is part of the Open Data Cube, see https://opendatacube.org for more information | ||
# | ||
# Copyright (c) 2015-2020 ODC Contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
import pytest | ||
from sqlalchemy.exc import OperationalError | ||
from sqlalchemy.engine.url import URL | ||
|
||
from datacube.drivers.postgres._connections import PostgresDb, handle_dynamic_token_authentication | ||
|
||
|
||
counter = [0] | ||
last_base = [None] | ||
|
||
|
||
def next_token(base): | ||
counter[0] = counter[0] + 1 | ||
last_base[0] = base | ||
return f"{base}{counter[0]}" | ||
|
||
|
||
def test_dynamic_password(): | ||
url = URL.create( | ||
'postgresql', | ||
host="fake_host", database="fake_database", port=6543, | ||
username="fake_username", password="fake_password" | ||
) | ||
engine = PostgresDb._create_engine(url) | ||
counter[0] = 0 | ||
last_base[0] = None | ||
handle_dynamic_token_authentication(engine, next_token, base="password") | ||
with pytest.raises(OperationalError): | ||
conn = engine.connect() | ||
assert counter[0] == 1 | ||
assert last_base[0] == "password" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters