Skip to content

Commit 10f275b

Browse files
committed
Add canonical PostgreSQL client parameter sslmode
This implements `sslmode=prefer` to connect to SSL-enabled CrateDB instances without verifying the host name.
1 parent 69fdae7 commit 10f275b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22

33
## Unreleased
4+
- Added canonical [PostgreSQL client parameter `sslmode`], implementing
5+
`sslmode=prefer` to connect to SSL-enabled CrateDB instances without
6+
verifying the host name.
7+
8+
[PostgreSQL client parameter `sslmode`]: https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-PROTECTION
49

510
## 2025/01/30 0.41.0
611
- Dependencies: Updated to `crate-2.0.0`, which uses `orjson` for JSON marshalling

src/sqlalchemy_cratedb/dialect.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,12 @@ def connect(self, host=None, port=None, *args, **kwargs):
228228
servers = to_list(server)
229229
if servers:
230230
use_ssl = asbool(kwargs.pop("ssl", False))
231-
if use_ssl:
231+
# TODO: Switch to the canonical default `sslmode=prefer` later.
232+
sslmode = kwargs.pop("sslmode", "disable")
233+
if use_ssl or sslmode in ["allow", "prefer", "require", "verify-ca", "verify-full"]:
232234
servers = ["https://" + server for server in servers]
235+
if sslmode == "require":
236+
kwargs["verify_ssl_cert"] = False
233237
return self.dbapi.connect(servers=servers, **kwargs)
234238
return self.dbapi.connect(**kwargs)
235239

0 commit comments

Comments
 (0)