Skip to content

Commit

Permalink
Merge branch 'master' into pjoshi30_aurora_simple
Browse files Browse the repository at this point in the history
  • Loading branch information
saikonen authored Oct 25, 2023
2 parents 158e27f + 65d41dd commit 379b21b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
15 changes: 3 additions & 12 deletions services/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from packaging.version import Version, parse
from importlib import metadata


USE_SEPARATE_READER_POOL = os.environ.get("USE_SEPARATE_READER_POOL", "0") in ["True", "true", "1"]

version = metadata.version("metadata_service")
Expand Down Expand Up @@ -272,17 +273,6 @@ def connection_string_url(self, type=None):
elif type == DBType.READER:
base_url = f'postgresql://{quote(self._user)}:{quote(self._password)}@{self._read_replica_host}:{self._port}/{self._database_name}'

if (self._ssl_mode in ['allow', 'prefer', 'require', 'verify-ca', 'verify-full']):
ssl_query = f'sslmode={self._ssl_mode}'
if self._ssl_cert_path is not None:
ssl_query = f'{ssl_query}&sslcert={self._ssl_cert_path}'
if self._ssl_key_path is not None:
ssl_query = f'{ssl_query}&sslkey={self._ssl_key_path}'
if self._ssl_root_cert_path is not None:
ssl_query = f'{ssl_query}&sslrootcert={self._ssl_root_cert_path}'
else:
ssl_query = f'sslmode=disable'

return f'{base_url}?{ssl_query}'

def get_dsn(self, type=None):
Expand All @@ -307,12 +297,13 @@ def get_dsn(self, type=None):
'sslkey': sslkey,
'sslrootcert': sslrootcert
}

if type == DBType.READER:
# We assume that everything except the hostname remains the same for a reader.
# At the moment this is a fair assumption for Postgres read replicas.
kwargs.update({"host":self._read_replica_host})


return psycopg2.extensions.make_dsn(**{k: v for k, v in kwargs.items() if v is not None})
else:
return self._dsn
Expand Down
1 change: 1 addition & 0 deletions services/utils/tests/unit_tests/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def test_db_conf_env_dsn():
# valid DSN in env should set correctly.
assert DBConfiguration().get_dsn() == 'dbname=testgres user=test_user host=test_host port=1234 password=test_pwd sslmode=verify-full sslrootcert=/test'


def test_db_conf_pool_size():
with set_env():
db_conf = DBConfiguration(pool_min=2, pool_max=4)
Expand Down

0 comments on commit 379b21b

Please sign in to comment.