dfx_core/config/model/
canister_http_adapter.rsuse schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::{path::PathBuf, str::FromStr};
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Default)]
pub enum IncomingSource {
#[default]
Systemd,
Path(PathBuf),
}
#[derive(Clone, Debug, Serialize, Deserialize, Copy, PartialEq, Eq, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum HttpAdapterLogLevel {
Critical,
#[default]
Error,
Warning,
Info,
Debug,
Trace,
}
impl FromStr for HttpAdapterLogLevel {
type Err = String;
fn from_str(input: &str) -> Result<HttpAdapterLogLevel, Self::Err> {
match input {
"critical" => Ok(HttpAdapterLogLevel::Critical),
"error" => Ok(HttpAdapterLogLevel::Error),
"warning" => Ok(HttpAdapterLogLevel::Warning),
"info" => Ok(HttpAdapterLogLevel::Info),
"debug" => Ok(HttpAdapterLogLevel::Debug),
"trace" => Ok(HttpAdapterLogLevel::Trace),
other => Err(format!("Unknown log level: {}", other)),
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct LoggerConfig {
pub level: HttpAdapterLogLevel,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Config {
#[serde(default)]
pub incoming_source: IncomingSource,
pub logger: LoggerConfig,
}
impl Config {
pub fn new(uds_path: PathBuf, log_level: HttpAdapterLogLevel) -> Config {
Config {
incoming_source: IncomingSource::Path(uds_path),
logger: LoggerConfig { level: log_level },
}
}
pub fn get_socket_path(&self) -> Option<PathBuf> {
match &self.incoming_source {
IncomingSource::Systemd => None,
IncomingSource::Path(path) => Some(path.clone()),
}
}
}