Skip to content

Commit b4d289a

Browse files
authored
Fix verify_in_ssl log statement which no longer has access to SSL params (#202)
## Ticket #200 ## Changes Removes log statement that relies on variables no longer in psycopg 3. ## Context for reviewers The upgrade to psycopg3 got this error during migrations: `AttributeError: 'ConnectionInfo' object has no attribute 'ssl_attribute_names'` - https://github.com/navapbc/platform-test-flask/actions/runs/6275581568/job/17043454952 These aren't available anymore and looking through the connection info object, I don't see any equivalent. Looking at the docs for version 2, these attributes say `Only available if psycopg was built with libpq >= 9.5` https://www.psycopg.org/docs/extensions.html#psycopg2.extensions.ConnectionInfo.ssl_attribute While the docs for psycopg3 mention libpq as being the backing library it uses, I don't see any mention of these parameters in their docs. https://www.psycopg.org/psycopg3/docs/api/connections.html#psycopg.Connection.pgconn - so seems to just be gone entirely? ## Testing Updated tests
1 parent 42d6923 commit b4d289a

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

app/src/adapters/db/clients/postgres_client.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,6 @@ def generate_iam_auth_token(aws_region: str, host: str, port: int, user: str) ->
121121
def verify_ssl(connection_info: Any) -> None:
122122
"""Verify that the database connection is encrypted and log a warning if not."""
123123
if connection_info.pgconn.ssl_in_use:
124-
logger.info(
125-
"database connection is using SSL: %s",
126-
", ".join(
127-
name + " " + connection_info.ssl_attribute(name)
128-
for name in connection_info.ssl_attribute_names
129-
),
130-
)
124+
logger.info("database connection is using SSL")
131125
else:
132126
logger.warning("database connection is not using SSL")

app/tests/src/adapters/db/clients/test_postgres_client.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,24 @@ class DummyPgConn:
1313

1414

1515
class DummyConnectionInfo:
16-
def __init__(self, ssl_in_use, attributes):
17-
self.attributes = attributes
18-
self.ssl_attribute_names = tuple(attributes.keys())
16+
def __init__(self, ssl_in_use):
1917
self.pgconn = DummyPgConn(ssl_in_use)
2018

21-
def ssl_attribute(self, name):
22-
return self.attributes[name]
23-
2419

2520
def test_verify_ssl(caplog):
2621
caplog.set_level(logging.INFO) # noqa: B1
2722

28-
conn_info = DummyConnectionInfo(True, {"protocol": "ABCv3", "key_bits": "64", "cipher": "XYZ"})
23+
conn_info = DummyConnectionInfo(True)
2924
verify_ssl(conn_info)
3025

31-
assert caplog.messages == [
32-
"database connection is using SSL: protocol ABCv3, key_bits 64, cipher XYZ"
33-
]
26+
assert caplog.messages == ["database connection is using SSL"]
3427
assert caplog.records[0].levelname == "INFO"
3528

3629

3730
def test_verify_ssl_not_in_use(caplog):
3831
caplog.set_level(logging.INFO) # noqa: B1
3932

40-
conn_info = DummyConnectionInfo(False, {})
33+
conn_info = DummyConnectionInfo(False)
4134
verify_ssl(conn_info)
4235

4336
assert caplog.messages == ["database connection is not using SSL"]

0 commit comments

Comments
 (0)