2019-08-29 14:46:54 -07:00
|
|
|
//! Zebrad Config
|
|
|
|
//!
|
|
|
|
//! See instructions in `commands.rs` to specify the path to your
|
|
|
|
//! application's configuration file and/or command-line options
|
|
|
|
//! for specifying it.
|
|
|
|
|
2020-02-14 13:38:33 -08:00
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
2019-08-29 14:46:54 -07:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2019-10-08 13:57:24 -07:00
|
|
|
use zebra_network::Config as NetworkSection;
|
|
|
|
|
2020-06-17 14:44:24 -07:00
|
|
|
/// Configuration for `zebrad`.
|
|
|
|
///
|
|
|
|
/// The `zebrad` config is a TOML-encoded version of this structure. The meaning
|
|
|
|
/// of each field is described in the documentation, although it may be necessary
|
|
|
|
/// to click through to the sub-structures for each section.
|
2019-12-20 11:20:04 -08:00
|
|
|
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
|
2020-06-18 13:34:05 -07:00
|
|
|
#[serde(deny_unknown_fields, default)]
|
2019-08-29 14:46:54 -07:00
|
|
|
pub struct ZebradConfig {
|
2019-09-09 13:05:42 -07:00
|
|
|
/// Tracing configuration
|
|
|
|
pub tracing: TracingSection,
|
2020-02-14 13:38:33 -08:00
|
|
|
/// Networking configuration
|
2019-10-08 13:57:24 -07:00
|
|
|
pub network: NetworkSection,
|
2020-02-14 13:38:33 -08:00
|
|
|
/// Metrics configuration
|
|
|
|
pub metrics: MetricsSection,
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
|
2019-09-09 13:05:42 -07:00
|
|
|
/// Tracing configuration section.
|
2020-06-04 19:34:06 -07:00
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
2020-06-18 13:34:05 -07:00
|
|
|
#[serde(deny_unknown_fields, default)]
|
2019-09-09 13:05:42 -07:00
|
|
|
pub struct TracingSection {
|
|
|
|
/// The filter used for tracing events.
|
2020-06-04 19:34:06 -07:00
|
|
|
pub filter: Option<String>,
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
|
2020-06-04 19:34:06 -07:00
|
|
|
impl TracingSection {
|
|
|
|
pub fn populated() -> Self {
|
2019-08-29 14:46:54 -07:00
|
|
|
Self {
|
2020-06-04 19:34:06 -07:00
|
|
|
filter: Some("info".to_owned()),
|
2019-08-29 14:46:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 13:38:33 -08:00
|
|
|
|
|
|
|
/// Metrics configuration section.
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
2020-06-18 13:34:05 -07:00
|
|
|
#[serde(deny_unknown_fields, default)]
|
2020-02-14 13:38:33 -08:00
|
|
|
pub struct MetricsSection {
|
|
|
|
pub endpoint_addr: SocketAddr,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for MetricsSection {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2020-06-18 22:44:59 -07:00
|
|
|
endpoint_addr: "0.0.0.0:9999".parse().unwrap(),
|
2020-02-14 13:38:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-09 12:24:28 -07:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2020-06-22 15:36:23 -07:00
|
|
|
use color_eyre::eyre::Result;
|
|
|
|
|
2020-06-09 12:24:28 -07:00
|
|
|
#[test]
|
2020-06-22 15:36:23 -07:00
|
|
|
fn test_toml_ser() -> Result<()> {
|
2020-06-09 12:24:28 -07:00
|
|
|
let default_config = super::ZebradConfig::default();
|
|
|
|
println!("Default config: {:?}", default_config);
|
|
|
|
|
|
|
|
println!("Toml:\n{}", toml::Value::try_from(&default_config)?);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|