|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +from dataclasses import dataclass |
5 | 6 | from enum import Enum |
6 | 7 | from typing import TYPE_CHECKING |
7 | 8 |
|
|
17 | 18 | from pathlib import Path |
18 | 19 |
|
19 | 20 | import typer |
20 | | -from cli_core_yo.certs import resolve_https_certs, shared_dayhoff_certs_dir |
21 | 21 | from cli_core_yo.server import ( |
22 | 22 | display_host, |
23 | 23 | latest_log, |
|
28 | 28 | ) |
29 | 29 | from rich.console import Console |
30 | 30 |
|
| 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 | + |
31 | 68 | from bloom_lims.config import ( |
32 | 69 | DEFAULT_BLOOM_WEB_PORT, |
33 | 70 | apply_runtime_environment, |
|
0 commit comments