Skip to content

Commit

Permalink
enabler(backends): allow ssl string parameters in PostgreSQL URL (#575)
Browse files Browse the repository at this point in the history
The underlying library asyncpg accepts string values in the ssl
parameter. The old code only accepted the values true and false, which
are converted to boolean.
  • Loading branch information
Elouan Martinet committed Nov 28, 2023
1 parent 2d05618 commit 9e1aa48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion databases/backends/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def _get_connection_kwargs(self) -> dict:
if max_size is not None:
kwargs["max_size"] = int(max_size)
if ssl is not None:
kwargs["ssl"] = {"true": True, "false": False}[ssl.lower()]
ssl_lower = ssl.lower()
if ssl_lower == "true":
kwargs["ssl"] = True
elif ssl_lower == "false":
kwargs["ssl"] = False

kwargs.update(self._options)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_connection_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def test_postgres_ssl():
assert kwargs == {"ssl": True}


def test_postgres_ssl_verify_full():
backend = PostgresBackend("postgres://localhost/database?ssl=verify-full")
kwargs = backend._get_connection_kwargs()
assert kwargs == {"ssl": "verify-full"}


def test_postgres_explicit_ssl():
backend = PostgresBackend("postgres://localhost/database", ssl=True)
kwargs = backend._get_connection_kwargs()
Expand Down

0 comments on commit 9e1aa48

Please sign in to comment.