Skip to content

Connectivity: Connect using SSL by default #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: sslmode
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyproject.toml export-subst
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

## Unreleased
- SSL: Added canonical [PostgreSQL client parameter `sslmode`], implementing
`sslmode=prefer` to connect to SSL-enabled CrateDB instances without
verifying the host name.
- SSL: Connect using SSL by default

[PostgreSQL client parameter `sslmode`]: https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-PROTECTION

## 2025/01/30 0.41.0
- Dependencies: Updated to `crate-2.0.0`, which uses `orjson` for JSON marshalling
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ dependencies = [
"backports.zoneinfo<1; python_version<'3.9'",
"crate>=2,<3",
"geojson<4,>=2.5",
"importlib-metadata; python_version<'3.8'",
"importlib-resources; python_version<'3.9'",
"sqlalchemy<2.1,>=1",
"verlib2<0.3",
Expand Down Expand Up @@ -252,8 +253,9 @@ non_interactive = true
# enable_recursive_aliases = true

[tool.versioningit.vcs]
method = "git"
method = "git-archive"
default-tag = "0.0.0"
describe-subst = "$Format:%(describe:tags)$"

# ===================
# Tasks configuration
Expand Down
15 changes: 15 additions & 0 deletions src/sqlalchemy_cratedb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,22 @@
monkeypatch_add_exec_driver_sql()


try:
from importlib.metadata import PackageNotFoundError, version
except (ImportError, ModuleNotFoundError): # pragma:nocover
from importlib_metadata import ( # type: ignore[assignment,no-redef,unused-ignore]
PackageNotFoundError,
version,
)

try:
__version__ = version("sqlalchemy-cratedb")
except PackageNotFoundError: # pragma: no cover
__version__ = "unknown"


__all__ = [
__version__,
dialect,
FloatVector,
Geopoint,
Expand Down
7 changes: 5 additions & 2 deletions src/sqlalchemy_cratedb/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,12 @@ def connect(self, host=None, port=None, *args, **kwargs):
server = kwargs.pop("servers")
servers = to_list(server)
if servers:
use_ssl = asbool(kwargs.pop("ssl", False))
if use_ssl:
use_ssl = asbool(kwargs.pop("ssl", True))
sslmode = kwargs.pop("sslmode", "prefer")
if use_ssl or sslmode in ["allow", "prefer", "require", "verify-ca", "verify-full"]:
servers = ["https://" + server for server in servers]
if sslmode == "require":
kwargs["verify_ssl_cert"] = False
return self.dbapi.connect(servers=servers, **kwargs)
return self.dbapi.connect(**kwargs)

Expand Down
Loading