Skip to content

Commit 72c23b0

Browse files
authored
adds certifi certs to the API calls (#1211)
* adds certifi certs to the API calls * changelog
1 parent 434dd2c commit 72c23b0

File tree

7 files changed

+14
-173
lines changed

7 files changed

+14
-173
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1717
### Added
1818

1919
### Changed
20+
- Fixes SSL certificate verification for remote datasets by adding CA certificates using `certifi`. [#1211](https://github.com/scalableminds/webknossos-libs/pull/1211)
2021

2122
### Fixed
2223

webknossos/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies = [
3232
"attrs >=22.0.0",
3333
"boltons >=21.0.0",
3434
"cattrs >=22.0.0",
35+
"certifi>=2023",
3536
"cluster-tools",
3637
"fsspec ~=2024.6.0",
3738
"httpx ~=0.27.0",

webknossos/uv.lock

Lines changed: 2 additions & 172 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webknossos/webknossos/annotation/annotation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
RemoteDataset,
6262
SegmentationLayer,
6363
)
64-
from ..dataset.defaults import PROPERTIES_FILE_NAME
64+
from ..dataset.defaults import PROPERTIES_FILE_NAME, SSL_CONTEXT
6565
from ..dataset.properties import DatasetProperties, dataset_converter
6666
from ..geometry import NDBoundingBox, Vec3Int
6767
from ..skeleton import Skeleton
@@ -897,6 +897,7 @@ def get_remote_annotation_dataset(self) -> Dataset:
897897
zarr_path = UPath(
898898
f"{datastore_url}/data/annotations/zarr/{self.annotation_id}/",
899899
headers={} if token is None else {"X-Auth-Token": token},
900+
ssl=SSL_CONTEXT,
900901
)
901902
return Dataset.open(zarr_path)
902903

webknossos/webknossos/client/api_client/_abstract_api_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import httpx
66

7+
from ...dataset.defaults import SSL_CONTEXT
78
from ._serialization import custom_converter
89
from .errors import CannotHandleResponseError, UnexpectedStatusError
910

@@ -197,6 +198,7 @@ def _request(
197198
files=files,
198199
headers=self.headers,
199200
timeout=timeout_seconds or self.timeout_seconds,
201+
verify=SSL_CONTEXT,
200202
)
201203
if response.status_code == 200 or response.status_code == 400:
202204
# Stop retrying in case of success or bad request

webknossos/webknossos/dataset/dataset.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
DEFAULT_CHUNKS_PER_SHARD_ZARR,
5454
DEFAULT_DATA_FORMAT,
5555
PROPERTIES_FILE_NAME,
56+
SSL_CONTEXT,
5657
ZARR_JSON_FILE_NAME,
5758
ZATTRS_FILE_NAME,
5859
ZGROUP_FILE_NAME,
@@ -681,6 +682,7 @@ def open_remote(
681682
zarr_path = UPath(
682683
f"{datastore_url}/data/zarr/{organization_id}/{dataset_name}/",
683684
headers={} if token is None else {"X-Auth-Token": token},
685+
ssl=SSL_CONTEXT,
684686
)
685687
return RemoteDataset(
686688
zarr_path, dataset_name, organization_id, sharing_token, context_manager

webknossos/webknossos/dataset/defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import os
2+
import ssl
3+
4+
import certifi
25

36
from ..geometry import Vec3Int
47
from .data_format import DataFormat
@@ -22,3 +25,4 @@
2225
ZGROUP_FILE_NAME = ".zgroup"
2326
ZATTRS_FILE_NAME = ".zattrs"
2427
ZARR_JSON_FILE_NAME = "zarr.json"
28+
SSL_CONTEXT = ssl.create_default_context(cafile=certifi.where())

0 commit comments

Comments
 (0)