Skip to content

Commit

Permalink
Postgres SSL mode doesn't pass credentials correctly (#44)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Hopkins <[email protected]>
  • Loading branch information
razodactyl and ahopkins authored Apr 11, 2023
1 parent a01bdf1 commit 1872830
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/mayim/base/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"password": UrlMapping("_password", str),
"port": UrlMapping("_port", int),
"path": UrlMapping("_db", lambda value: value.replace("/", "")),
"query": UrlMapping("_query", str),
}


Expand Down Expand Up @@ -52,6 +53,7 @@ def __init__(
user: Optional[str] = None,
password: Optional[str] = None,
db: Optional[int] = None,
query: Optional[str] = None,
) -> None:
"""DB class initialization.
Expand All @@ -61,6 +63,7 @@ def __init__(
port (int, optional): DB port. Defaults to 6379
password (str, optional): DB password
db (int, optional): DB db. Defaults to 1
query (str, optional): DB query parameters. Defaults to None
"""

if dsn and host:
Expand Down Expand Up @@ -92,6 +95,7 @@ def __init__(
self._user = user
self._password = password
self._db = db
self._query = query
self._full_dsn: Optional[str] = None
self._connection: ContextVar[Any] = ContextVar(
"connection", default=None
Expand Down Expand Up @@ -138,6 +142,7 @@ def _populate_dsn(self):
if self.password
else self.dsn
)
self._full_dsn += f"?{self._query}" if self._query else ""

@property
def dsn(self):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
@pytest.fixture
def mayim(FooExecutor):
return Mayim(
executors=[FooExecutor], dsn="postgres://user:password@host:1234/db"
executors=[FooExecutor],
dsn="postgres://user:password@host:1234/db?sslmode=verify-ca",
)


Expand Down

0 comments on commit 1872830

Please sign in to comment.