dfx_core/config/model/
canister_http_adapter.rs1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::{path::PathBuf, str::FromStr};
4
5#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Default)]
7pub enum IncomingSource {
10 #[default]
12 Systemd,
13 Path(PathBuf),
15}
16
17#[derive(Clone, Debug, Serialize, Deserialize, Copy, PartialEq, Eq, JsonSchema, Default)]
19#[serde(rename_all = "snake_case")]
20pub enum HttpAdapterLogLevel {
21 Critical,
22 #[default]
23 Error,
24 Warning,
25 Info,
26 Debug,
27 Trace,
28}
29
30impl FromStr for HttpAdapterLogLevel {
31 type Err = String;
32
33 fn from_str(input: &str) -> Result<HttpAdapterLogLevel, Self::Err> {
34 match input {
35 "critical" => Ok(HttpAdapterLogLevel::Critical),
36 "error" => Ok(HttpAdapterLogLevel::Error),
37 "warning" => Ok(HttpAdapterLogLevel::Warning),
38 "info" => Ok(HttpAdapterLogLevel::Info),
39 "debug" => Ok(HttpAdapterLogLevel::Debug),
40 "trace" => Ok(HttpAdapterLogLevel::Trace),
41 other => Err(format!("Unknown log level: {other}")),
42 }
43 }
44}
45
46#[derive(Clone, Debug, Deserialize, Serialize)]
47pub struct LoggerConfig {
48 pub level: HttpAdapterLogLevel,
49}
50
51#[derive(Clone, Debug, Deserialize, Serialize)]
53pub struct Config {
54 #[serde(default)]
56 pub incoming_source: IncomingSource,
57
58 pub logger: LoggerConfig,
59}
60
61impl Config {
62 pub fn new(uds_path: PathBuf, log_level: HttpAdapterLogLevel) -> Config {
63 Config {
64 incoming_source: IncomingSource::Path(uds_path),
65 logger: LoggerConfig { level: log_level },
66 }
67 }
68
69 pub fn get_socket_path(&self) -> Option<PathBuf> {
70 match &self.incoming_source {
71 IncomingSource::Systemd => None,
72 IncomingSource::Path(path) => Some(path.clone()),
73 }
74 }
75}