manta-cli 1.64.3

Another CLI for ALPS
//! Runtime backend selector — wraps either a CSM or an OpenCHAMI backend
//! behind a single enum so the rest of the codebase is backend-agnostic.

use manta_backend_dispatcher::error::Error;
use csm_rs::backend_connector::Csm;
use ochami_rs::backend_connector::Ochami;

#[derive(Clone)]
#[allow(clippy::upper_case_acronyms)]
/// Routes API calls to either a CSM or OCHAMI backend.
///
/// All backend-specific trait methods are dispatched via
/// the [`dispatch!`] macro defined in the `backend_dispatcher`
/// module.
pub enum StaticBackendDispatcher {
  CSM(Csm),
  OCHAMI(Ochami),
}

impl StaticBackendDispatcher {
  /// Create a new dispatcher for the given backend type.
  ///
  /// `backend_type` must be `"csm"` or `"ochami"`;
  /// any other value returns an error.
  pub fn new(
    backend_type: &str,
    base_url: &str,
    root_cert: &[u8],
    socks5_proxy: Option<&str>,
  ) -> Result<Self, Error> {
    match backend_type {
      "csm" => Ok(Self::CSM(Csm::new(base_url, root_cert, socks5_proxy))),
      "ochami" => Ok(Self::OCHAMI(Ochami::new(base_url, root_cert, socks5_proxy))),
      _ => Err(Error::UnsupportedBackend(format!(
        "Backend '{}' not supported",
        backend_type
      ))),
    }
  }
}