Skip to content

Commit 8ae645a

Browse files
committed
Keep Bloom CLI cert helpers compatible
1 parent 416a653 commit 8ae645a

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

bloom_lims/cli/server.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from dataclasses import dataclass
56
from enum import Enum
67
from typing import TYPE_CHECKING
78

@@ -17,7 +18,6 @@
1718
from pathlib import Path
1819

1920
import typer
20-
from cli_core_yo.certs import resolve_https_certs, shared_dayhoff_certs_dir
2121
from cli_core_yo.server import (
2222
display_host,
2323
latest_log,
@@ -28,6 +28,43 @@
2828
)
2929
from rich.console import Console
3030

31+
try:
32+
from cli_core_yo.certs import resolve_https_certs, shared_dayhoff_certs_dir
33+
except ImportError:
34+
from cli_core_yo.certs import ensure_certs
35+
36+
@dataclass
37+
class _CompatResolvedHttpsCerts:
38+
cert_path: Path
39+
key_path: Path
40+
source: str = "ensure_certs"
41+
42+
def shared_dayhoff_certs_dir(deployment_code: str) -> Path:
43+
return Path.home() / ".config" / "dayhoff" / "certs" / deployment_code
44+
45+
def resolve_https_certs(
46+
*,
47+
cert_path: str | None = None,
48+
key_path: str | None = None,
49+
shared_certs_dir: Path | None = None,
50+
fallback_certs_dir: Path | None = None,
51+
hosts: tuple[str, ...] | None = None,
52+
) -> _CompatResolvedHttpsCerts:
53+
del hosts
54+
if cert_path and key_path:
55+
return _CompatResolvedHttpsCerts(
56+
cert_path=Path(cert_path),
57+
key_path=Path(key_path),
58+
source="explicit",
59+
)
60+
cert_dir = Path(shared_certs_dir or fallback_certs_dir or (Path.home() / ".config" / "bloom" / "certs"))
61+
cert_file, key_file = ensure_certs(cert_dir)
62+
return _CompatResolvedHttpsCerts(
63+
cert_path=Path(cert_file),
64+
key_path=Path(key_file),
65+
source="ensure_certs",
66+
)
67+
3168
from bloom_lims.config import (
3269
DEFAULT_BLOOM_WEB_PORT,
3370
apply_runtime_environment,

tests/test_cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@
1616
build_app,
1717
config_extra,
1818
)
19-
from cli_core_yo.certs import ResolvedHttpsCerts
19+
20+
try:
21+
from cli_core_yo.certs import ResolvedHttpsCerts
22+
except ImportError:
23+
from dataclasses import dataclass
24+
25+
@dataclass
26+
class ResolvedHttpsCerts:
27+
cert_path: Path
28+
key_path: Path
29+
source: str = "ensure_certs"
2030

2131
server_commands = importlib.import_module("bloom_lims.cli.server")
2232

0 commit comments

Comments
 (0)