trifid/tfclient/src/config.rs

635 lines
17 KiB
Rust
Raw Normal View History

2023-05-14 17:47:49 +00:00
use ipnet::{IpNet, Ipv4Net};
2023-03-30 11:29:02 +00:00
use std::collections::HashMap;
use std::error::Error;
use std::fs;
2023-03-30 11:29:02 +00:00
use std::net::{Ipv4Addr, SocketAddrV4};
2023-03-29 00:42:36 +00:00
2023-11-23 20:23:52 +00:00
use crate::dirs::{config_dir, tfclient_toml, tfdata_toml};
use dnapi_rs::client_blocking::EnrollMeta;
2023-03-29 22:13:04 +00:00
use dnapi_rs::credentials::Credentials;
2023-05-14 17:47:49 +00:00
use log::{debug, info};
use serde::{Deserialize, Serialize};
pub const DEFAULT_PORT: u16 = 8157;
2023-05-14 17:47:49 +00:00
fn default_port() -> u16 {
DEFAULT_PORT
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct TFClientConfig {
#[serde(default = "default_port")]
2023-03-30 21:34:00 +00:00
pub listen_port: u16,
#[serde(default = "bool_false")]
2023-05-14 17:47:49 +00:00
pub disable_automatic_config_updates: bool,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct TFClientData {
2023-03-30 14:43:09 +00:00
pub dh_privkey: Option<Vec<u8>>,
pub creds: Option<Credentials>,
2023-05-14 17:47:49 +00:00
pub meta: Option<EnrollMeta>,
}
pub fn create_config(instance: &str) -> Result<(), Box<dyn Error>> {
info!("Creating config directory...");
2023-06-26 02:00:36 +00:00
fs::create_dir_all(config_dir(instance))?;
info!("Copying default config file to config directory...");
let config = TFClientConfig {
2023-03-30 21:34:00 +00:00
listen_port: DEFAULT_PORT,
disable_automatic_config_updates: false,
};
let config_str = toml::to_string(&config)?;
2023-11-23 20:23:52 +00:00
fs::write(tfclient_toml(instance), config_str)?;
Ok(())
}
pub fn load_config(instance: &str) -> Result<TFClientConfig, Box<dyn Error>> {
info!("Loading config...");
2023-06-26 02:00:36 +00:00
let config_file = tfclient_toml(instance);
if !config_file.exists() {
create_config(instance)?;
}
debug!("opening {}", config_file.as_path().display());
let config_str = fs::read_to_string(config_file)?;
debug!("parsing config file");
let config: TFClientConfig = toml::from_str(&config_str)?;
info!("Loaded config successfully");
Ok(config)
}
pub fn create_cdata(instance: &str) -> Result<(), Box<dyn Error>> {
info!("Creating data directory...");
2023-06-26 02:00:36 +00:00
fs::create_dir_all(config_dir(instance))?;
info!("Copying default data file to config directory...");
2023-05-14 17:47:49 +00:00
let config = TFClientData {
dh_privkey: None,
creds: None,
meta: None,
};
let config_str = toml::to_string(&config)?;
2023-11-23 20:23:52 +00:00
fs::write(tfdata_toml(instance), config_str)?;
Ok(())
}
pub fn load_cdata(instance: &str) -> Result<TFClientData, Box<dyn Error>> {
info!("Loading cdata...");
2023-06-26 02:00:36 +00:00
let config_file = tfdata_toml(instance);
if !config_file.exists() {
create_cdata(instance)?;
}
debug!("opening {}", config_file.as_path().display());
let config_str = fs::read_to_string(config_file)?;
debug!("parsing cdata file");
let config: TFClientData = toml::from_str(&config_str)?;
info!("Loaded cdata successfully");
Ok(config)
}
pub fn save_cdata(instance: &str, data: TFClientData) -> Result<(), Box<dyn Error>> {
info!("Saving cdata...");
2023-06-26 02:00:36 +00:00
let config_file = tfdata_toml(instance);
if !config_file.exists() {
create_cdata(instance)?;
}
debug!("serializing cdata file");
let config: String = toml::to_string(&data)?;
debug!("writing to {}", config_file.as_path().display());
fs::write(config_file, config)?;
info!("Saved cdata successfully");
Ok(())
2023-03-30 11:29:02 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 11:29:02 +00:00
pub struct NebulaConfig {
pub pki: NebulaConfigPki,
#[serde(default = "empty_hashmap")]
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_empty_hashmap")]
2023-03-30 11:29:02 +00:00
pub static_host_map: HashMap<Ipv4Addr, Vec<SocketAddrV4>>,
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_none")]
pub lighthouse: Option<NebulaConfigLighthouse>,
#[serde(skip_serializing_if = "is_none")]
pub listen: Option<NebulaConfigListen>,
#[serde(skip_serializing_if = "is_none")]
pub punchy: Option<NebulaConfigPunchy>,
#[serde(default = "cipher_aes")]
#[serde(skip_serializing_if = "is_cipher_aes")]
pub cipher: NebulaConfigCipher,
#[serde(default = "empty_vec")]
#[serde(skip_serializing_if = "is_empty_vec")]
pub preferred_ranges: Vec<IpNet>,
#[serde(skip_serializing_if = "is_none")]
pub relay: Option<NebulaConfigRelay>,
#[serde(skip_serializing_if = "is_none")]
pub tun: Option<NebulaConfigTun>,
#[serde(skip_serializing_if = "is_none")]
pub logging: Option<NebulaConfigLogging>,
#[serde(skip_serializing_if = "is_none")]
pub sshd: Option<NebulaConfigSshd>,
2023-03-30 14:22:34 +00:00
#[serde(skip_serializing_if = "is_none")]
pub firewall: Option<NebulaConfigFirewall>,
#[serde(default = "u64_1")]
#[serde(skip_serializing_if = "is_u64_1")]
pub routines: u64,
2023-03-30 13:26:31 +00:00
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub stats: Option<NebulaConfigStats>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
2023-05-14 17:47:49 +00:00
pub local_range: Option<Ipv4Net>,
2023-03-30 11:29:02 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 11:29:02 +00:00
pub struct NebulaConfigPki {
pub ca: String,
pub cert: String,
2023-03-30 16:13:29 +00:00
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub key: Option<String>,
2023-03-30 11:29:02 +00:00
#[serde(default = "empty_vec")]
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_empty_vec")]
2023-03-30 11:29:02 +00:00
pub blocklist: Vec<String>,
#[serde(default = "bool_false")]
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_bool_false")]
2023-05-14 17:47:49 +00:00
pub disconnect_invalid: bool,
2023-03-30 11:29:02 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 11:29:02 +00:00
pub struct NebulaConfigLighthouse {
#[serde(default = "bool_false")]
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_bool_false")]
2023-03-30 11:29:02 +00:00
pub am_lighthouse: bool,
#[serde(default = "bool_false")]
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_bool_false")]
2023-03-30 11:29:02 +00:00
pub serve_dns: bool,
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_none")]
2023-03-30 11:29:02 +00:00
pub dns: Option<NebulaConfigLighthouseDns>,
#[serde(default = "u32_10")]
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_u32_10")]
2023-03-30 11:29:02 +00:00
pub interval: u32,
#[serde(default = "empty_vec")]
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_empty_vec")]
2023-03-30 11:29:02 +00:00
pub hosts: Vec<Ipv4Addr>,
#[serde(default = "empty_hashmap")]
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_empty_hashmap")]
pub remote_allow_list: HashMap<Ipv4Net, bool>,
#[serde(default = "empty_hashmap")]
#[serde(skip_serializing_if = "is_empty_hashmap")]
pub local_allow_list: HashMap<Ipv4Net, bool>, // `interfaces` is not supported
2023-03-30 11:29:02 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 11:29:02 +00:00
pub struct NebulaConfigLighthouseDns {
2023-03-30 16:13:29 +00:00
#[serde(default = "string_empty")]
#[serde(skip_serializing_if = "is_string_empty")]
pub host: String,
2023-03-30 11:29:02 +00:00
#[serde(default = "u16_53")]
2023-03-30 13:26:31 +00:00
#[serde(skip_serializing_if = "is_u16_53")]
2023-05-14 17:47:49 +00:00
pub port: u16,
2023-03-30 11:29:02 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub struct NebulaConfigListen {
2023-03-30 16:13:29 +00:00
#[serde(default = "string_empty")]
#[serde(skip_serializing_if = "is_string_empty")]
pub host: String,
2023-03-30 13:26:31 +00:00
#[serde(default = "u16_0")]
#[serde(skip_serializing_if = "is_u16_0")]
pub port: u16,
#[serde(default = "u32_64")]
#[serde(skip_serializing_if = "is_u32_64")]
pub batch: u32,
#[serde(skip_serializing_if = "is_none")]
pub read_buffer: Option<u32>,
#[serde(skip_serializing_if = "is_none")]
2023-05-14 17:47:49 +00:00
pub write_buffer: Option<u32>,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub struct NebulaConfigPunchy {
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub punch: bool,
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub respond: bool,
#[serde(default = "string_1s")]
#[serde(skip_serializing_if = "is_string_1s")]
2023-05-14 17:47:49 +00:00
pub delay: String,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub enum NebulaConfigCipher {
#[serde(rename = "aes")]
Aes,
#[serde(rename = "chachapoly")]
2023-05-14 17:47:49 +00:00
ChaChaPoly,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub struct NebulaConfigRelay {
#[serde(default = "empty_vec")]
#[serde(skip_serializing_if = "is_empty_vec")]
pub relays: Vec<Ipv4Addr>,
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub am_relay: bool,
#[serde(default = "bool_true")]
#[serde(skip_serializing_if = "is_bool_true")]
2023-05-14 17:47:49 +00:00
pub use_relays: bool,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub struct NebulaConfigTun {
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub disabled: bool,
#[serde(skip_serializing_if = "is_none")]
pub dev: Option<String>,
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub drop_local_broadcast: bool,
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub drop_multicast: bool,
#[serde(default = "u64_500")]
#[serde(skip_serializing_if = "is_u64_500")]
pub tx_queue: u64,
#[serde(default = "u64_1300")]
#[serde(skip_serializing_if = "is_u64_1300")]
pub mtu: u64,
#[serde(default = "empty_vec")]
#[serde(skip_serializing_if = "is_empty_vec")]
pub routes: Vec<NebulaConfigTunRouteOverride>,
#[serde(default = "empty_vec")]
#[serde(skip_serializing_if = "is_empty_vec")]
2023-05-14 17:47:49 +00:00
pub unsafe_routes: Vec<NebulaConfigTunUnsafeRoute>,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub struct NebulaConfigTunRouteOverride {
pub mtu: u64,
2023-05-14 17:47:49 +00:00
pub route: Ipv4Net,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub struct NebulaConfigTunUnsafeRoute {
pub route: Ipv4Net,
pub via: Ipv4Addr,
#[serde(default = "u64_1300")]
#[serde(skip_serializing_if = "is_u64_1300")]
pub mtu: u64,
#[serde(default = "i64_100")]
#[serde(skip_serializing_if = "is_i64_100")]
2023-05-14 17:47:49 +00:00
pub metric: i64,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub struct NebulaConfigLogging {
#[serde(default = "loglevel_info")]
#[serde(skip_serializing_if = "is_loglevel_info")]
pub level: NebulaConfigLoggingLevel,
#[serde(default = "format_text")]
#[serde(skip_serializing_if = "is_format_text")]
pub format: NebulaConfigLoggingFormat,
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub disable_timestamp: bool,
#[serde(default = "timestamp")]
#[serde(skip_serializing_if = "is_timestamp")]
2023-05-14 17:47:49 +00:00
pub timestamp_format: String,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub enum NebulaConfigLoggingLevel {
#[serde(rename = "panic")]
Panic,
#[serde(rename = "fatal")]
Fatal,
#[serde(rename = "error")]
Error,
#[serde(rename = "warning")]
Warning,
#[serde(rename = "info")]
Info,
#[serde(rename = "debug")]
2023-05-14 17:47:49 +00:00
Debug,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 13:26:31 +00:00
pub enum NebulaConfigLoggingFormat {
#[serde(rename = "json")]
Json,
#[serde(rename = "text")]
2023-05-14 17:47:49 +00:00
Text,
2023-03-30 13:26:31 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NebulaConfigSshd {
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub enabled: bool,
pub listen: SocketAddrV4,
pub host_key: String,
#[serde(default = "empty_vec")]
#[serde(skip_serializing_if = "is_empty_vec")]
2023-05-14 17:47:49 +00:00
pub authorized_users: Vec<NebulaConfigSshdAuthorizedUser>,
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NebulaConfigSshdAuthorizedUser {
pub user: String,
#[serde(default = "empty_vec")]
#[serde(skip_serializing_if = "is_empty_vec")]
2023-05-14 17:47:49 +00:00
pub keys: Vec<String>,
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "type")]
pub enum NebulaConfigStats {
#[serde(rename = "graphite")]
Graphite(NebulaConfigStatsGraphite),
#[serde(rename = "prometheus")]
2023-05-14 17:47:49 +00:00
Prometheus(NebulaConfigStatsPrometheus),
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NebulaConfigStatsGraphite {
#[serde(default = "string_nebula")]
#[serde(skip_serializing_if = "is_string_nebula")]
pub prefix: String,
#[serde(default = "protocol_tcp")]
#[serde(skip_serializing_if = "is_protocol_tcp")]
pub protocol: NebulaConfigStatsGraphiteProtocol,
pub host: SocketAddrV4,
pub interval: String,
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub message_metrics: bool,
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
2023-05-14 17:47:49 +00:00
pub lighthouse_metrics: bool,
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum NebulaConfigStatsGraphiteProtocol {
#[serde(rename = "tcp")]
Tcp,
#[serde(rename = "udp")]
2023-05-14 17:47:49 +00:00
Udp,
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NebulaConfigStatsPrometheus {
pub listen: String,
pub path: String,
#[serde(default = "string_nebula")]
#[serde(skip_serializing_if = "is_string_nebula")]
pub namespace: String,
#[serde(default = "string_nebula")]
#[serde(skip_serializing_if = "is_string_nebula")]
pub subsystem: String,
pub interval: String,
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
pub message_metrics: bool,
#[serde(default = "bool_false")]
#[serde(skip_serializing_if = "is_bool_false")]
2023-05-14 17:47:49 +00:00
pub lighthouse_metrics: bool,
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 14:22:34 +00:00
pub struct NebulaConfigFirewall {
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub conntrack: Option<NebulaConfigFirewallConntrack>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub inbound: Option<Vec<NebulaConfigFirewallRule>>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub outbound: Option<Vec<NebulaConfigFirewallRule>>,
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 14:22:34 +00:00
pub struct NebulaConfigFirewallConntrack {
#[serde(default = "string_12m")]
#[serde(skip_serializing_if = "is_string_12m")]
pub tcp_timeout: String,
#[serde(default = "string_3m")]
#[serde(skip_serializing_if = "is_string_3m")]
pub udp_timeout: String,
#[serde(default = "string_10m")]
#[serde(skip_serializing_if = "is_string_10m")]
2023-05-14 17:47:49 +00:00
pub default_timeout: String,
2023-03-30 14:22:34 +00:00
}
2023-03-30 14:43:09 +00:00
#[derive(Serialize, Deserialize, Clone, Debug)]
2023-03-30 14:22:34 +00:00
pub struct NebulaConfigFirewallRule {
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub port: Option<String>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub proto: Option<String>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub ca_name: Option<String>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub ca_sha: Option<String>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub host: Option<String>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub group: Option<String>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
pub groups: Option<Vec<String>>,
#[serde(default = "none")]
#[serde(skip_serializing_if = "is_none")]
2023-05-14 17:47:49 +00:00
pub cidr: Option<String>,
2023-03-30 14:22:34 +00:00
}
2023-03-30 11:29:02 +00:00
// Default values for serde
2023-03-30 14:22:34 +00:00
2023-05-14 17:47:49 +00:00
fn string_12m() -> String {
"12m".to_string()
}
fn is_string_12m(s: &str) -> bool {
s == "12m"
}
2023-03-30 14:22:34 +00:00
2023-05-14 17:47:49 +00:00
fn string_3m() -> String {
"3m".to_string()
}
fn is_string_3m(s: &str) -> bool {
s == "3m"
}
2023-03-30 14:22:34 +00:00
2023-05-14 17:47:49 +00:00
fn string_10m() -> String {
"10m".to_string()
}
fn is_string_10m(s: &str) -> bool {
s == "10m"
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn empty_vec<T>() -> Vec<T> {
vec![]
}
fn is_empty_vec<T>(v: &Vec<T>) -> bool {
v.is_empty()
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn empty_hashmap<A, B>() -> HashMap<A, B> {
HashMap::new()
}
fn is_empty_hashmap<A, B>(h: &HashMap<A, B>) -> bool {
h.is_empty()
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn bool_false() -> bool {
false
}
fn is_bool_false(b: &bool) -> bool {
!*b
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn bool_true() -> bool {
true
}
fn is_bool_true(b: &bool) -> bool {
*b
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn u16_53() -> u16 {
53
}
fn is_u16_53(u: &u16) -> bool {
*u == 53
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn u32_10() -> u32 {
10
}
fn is_u32_10(u: &u32) -> bool {
*u == 10
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn u16_0() -> u16 {
0
}
fn is_u16_0(u: &u16) -> bool {
*u == 0
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn u32_64() -> u32 {
64
}
fn is_u32_64(u: &u32) -> bool {
*u == 64
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn string_1s() -> String {
"1s".to_string()
}
fn is_string_1s(s: &str) -> bool {
s == "1s"
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn cipher_aes() -> NebulaConfigCipher {
NebulaConfigCipher::Aes
}
fn is_cipher_aes(c: &NebulaConfigCipher) -> bool {
matches!(c, NebulaConfigCipher::Aes)
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn u64_500() -> u64 {
500
}
fn is_u64_500(u: &u64) -> bool {
*u == 500
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn u64_1300() -> u64 {
1300
}
fn is_u64_1300(u: &u64) -> bool {
*u == 1300
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn i64_100() -> i64 {
100
}
fn is_i64_100(i: &i64) -> bool {
*i == 100
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn loglevel_info() -> NebulaConfigLoggingLevel {
NebulaConfigLoggingLevel::Info
}
fn is_loglevel_info(l: &NebulaConfigLoggingLevel) -> bool {
matches!(l, NebulaConfigLoggingLevel::Info)
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn format_text() -> NebulaConfigLoggingFormat {
NebulaConfigLoggingFormat::Text
}
fn is_format_text(f: &NebulaConfigLoggingFormat) -> bool {
matches!(f, NebulaConfigLoggingFormat::Text)
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn timestamp() -> String {
"2006-01-02T15:04:05Z07:00".to_string()
}
fn is_timestamp(s: &str) -> bool {
s == "2006-01-02T15:04:05Z07:00"
}
2023-03-30 13:26:31 +00:00
2023-05-14 17:47:49 +00:00
fn u64_1() -> u64 {
1
}
fn is_u64_1(u: &u64) -> bool {
*u == 1
}
2023-05-14 17:47:49 +00:00
fn string_nebula() -> String {
"nebula".to_string()
}
fn is_string_nebula(s: &str) -> bool {
s == "nebula"
}
2023-05-14 17:47:49 +00:00
fn string_empty() -> String {
String::new()
}
fn is_string_empty(s: &str) -> bool {
s.is_empty()
}
2023-03-30 16:13:29 +00:00
2023-05-14 17:47:49 +00:00
fn protocol_tcp() -> NebulaConfigStatsGraphiteProtocol {
NebulaConfigStatsGraphiteProtocol::Tcp
}
fn is_protocol_tcp(p: &NebulaConfigStatsGraphiteProtocol) -> bool {
matches!(p, NebulaConfigStatsGraphiteProtocol::Tcp)
}
2023-05-14 17:47:49 +00:00
fn none<T>() -> Option<T> {
None
}
fn is_none<T>(o: &Option<T>) -> bool {
o.is_none()
}