manta_server/manta_backend_dispatcher.rs
1//! Runtime backend selector — wraps either a CSM or an OpenCHAMI backend
2//! behind a single enum so the rest of the codebase is backend-agnostic.
3
4use csm_rs::backend_connector::Csm;
5use manta_backend_dispatcher::error::Error;
6use ochami_rs::backend_connector::Ochami;
7
8#[derive(Clone)]
9#[allow(clippy::upper_case_acronyms)]
10/// Routes API calls to either a CSM or OCHAMI backend.
11///
12/// All backend-specific trait methods are dispatched via
13/// the `dispatch!` macro defined in the
14/// [`crate::backend_dispatcher`] module.
15#[derive(Debug)]
16pub enum StaticBackendDispatcher {
17 /// HPE Cray System Management (CSM) backend, used by Alps-style
18 /// deployments. Wraps a `csm-rs` HTTP client.
19 CSM(Csm),
20 /// OpenCHAMI backend, used by sites running the open-source CSM
21 /// alternative. Wraps an `ochami-rs` HTTP client.
22 OCHAMI(Ochami),
23}
24
25impl StaticBackendDispatcher {
26 /// Returns `"csm"` or `"ochami"` for the currently-selected variant.
27 /// Cheap, infallible — intended for use as a structured `tracing` field.
28 pub fn backend_kind(&self) -> &'static str {
29 match self {
30 Self::CSM(_) => "csm",
31 Self::OCHAMI(_) => "ochami",
32 }
33 }
34
35 /// Create a new dispatcher for the given backend type.
36 ///
37 /// `backend_type` must be `"csm"` or `"ochami"`;
38 /// any other value returns an error.
39 pub fn new(
40 backend_type: &str,
41 base_url: &str,
42 root_cert: &[u8],
43 socks5_proxy: Option<&str>,
44 ) -> Result<Self, Error> {
45 match backend_type {
46 "csm" => Ok(Self::CSM(Csm::new(base_url, root_cert, socks5_proxy)?)),
47 "ochami" => {
48 Ok(Self::OCHAMI(Ochami::new(base_url, root_cert, socks5_proxy)))
49 }
50 _ => Err(Error::UnsupportedBackend(format!(
51 "Backend '{backend_type}' not supported"
52 ))),
53 }
54 }
55}