Coverage for nexusLIMS/harvesters/__init__.py: 100%
11 statements
« prev ^ index » next coverage.py v7.11.3, created at 2026-03-24 05:23 +0000
« prev ^ index » next coverage.py v7.11.3, created at 2026-03-24 05:23 +0000
1"""
2Handles obtaining a certificate authority bundle from settings.
4Sub-modules include connections to calendar APIs (NEMO) as well as
5a class to represent a Reservation Event
6"""
8from functools import cache
9from pathlib import Path
11from nexusLIMS.config import settings
14@cache
15def get_ca_bundle_path() -> Path | None:
16 """Get the path to the custom CA bundle file, if configured.
18 Loaded from the `NX_CERT_BUNDLE_FILE` configuration setting.
20 Returns
21 -------
22 pathlib.Path | None
23 Path to the certificate authority bundle file, or None if not configured.
24 """
25 return settings.NX_CERT_BUNDLE_FILE
28@cache
29def get_ca_bundle_content() -> list[bytes] | None:
30 """Get the content of the custom CA bundle, if configured.
32 Loaded from `NX_CERT_BUNDLE` configuration or reads the file at
33 `get_ca_bundle_path()` if not provided.
35 Returns
36 -------
37 list[bytes] | None
38 Certificate authority bundle content as a list of byte strings,
39 or None if not configured.
40 """
41 ca_bundle_content = settings.NX_CERT_BUNDLE
42 ca_bundle_path = get_ca_bundle_path()
44 if ca_bundle_content is None: # pragma: no cover
45 # no way to test this in CI/CD pipeline
46 if ca_bundle_path:
47 with Path(ca_bundle_path).open(mode="rb") as our_cert:
48 return our_cert.readlines()
49 return None
51 # split content into a list of bytes on \n characters
52 return [(i + "\n").encode() for i in ca_bundle_content.split(r"\n")]