From ab59923dae646cc0a0f76a286dca115e62a337bc Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Sat, 2 Nov 2024 13:51:12 -0400 Subject: [PATCH] feat(opnsense-config): Add MaybeString type to preserve xml serialization of empty elements --- harmony-rs/Cargo.lock | 23 + harmony-rs/opnsense-config/Cargo.toml | 3 + harmony-rs/opnsense-config/src/config.rs | 2 + .../opnsense-config/src/infra/generic_xml.rs | 217 ++--- .../opnsense-config/src/infra/maybe_string.rs | 173 ++++ harmony-rs/opnsense-config/src/infra/mod.rs | 1 + .../opnsense-config/src/modules/dhcp.rs | 124 ++- .../opnsense-config/src/modules/opnsense.rs | 778 +++++++++--------- 8 files changed, 780 insertions(+), 541 deletions(-) create mode 100644 harmony-rs/opnsense-config/src/infra/maybe_string.rs diff --git a/harmony-rs/Cargo.lock b/harmony-rs/Cargo.lock index a115db3..57e2bb8 100644 --- a/harmony-rs/Cargo.lock +++ b/harmony-rs/Cargo.lock @@ -440,6 +440,12 @@ dependencies = [ "cipher", ] +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "digest" version = "0.10.7" @@ -1242,6 +1248,7 @@ dependencies = [ "async-trait", "env_logger", "log", + "pretty_assertions", "russh", "russh-keys", "serde", @@ -1426,6 +1433,16 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "pretty_assertions" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" +dependencies = [ + "diff", + "yansi", +] + [[package]] name = "primeorder" version = "0.13.6" @@ -2594,6 +2611,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + [[package]] name = "yaserde" version = "0.11.1" diff --git a/harmony-rs/opnsense-config/Cargo.toml b/harmony-rs/opnsense-config/Cargo.toml index 7f6894d..ca7a3ea 100644 --- a/harmony-rs/opnsense-config/Cargo.toml +++ b/harmony-rs/opnsense-config/Cargo.toml @@ -17,3 +17,6 @@ xml-rs = "0.8" thiserror = "1.0" async-trait = { workspace = true } tokio = { workspace = true } + +[dev-dependencies] +pretty_assertions = "1.4.1" diff --git a/harmony-rs/opnsense-config/src/config.rs b/harmony-rs/opnsense-config/src/config.rs index 79829c6..233ae69 100644 --- a/harmony-rs/opnsense-config/src/config.rs +++ b/harmony-rs/opnsense-config/src/config.rs @@ -194,6 +194,8 @@ mod tests { let serialized = yaserde::ser::to_string_with_config(&config.opnsense, &yaserde_cfg).unwrap(); fs::write("/tmp/serialized.xml", &serialized).unwrap(); + std::process::Command::new("xmllint").arg("/tmp/serialized.xml").arg("--output").arg("/tmp/serialized.xmllint.xml").status().expect("xmllint failed"); + assert_eq!(config_file_str, serialized); } diff --git a/harmony-rs/opnsense-config/src/infra/generic_xml.rs b/harmony-rs/opnsense-config/src/infra/generic_xml.rs index 6e1d1a5..1e70a71 100644 --- a/harmony-rs/opnsense-config/src/infra/generic_xml.rs +++ b/harmony-rs/opnsense-config/src/infra/generic_xml.rs @@ -1,21 +1,5 @@ -use xml::reader::{EventReader, XmlEvent as ReadEvent}; -use xml::writer::{EventWriter, XmlEvent as WriteEvent}; +use xml::reader::XmlEvent as ReadEvent; use yaserde::{ser, YaDeserialize as YaDeserializeTrait, YaSerialize as YaSerializeTrait}; -use yaserde_derive::{YaDeserialize, YaSerialize}; - -#[derive(Debug, PartialEq, Default, YaDeserialize)] -pub struct Parent { - // pub rawxml_child: RawXml, - pub string_child: String, - pub child_child: Child, -} - -#[derive(Debug, PartialEq, Default, YaDeserialize)] -pub struct Child { - pub child_val: String, - pub child_val2: String, - pub child_option: Option, -} #[derive(Debug, PartialEq, Default)] pub struct RawXml(String); @@ -131,119 +115,100 @@ impl YaSerializeTrait for RawXml { todo!() } } -// impl YaSerializeTrait for RawXml { -// fn serialize( -// &self, -// writer: &mut yaserde::ser::Serializer, -// ) -> Result<(), String> { -// let mut reader = EventReader::from_str(&self.0); -// loop { -// match reader.next() { -// Ok(ReadEvent::StartElement { -// name, -// attributes, -// namespace, -// }) => { -// let write = WriteEvent::from(reader.next().unwrap()); -// writer -// .write(WriteEvent::StartElement { -// name: name.clone(), -// attributes: attributes.clone(), -// namespace: namespace.clone(), -// }) -// .map_err(|e| e.to_string())?; -// } -// Ok(ReadEvent::EndElement { name }) => { -// writer -// .write(WriteEvent::EndElement { name: Some(name) }) -// .map_err(|e| e.to_string())?; -// } -// Ok(ReadEvent::Characters(content)) => { -// writer -// .write(WriteEvent::Characters(&content)) -// .map_err(|e| e.to_string())?; -// } -// Ok(ReadEvent::Eof) => break, -// Err(e) => return Err(e.to_string()), -// _ => {} -// } -// } -// Ok(()) -// } -// } -// -#[test] -fn rawxml_should_buffer_empty_element() { - let rawxml: RawXml = yaserde::de::from_str("").unwrap(); - assert_eq!(rawxml.0, String::from("")); -} -#[test] -fn rawxml_should_buffer_elements_with_different_case_as_they_are() { - let xml = ""; - let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); - assert_eq!(rawxml.0, String::from(xml)); -} +#[cfg(test)] +mod test { + use super::*; + use yaserde_derive::YaDeserialize; + use yaserde_derive::YaSerialize; -#[test] -fn rawxml_should_buffer_elements_with_attributes() { - let xml = r#""#; - let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); - assert_eq!(rawxml.0, String::from(xml)); -} - -#[test] -fn rawxml_should_handle_complex_documents() { - let xml = r#"1060s00101024102401ignore204816384"#; - let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); - assert_eq!(rawxml.0, String::from(xml)); -} - -#[test] -fn rawxml_should_serialize_simple_documents() { - let xml = r#""#; - let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); - assert_eq!(yaserde::ser::to_string(&rawxml).unwrap(), xml); -} - -#[test] -fn rawxml_should_serialize_complex_documents() { - let xml = r#"1060s00101024102401ignore204816384"#; - let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); - assert_eq!(yaserde::ser::to_string(&rawxml).unwrap(), xml); -} - -#[test] -fn rawxml_should_allow_siblings_before() { - #[derive(YaDeserialize, YaSerialize)] - struct Config { - paul: Vec, - raw: RawXml, + #[derive(Debug, PartialEq, Default, YaDeserialize)] + pub struct Parent { + // pub rawxml_child: RawXml, + pub string_child: String, + pub child_child: Child, } - let xml = r#"bobobpatateallo something"#; - let config: Config = yaserde::de::from_str(xml).unwrap(); - assert_eq!(yaserde::ser::to_string(&config).unwrap(), xml); -} -#[test] -fn rawxml_should_allow_siblings_after() { - #[derive(YaDeserialize, YaSerialize)] - struct Config { - raw: RawXml, - paul: Vec, + #[derive(Debug, PartialEq, Default, YaDeserialize)] + pub struct Child { + pub child_val: String, + pub child_val2: String, + pub child_option: Option, } - let xml = r#"allo somethingbobobpatate"#; - let config: Config = yaserde::de::from_str(xml).unwrap(); - assert_eq!(config.paul.get(0).unwrap(), "bobob"); - assert_eq!(config.paul.get(1).unwrap(), "patate"); - assert_eq!(config.paul.len(), 2); - assert_eq!(config.raw.0, "allo something"); - assert_eq!(yaserde::ser::to_string(&config).unwrap(), xml); -} -#[test] -fn rawxml_should_allow_being_end_of_document() { - let xml = r#"allo somethingbobobpatate"#; - let config: RawXml = yaserde::de::from_str(xml).unwrap(); - assert_eq!(yaserde::ser::to_string(&config).unwrap(), xml); + #[test] + fn rawxml_should_buffer_empty_element() { + let rawxml: RawXml = yaserde::de::from_str("").unwrap(); + assert_eq!(rawxml.0, String::from("")); + } + + #[test] + fn rawxml_should_buffer_elements_with_different_case_as_they_are() { + let xml = ""; + let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); + assert_eq!(rawxml.0, String::from(xml)); + } + + #[test] + fn rawxml_should_buffer_elements_with_attributes() { + let xml = r#""#; + let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); + assert_eq!(rawxml.0, String::from(xml)); + } + + #[test] + fn rawxml_should_handle_complex_documents() { + let xml = r#"1060s00101024102401ignore204816384"#; + let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); + assert_eq!(rawxml.0, String::from(xml)); + } + + #[test] + fn rawxml_should_serialize_simple_documents() { + let xml = r#""#; + let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); + assert_eq!(yaserde::ser::to_string(&rawxml).unwrap(), xml); + } + + #[test] + fn rawxml_should_serialize_complex_documents() { + let xml = r#"1060s00101024102401ignore204816384"#; + let rawxml: RawXml = yaserde::de::from_str(xml).unwrap(); + assert_eq!(yaserde::ser::to_string(&rawxml).unwrap(), xml); + } + + #[test] + fn rawxml_should_allow_siblings_before() { + #[derive(YaDeserialize, YaSerialize)] + struct Config { + paul: Vec, + raw: RawXml, + } + let xml = r#"bobobpatateallo something"#; + let config: Config = yaserde::de::from_str(xml).unwrap(); + assert_eq!(yaserde::ser::to_string(&config).unwrap(), xml); + } + + #[test] + fn rawxml_should_allow_siblings_after() { + #[derive(YaDeserialize, YaSerialize)] + struct Config { + raw: RawXml, + paul: Vec, + } + let xml = r#"allo somethingbobobpatate"#; + let config: Config = yaserde::de::from_str(xml).unwrap(); + assert_eq!(config.paul.get(0).unwrap(), "bobob"); + assert_eq!(config.paul.get(1).unwrap(), "patate"); + assert_eq!(config.paul.len(), 2); + assert_eq!(config.raw.0, "allo something"); + assert_eq!(yaserde::ser::to_string(&config).unwrap(), xml); + } + + #[test] + fn rawxml_should_allow_being_end_of_document() { + let xml = r#"allo somethingbobobpatate"#; + let config: RawXml = yaserde::de::from_str(xml).unwrap(); + assert_eq!(yaserde::ser::to_string(&config).unwrap(), xml); + } } diff --git a/harmony-rs/opnsense-config/src/infra/maybe_string.rs b/harmony-rs/opnsense-config/src/infra/maybe_string.rs new file mode 100644 index 0000000..7c7f4c9 --- /dev/null +++ b/harmony-rs/opnsense-config/src/infra/maybe_string.rs @@ -0,0 +1,173 @@ +use xml::reader::XmlEvent as ReadEvent; +use xml::writer::XmlEvent as WriteEvent; +use yaserde::{ser, YaDeserialize as YaDeserializeTrait, YaSerialize as YaSerializeTrait}; + +#[derive(Debug, PartialEq, Default)] +pub struct MaybeString { + field_name: String, + content: Option, +} + +impl YaDeserializeTrait for MaybeString { + fn deserialize( + reader: &mut yaserde::de::Deserializer, + ) -> Result { + let field_name = match reader.peek()? { + ReadEvent::StartElement { + name, attributes, .. + } => { + if attributes.len() > 0 { + return Err(String::from( + "Attributes not currently supported by MaybeString", + )); + } + + name.local_name.clone() + } + _ => return Err(String::from("Unsupporte ReadEvent type")), + }; + reader.next_event()?; + + let content = match reader.peek()? { + ReadEvent::Characters(content) => Some(content.clone()), + ReadEvent::EndElement { name } => { + if name.local_name != field_name { + return Err(format!( + "Invalid EndElement, expected {field_name} but got {}", + name.local_name + )); + } + None + } + _ => return Err(String::from("Unsupporte ReadEvent type")), + }; + + Ok(Self { + field_name, + content, + }) + } +} + +impl YaSerializeTrait for MaybeString { + fn serialize(&self, writer: &mut ser::Serializer) -> Result<(), String> { + let start_element_event = WriteEvent::start_element(self.field_name.as_str()); + writer.write(start_element_event).expect("Writer failed"); + match &self.content { + Some(content) => { + writer + .write(WriteEvent::characters(content)) + .expect("Writer failed"); + } + None => {} + }; + + writer + .write(WriteEvent::end_element()) + .expect("Writer failed"); + Ok(()) + } + + fn serialize_attributes( + &self, + _attributes: Vec, + _namespace: xml::namespace::Namespace, + ) -> Result< + ( + Vec, + xml::namespace::Namespace, + ), + String, + > { + unimplemented!("MaybeString does not currently support attributes") + } +} + +#[cfg(test)] +mod test { + use super::*; + use pretty_assertions::assert_eq; + use yaserde_derive::YaDeserialize; + use yaserde_derive::YaSerialize; + + #[derive(Debug, PartialEq, Default, YaDeserialize, YaSerialize)] + struct TestStruct { + maybe: MaybeString, + } + + #[test] + fn maybe_string_should_deserialize_empty_element() { + let initial_xml = ""; + let test_struct: TestStruct = + yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct"); + println!("Got test_struct {:?}", test_struct); + assert_eq!( + test_struct, + TestStruct { + maybe: MaybeString { + field_name: String::from("maybe"), + content: None + } + } + ); + } + + #[test] + fn maybe_string_should_deserialize_content() { + let initial_xml = "some content"; + let test_struct: TestStruct = + yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct"); + println!("Got test_struct {:?}", test_struct); + assert_eq!( + test_struct, + TestStruct { + maybe: MaybeString { + field_name: String::from("maybe"), + content: Some(String::from("some content")) + } + } + ); + } + + #[test] + fn maybe_string_should_deserialize_empty_long_format() { + let initial_xml = ""; + let test_struct: TestStruct = + yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct"); + println!("Got test_struct {:?}", test_struct); + assert_eq!( + test_struct, + TestStruct { + maybe: MaybeString { + field_name: String::from("maybe"), + content: None + } + } + ); + } + + #[test] + fn maybe_string_should_serialize_to_empty_element() { + let initial_xml = + r#""#; + let test_struct: TestStruct = + yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct"); + println!("Got test_struct {:?}", test_struct); + assert_eq!( + yaserde::ser::to_string(&test_struct).expect("should serialize teststruct"), + initial_xml + ); + } + + #[test] + fn maybe_string_should_serialize_content() { + let initial_xml = r#"some content"#; + let test_struct: TestStruct = + yaserde::de::from_str(initial_xml).expect("Shoudl deserialize teststruct"); + println!("Got test_struct {:?}", test_struct); + assert_eq!( + yaserde::ser::to_string(&test_struct).expect("should serialize teststruct"), + initial_xml + ); + } +} diff --git a/harmony-rs/opnsense-config/src/infra/mod.rs b/harmony-rs/opnsense-config/src/infra/mod.rs index 66b22fc..2563d9c 100644 --- a/harmony-rs/opnsense-config/src/infra/mod.rs +++ b/harmony-rs/opnsense-config/src/infra/mod.rs @@ -1,3 +1,4 @@ pub mod generic_xml; +pub mod maybe_string; diff --git a/harmony-rs/opnsense-config/src/modules/dhcp.rs b/harmony-rs/opnsense-config/src/modules/dhcp.rs index 8d7172a..92972dc 100644 --- a/harmony-rs/opnsense-config/src/modules/dhcp.rs +++ b/harmony-rs/opnsense-config/src/modules/dhcp.rs @@ -1,4 +1,8 @@ use super::opnsense::{OPNsense, StaticMap}; +use crate::infra::maybe_string::MaybeString; +use crate::modules::opnsense::NumberOption; +use crate::modules::opnsense::Range; +use yaserde_derive::{YaDeserialize, YaSerialize}; pub struct DhcpConfig<'a> { opnsense: &'a mut OPNsense, @@ -14,10 +18,10 @@ impl<'a> DhcpConfig<'a> { mac, ipaddr, hostname, - descr: Some("Automatically generated".into()), - winsserver: None, - dnsserver: None, - ntpserver: None, + descr: Default::default(), + winsserver: Default::default(), + dnsserver: Default::default(), + ntpserver: Default::default(), }; self.opnsense.dhcpd.lan.staticmaps.push(static_map); } @@ -26,3 +30,115 @@ impl<'a> DhcpConfig<'a> { &self.opnsense.dhcpd.lan.staticmaps } } + +#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] +#[yaserde(rename = "dhcpd")] +pub struct Dhcpd { + #[yaserde(rename = "lan")] + pub lan: DhcpInterface, +} + +#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] +pub struct DhcpInterface { + pub enable: i32, + pub gateway: String, + pub domain: String, + #[yaserde(rename = "ddnsdomainalgorithm")] + pub ddns_domain_algorithm: String, + #[yaserde(rename = "numberoptions")] + pub number_options: Vec, + #[yaserde(rename = "range")] + pub range: Range, + pub winsserver: MaybeString, + pub dnsserver: MaybeString, + pub ntpserver: MaybeString, + #[yaserde(rename = "staticmap")] + pub staticmaps: Vec, + pub pool: MaybeString, +} + +#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] +pub struct DhcpRange { + #[yaserde(rename = "from")] + pub from: String, + #[yaserde(rename = "to")] + pub to: String, +} + +#[cfg(test)] +mod test { + use super::*; + use pretty_assertions::assert_eq; + + #[test] + fn dhcpd_should_deserialize_serialize_identical() { + let dhcpd: Dhcpd = + yaserde::de::from_str(SERIALIZED_DHCPD).expect("Deserialize Dhcpd failed"); + + let yaserde_cfg = yaserde::ser::Config { + perform_indent: true, + write_document_declaration: false, + ..Default::default() + }; + assert_eq!( + yaserde::ser::to_string_with_config(&dhcpd, &yaserde_cfg) + .expect("Serialize Dhcpd failed"), + SERIALIZED_DHCPD + ); + } + + const SERIALIZED_DHCPD: &str = " + + 1 + 192.168.20.1 + somedomain.yourlocal.mcd + hmac-md5 + + + + + 192.168.20.50 + 192.168.20.200 + + + 192.168.20.1 + + + 55:55:55:55:55:1c + 192.168.20.160 + somehost983 + someservire8 + + + + + + 55:55:55:55:55:1c + 192.168.20.155 + somehost893 + + + + + + 55:55:55:55:55:1c + 192.168.20.165 + somehost893 + + + + + + + 55:55:55:55:55:1c + 192.168.20.50 + hostswitch2 + switch-2 (bottom) + + + + + + +"; +} diff --git a/harmony-rs/opnsense-config/src/modules/opnsense.rs b/harmony-rs/opnsense-config/src/modules/opnsense.rs index 6b2c602..9daa437 100644 --- a/harmony-rs/opnsense-config/src/modules/opnsense.rs +++ b/harmony-rs/opnsense-config/src/modules/opnsense.rs @@ -1,13 +1,15 @@ +use super::dhcp::Dhcpd; +use crate::infra::{generic_xml::RawXml, maybe_string::MaybeString}; use yaserde_derive::{YaDeserialize, YaSerialize}; #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] #[yaserde(rename = "opnsense")] pub struct OPNsense { - pub dhcpd: Dhcpd, pub theme: String, pub sysctl: Sysctl, pub system: RawXml, - pub interfaces: Interfaces, + pub interfaces: RawXml, + pub dhcpd: Dhcpd, pub snmpd: Snmpd, pub syslog: Syslog, pub nat: Nat, @@ -19,7 +21,7 @@ pub struct OPNsense { #[yaserde(rename = "OPNsense")] pub opnsense: OPNsenseConfig, pub staticroutes: StaticRoutes, - pub ca: Option, + pub ca: MaybeString, pub gateways: Gateways, pub cert: Cert, pub dhcpdv6: DhcpDv6, @@ -71,9 +73,9 @@ pub struct Revision { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Options { - pub path: Option, - pub host: Option, - pub code: Option, + pub path: MaybeString, + pub host: MaybeString, + pub code: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -85,18 +87,18 @@ pub struct Filters { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Rule { #[yaserde(attribute)] - pub uuid: Option, + pub uuid: MaybeString, #[yaserde(rename = "associated-rule-id")] - pub associated_rule_id: Option, + pub associated_rule_id: MaybeString, #[yaserde(rename = "type")] - pub r#type: Option, + pub r#type: MaybeString, pub interface: String, pub ipprotocol: String, pub statetype: String, pub descr: String, - pub direction: Option, - pub category: Option, - pub quick: Option, + pub direction: MaybeString, + pub category: MaybeString, + pub quick: MaybeString, pub protocol: String, pub source: Source, pub destination: Destination, @@ -112,8 +114,8 @@ pub struct Source { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Destination { - pub network: Option, - pub address: Option, + pub network: MaybeString, + pub address: MaybeString, pub port: Option, } @@ -125,7 +127,7 @@ pub struct Username { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Sysctl { - pub item: SysctlItem, + pub item: Vec, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -135,26 +137,12 @@ pub struct SysctlItem { pub value: String, } -#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] -pub struct Dhcpd { - #[yaserde(rename = "lan")] - pub lan: DhcpInterface, -} - -#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] -pub struct DhcpRange { - #[yaserde(rename = "from")] - pub from: String, - #[yaserde(rename = "to")] - pub to: String, -} - #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct System { #[yaserde(rename = "use_mfs_tmp")] - pub use_mfs_tmp: Option, + pub use_mfs_tmp: MaybeString, #[yaserde(rename = "use_mfs_var")] - pub use_mfs_var: Option, + pub use_mfs_var: MaybeString, pub serialspeed: u32, pub primaryconsole: String, pub secondaryconsole: String, @@ -189,12 +177,12 @@ pub struct System { pub sudo_allow_group: String, pub enablenatreflectionhelper: String, pub rulesetoptimization: String, - pub maximumstates: Option, - pub maximumfrags: Option, - pub aliasesresolveinterval: Option, - pub maximumtableentries: Option, + pub maximumstates: MaybeString, + pub maximumfrags: MaybeString, + pub aliasesresolveinterval: MaybeString, + pub maximumtableentries: MaybeString, pub language: String, - pub dnsserver: Option, + pub dnsserver: MaybeString, #[yaserde(rename = "dns1gw")] pub dns1gw: String, #[yaserde(rename = "dns2gw")] @@ -212,21 +200,21 @@ pub struct System { #[yaserde(rename = "dns8gw")] pub dns8gw: String, pub dnsallowoverride: u8, - pub dnsallowoverride_exclude: Option, + pub dnsallowoverride_exclude: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Ssh { pub group: String, pub noauto: u8, - pub interfaces: Option, - pub kex: Option, - pub ciphers: Option, - pub macs: Option, - pub keys: Option, + pub interfaces: MaybeString, + pub kex: MaybeString, + pub ciphers: MaybeString, + pub macs: MaybeString, + pub keys: MaybeString, pub enabled: String, pub passwordauth: u8, - pub keysig: Option, + pub keysig: MaybeString, pub permitrootlogin: u8, } @@ -234,12 +222,12 @@ pub struct Ssh { pub struct Firmware { #[yaserde(attribute)] pub version: String, - pub mirror: Option, - pub flavour: Option, + pub mirror: MaybeString, + pub flavour: MaybeString, pub plugins: String, #[yaserde(rename = "type")] - pub firmware_type: Option, - pub subscription: Option, + pub firmware_type: MaybeString, + pub subscription: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -261,16 +249,16 @@ pub struct Group { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct User { pub name: String, - pub descr: Option, + pub descr: MaybeString, pub scope: String, - pub groupname: Option, + pub groupname: MaybeString, pub password: String, pub uid: u32, - pub expires: Option, - pub authorizedkeys: Option, - pub ipsecpsk: Option, - pub otp_seed: Option, - pub shell: Option, + pub expires: MaybeString, + pub authorizedkeys: MaybeString, + pub ipsecpsk: MaybeString, + pub otp_seed: MaybeString, + pub shell: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -278,18 +266,16 @@ pub struct WebGui { pub protocol: String, #[yaserde(rename = "ssl-certref")] pub ssl_certref: String, - pub port: Option, + pub port: MaybeString, #[yaserde(rename = "ssl-ciphers")] - pub ssl_ciphers: Option, - pub interfaces: Option, + pub ssl_ciphers: MaybeString, + pub interfaces: MaybeString, - pub compression: Option, + pub compression: MaybeString, } use std::collections::HashMap; -use crate::infra::generic_xml::RawXml; - #[derive(Default, PartialEq, Debug)] pub struct Interfaces { pub interfaces: HashMap, @@ -302,50 +288,31 @@ pub struct Interface { pub descr: String, pub enable: u8, #[yaserde(rename = "spoofmac")] - pub spoof_mac: Option, + pub spoof_mac: MaybeString, pub internal_dynamic: Option, - pub ipaddr: Option, + pub ipaddr: MaybeString, #[yaserde(rename = "blockpriv")] pub block_priv: Option, #[yaserde(rename = "blockbogons")] pub block_bogons: Option, pub lock: Option, #[yaserde(rename = "type")] - pub r#type: Option, + pub r#type: MaybeString, #[yaserde(rename = "virtual")] - pub r#virtual: Option, - pub subnet: Option, + pub r#virtual: MaybeString, + pub subnet: MaybeString, pub networks: Option, - pub subnetv6: Option, - pub ipaddrv6: Option, + pub subnetv6: MaybeString, + pub ipaddrv6: MaybeString, #[yaserde(rename = "track6-interface")] - pub track6_interface: Option, + pub track6_interface: MaybeString, #[yaserde(rename = "track6-prefix-id")] - pub track6_prefix_id: Option, -} - -#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] -pub struct DhcpInterface { - pub enable: i32, - pub gateway: String, - pub pool: Option, - pub domain: String, - #[yaserde(rename = "ddnsdomainalgorithm")] - pub ddns_domain_algorithm: String, - #[yaserde(rename = "numberoptions")] - pub number_options: Vec, - #[yaserde(rename = "range")] - pub range: Range, - pub winsserver: Option, - pub dnsserver: String, - pub ntpserver: Option, - #[yaserde(rename = "staticmap")] - pub staticmaps: Vec, + pub track6_prefix_id: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct NumberOption { - item: Option, + item: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -361,16 +328,16 @@ pub struct StaticMap { pub mac: String, pub ipaddr: String, pub hostname: String, - pub descr: Option, - pub winsserver: Option, - pub dnsserver: Option, - pub ntpserver: Option, + pub descr: Option, + pub winsserver: MaybeString, + pub dnsserver: MaybeString, + pub ntpserver: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Snmpd { - pub syslocation: Option, - pub syscontact: Option, + pub syslocation: MaybeString, + pub syscontact: MaybeString, pub rocommunity: String, } @@ -397,10 +364,10 @@ pub struct Outbound { pub struct NatRule { pub protocol: String, pub interface: String, - pub category: Option, + pub category: MaybeString, pub ipprotocol: String, - pub descr: Option, - pub tag: Option, + pub descr: MaybeString, + pub tag: MaybeString, pub tagged: Option, pub poolopts: PoolOpts, #[yaserde(rename = "associated-rule-id")] @@ -423,14 +390,14 @@ pub struct PoolOpts { pub struct Updated { pub username: String, pub time: f64, - pub description: Option, + pub description: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Created { pub username: String, pub time: f64, - pub description: Option, + pub description: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -455,8 +422,8 @@ pub struct OPNsenseConfig { #[yaserde(rename = "Syslog")] pub syslog: Option, #[yaserde(rename = "TrafficShaper")] - pub traffic_shaper: Option, - pub unboundplus: Option, + pub traffic_shaper: Option, + pub unboundplus: Option, pub wireguard: Option, #[yaserde(rename = "Swanctl")] pub swanctl: Swanctl, @@ -475,13 +442,13 @@ pub struct OPNsenseConfig { struct IDS { #[yaserde(attribute)] version: String, - rules: Option, - policies: Option, + rules: MaybeString, + policies: MaybeString, #[yaserde(rename = "userDefinedRules")] - user_defined_rules: Option, - files: Option, + user_defined_rules: MaybeString, + files: MaybeString, #[yaserde(rename = "fileTags")] - file_tags: Option, + file_tags: MaybeString, general: IDSGeneral, } @@ -492,8 +459,8 @@ pub struct IDSGeneral { promisc: Option, interfaces: String, homenet: String, - defaultPacketSize: Option, - UpdateCron: Option, + defaultPacketSize: MaybeString, + UpdateCron: MaybeString, AlertLogrotate: String, AlertSaveLogs: u8, MPMAlgo: String, @@ -501,14 +468,14 @@ pub struct IDSGeneral { syslog: Option, syslog_eve: Option, LogPayload: Option, - verbosity: Option, + verbosity: MaybeString, } #[derive(Debug, YaSerialize, YaDeserialize, PartialEq)] pub struct Detect { Profile: String, - toclient_groups: Option, - toserver_groups: Option, + toclient_groups: MaybeString, + toserver_groups: MaybeString, } #[derive(Debug, YaSerialize, YaDeserialize, PartialEq)] @@ -517,13 +484,13 @@ pub struct IPsec { #[yaserde(attribute)] version: String, general: GeneralIpsec, - keyPairs: Option, - preSharedKeys: Option, + keyPairs: MaybeString, + preSharedKeys: MaybeString, } #[derive(Debug, YaSerialize, YaDeserialize, PartialEq)] pub struct GeneralIpsec { - enabled: Option, + enabled: MaybeString, } #[derive(Debug, YaSerialize, YaDeserialize, PartialEq)] @@ -563,21 +530,21 @@ struct GeneralMonit { startdelay: u32, mailserver: String, port: u16, - username: Option, - password: Option, + username: MaybeString, + password: MaybeString, ssl: u8, sslversion: String, sslverify: u8, logfile: String, - statefile: Option, - eventqueuePath: Option, - eventqueueSlots: Option, + statefile: MaybeString, + eventqueuePath: MaybeString, + eventqueueSlots: MaybeString, httpdEnabled: u8, httpdUsername: String, httpdPassword: String, httpdPort: u16, - httpdAllow: Option, - mmonitUrl: Option, + httpdAllow: MaybeString, + mmonitUrl: MaybeString, mmonitTimeout: u32, mmonitRegisterCredentials: u8, } @@ -589,10 +556,10 @@ struct Alert { enabled: u8, recipient: String, noton: u8, - events: Option, - format: Option, + events: MaybeString, + format: MaybeString, reminder: u32, - description: Option, + description: MaybeString, } #[derive(Debug, YaSerialize, YaDeserialize, PartialEq)] @@ -601,22 +568,22 @@ struct Service { uuid: String, enabled: u8, name: String, - description: Option, + description: MaybeString, #[yaserde(rename = "type")] r#type: String, - pidfile: Option, + pidfile: MaybeString, #[yaserde(rename = "match")] - r#match: Option, - path: Option, + r#match: MaybeString, + path: MaybeString, timeout: u32, starttimeout: u32, - address: Option, - interface: Option, - start: Option, - stop: Option, + address: MaybeString, + interface: MaybeString, + start: MaybeString, + stop: MaybeString, tests: String, - depends: Option, - polltime: Option, + depends: MaybeString, + polltime: MaybeString, } #[derive(Debug, YaSerialize, YaDeserialize, PartialEq)] @@ -628,7 +595,7 @@ struct Test { r#type: String, condition: String, action: String, - path: Option, + path: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -666,11 +633,11 @@ pub struct Netflow { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Capture { #[yaserde(rename = "interfaces")] - pub interfaces: Option, + pub interfaces: MaybeString, #[yaserde(rename = "egress_only")] pub egress_only: Option, #[yaserde(rename = "version")] - pub version: Option, + pub version: MaybeString, #[yaserde(rename = "targets")] pub targets: Option, } @@ -691,9 +658,9 @@ pub struct Zones { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Zone { #[yaserde(attribute)] - pub uuid: Option, + pub uuid: MaybeString, #[yaserde(rename = "name")] - pub name: Option, + pub name: MaybeString, // Add other fields as needed } @@ -707,9 +674,9 @@ pub struct Templates { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Template { #[yaserde(attribute)] - pub uuid: Option, + pub uuid: MaybeString, #[yaserde(rename = "name")] - pub name: Option, + pub name: MaybeString, // Add other fields as needed } @@ -723,9 +690,9 @@ pub struct Jobs { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Job { #[yaserde(attribute)] - pub uuid: Option, + pub uuid: MaybeString, #[yaserde(rename = "name")] - pub name: Option, + pub name: MaybeString, // Add other fields as needed } @@ -739,9 +706,9 @@ pub struct Targets { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Target { #[yaserde(attribute)] - pub uuid: Option, + pub uuid: MaybeString, #[yaserde(rename = "name")] - pub name: Option, + pub name: MaybeString, // Add other fields as needed } @@ -758,7 +725,7 @@ pub struct Firewall { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct LvTemplate { #[yaserde(attribute)] - pub version: Option, + pub version: MaybeString, #[yaserde(rename = "templates")] pub templates: Option, } @@ -766,7 +733,7 @@ pub struct LvTemplate { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Category { #[yaserde(attribute)] - pub version: Option, + pub version: MaybeString, #[yaserde(rename = "categories")] pub categories: Option, } @@ -780,19 +747,19 @@ pub struct Categories { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct CategoryItem { #[yaserde(attribute)] - pub uuid: Option, + pub uuid: MaybeString, #[yaserde(rename = "name")] - pub name: Option, + pub name: MaybeString, #[yaserde(rename = "auto")] pub auto: Option, #[yaserde(rename = "color")] - pub color: Option, + pub color: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Alias { #[yaserde(attribute)] - pub version: Option, + pub version: MaybeString, #[yaserde(rename = "geoip")] pub geoip: Option, #[yaserde(rename = "aliases")] @@ -802,7 +769,7 @@ pub struct Alias { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct GeoIP { #[yaserde(rename = "url")] - pub url: Option, + pub url: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -819,13 +786,13 @@ pub struct AliasItem { pub name: String, #[yaserde(rename = "type")] pub r#type: String, - pub interface: Option, + pub interface: MaybeString, pub counters: String, - pub updatefreq: Option, + pub updatefreq: MaybeString, pub content: String, - pub categories: Option, - pub description: Option, - pub proto: Option, + pub categories: MaybeString, + pub description: MaybeString, + pub proto: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -855,20 +822,20 @@ pub struct ConfigGeneral { pub enabled: i32, #[yaserde(rename = "error_pages")] pub error_pages: String, - pub icpPort: Option, + pub icpPort: MaybeString, pub logging: Logging, - pub alternateDNSservers: Option, + pub alternateDNSservers: MaybeString, pub dnsV4First: i32, pub forwardedForHandling: String, pub uriWhitespaceHandling: String, pub enablePinger: i32, pub useViaHeader: i32, pub suppressVersion: i32, - pub connecttimeout: Option, + pub connecttimeout: MaybeString, #[yaserde(rename = "VisibleEmail")] pub visible_email: String, #[yaserde(rename = "VisibleHostname")] - pub visible_hostname: Option, + pub visible_hostname: MaybeString, pub cache: Cache, pub traffic: Traffic, pub parentproxy: ParentProxy, @@ -877,8 +844,8 @@ pub struct ConfigGeneral { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Logging { pub enable: Enable, - pub ignoreLogACL: Option, - pub target: Option, + pub ignoreLogACL: MaybeString, + pub target: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -897,8 +864,8 @@ pub struct LocalCache { pub enabled: i32, pub directory: String, pub cache_mem: i32, - pub maximum_object_size: Option, - pub maximum_object_size_in_memory: Option, + pub maximum_object_size: MaybeString, + pub maximum_object_size_in_memory: MaybeString, pub memory_cache_mode: String, pub size: i32, pub l1: i32, @@ -919,13 +886,13 @@ pub struct Traffic { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct ParentProxy { pub enabled: i32, - pub host: Option, + pub host: MaybeString, pub enableauth: i32, - pub user: Option, - pub password: Option, - pub port: Option, - pub localdomains: Option, - pub localips: Option, + pub user: MaybeString, + pub password: MaybeString, + pub port: MaybeString, + pub localdomains: MaybeString, + pub localips: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -935,14 +902,14 @@ pub struct Forward { pub sslbumpport: i32, pub sslbump: i32, pub sslurlonly: i32, - pub sslcertificate: Option, - pub sslnobumpsites: Option, + pub sslcertificate: MaybeString, + pub sslnobumpsites: MaybeString, pub ssl_crtd_storage_max_size: i32, pub sslcrtd_children: i32, pub snmp_enable: i32, pub snmp_port: i32, pub snmp_password: String, - pub ftpInterfaces: Option, + pub ftpInterfaces: MaybeString, pub ftpPort: i32, pub ftpTransparentMode: i32, pub addACLforInterfaceSubnets: i32, @@ -954,15 +921,15 @@ pub struct Forward { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Acl { - pub allowedSubnets: Option, - pub unrestricted: Option, - pub bannedHosts: Option, - pub whiteList: Option, - pub blackList: Option, - pub browser: Option, - pub mimeType: Option, - pub googleapps: Option, - pub youtube: Option, + pub allowedSubnets: MaybeString, + pub unrestricted: MaybeString, + pub bannedHosts: MaybeString, + pub whiteList: MaybeString, + pub blackList: MaybeString, + pub browser: MaybeString, + pub mimeType: MaybeString, + pub googleapps: MaybeString, + pub youtube: MaybeString, pub safePorts: String, pub sslPorts: String, pub remoteACLs: RemoteAcls, @@ -970,8 +937,8 @@ pub struct Acl { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct RemoteAcls { - pub blacklists: Option, - pub UpdateCron: Option, + pub blacklists: MaybeString, + pub UpdateCron: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -986,13 +953,13 @@ pub struct Icap { pub EnablePreview: i32, pub PreviewSize: i32, pub OptionsTTL: i32, - pub exclude: Option, + pub exclude: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Authentication { - pub method: Option, - pub authEnforceGroup: Option, + pub method: MaybeString, + pub authEnforceGroup: MaybeString, pub realm: String, pub credentialsttl: i32, pub children: i32, @@ -1003,7 +970,7 @@ pub struct Pac {} #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct ErrorPages { - pub template: Option, + pub template: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1011,7 +978,7 @@ pub struct ConfigSyslog { #[yaserde(attribute)] pub version: String, pub general: SyslogGeneral, - pub destinations: Option, + pub destinations: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1019,16 +986,6 @@ pub struct SyslogGeneral { pub enabled: i32, } -#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] -#[yaserde(rename = "TrafficShaper")] -pub struct TrafficShaper { - #[yaserde(attribute)] - pub version: String, - pub pipes: Option, - pub queues: Option, - pub rules: Option, -} - #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct UnboundPlus { #[yaserde(attribute)] @@ -1038,32 +995,32 @@ pub struct UnboundPlus { pub acls: Acls, pub dnsbl: Dnsbl, pub forwarding: Forwarding, - pub dots: Option, + pub dots: MaybeString, pub hosts: Hosts, - pub aliases: Option, - pub domains: Option, + pub aliases: MaybeString, + pub domains: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct UnboundGeneral { pub enabled: i32, pub port: i32, - pub stats: Option, - pub active_interface: Option, - pub dnssec: Option, - pub dns64: Option, - pub dns64prefix: Option, - pub noarecords: Option, + pub stats: MaybeString, + pub active_interface: MaybeString, + pub dnssec: MaybeString, + pub dns64: MaybeString, + pub dns64prefix: MaybeString, + pub noarecords: MaybeString, pub regdhcp: i32, - pub regdhcpdomain: Option, + pub regdhcpdomain: MaybeString, pub regdhcpstatic: i32, - pub noreglladdr6: Option, - pub noregrecords: Option, - pub txtsupport: Option, - pub cacheflush: Option, + pub noreglladdr6: MaybeString, + pub noregrecords: MaybeString, + pub txtsupport: MaybeString, + pub cacheflush: MaybeString, pub local_zone_type: String, - pub outgoing_interface: Option, - pub enable_wpad: Option, + pub outgoing_interface: MaybeString, + pub enable_wpad: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1074,36 +1031,36 @@ pub struct Advanced { pub prefetchkey: i32, pub dnssecstripped: i32, pub serveexpired: i32, - pub serveexpiredreplyttl: Option, - pub serveexpiredttl: Option, + pub serveexpiredreplyttl: MaybeString, + pub serveexpiredttl: MaybeString, pub serveexpiredttlreset: i32, - pub serveexpiredclienttimeout: Option, + pub serveexpiredclienttimeout: MaybeString, pub qnameminstrict: i32, pub extendedstatistics: i32, pub logqueries: i32, pub logreplies: i32, pub logtagqueryreply: i32, - pub logservfail: Option, - pub loglocalactions: Option, + pub logservfail: MaybeString, + pub loglocalactions: MaybeString, pub logverbosity: i32, pub valloglevel: i32, - pub privatedomain: Option, - pub privateaddress: Option, - pub insecuredomain: Option, - pub msgcachesize: Option, - pub rrsetcachesize: Option, - pub outgoingnumtcp: Option, - pub incomingnumtcp: Option, - pub numqueriesperthread: Option, - pub outgoingrange: Option, - pub jostletimeout: Option, - pub cachemaxttl: Option, - pub cachemaxnegativettl: Option, - pub cacheminttl: Option, - pub infrahostttl: Option, - pub infrakeepprobing: Option, - pub infracachenumhosts: Option, - pub unwantedreplythreshold: Option, + pub privatedomain: MaybeString, + pub privateaddress: MaybeString, + pub insecuredomain: MaybeString, + pub msgcachesize: MaybeString, + pub rrsetcachesize: MaybeString, + pub outgoingnumtcp: MaybeString, + pub incomingnumtcp: MaybeString, + pub numqueriesperthread: MaybeString, + pub outgoingrange: MaybeString, + pub jostletimeout: MaybeString, + pub cachemaxttl: MaybeString, + pub cachemaxnegativettl: MaybeString, + pub cacheminttl: MaybeString, + pub infrahostttl: MaybeString, + pub infrakeepprobing: MaybeString, + pub infracachenumhosts: MaybeString, + pub unwantedreplythreshold: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1115,14 +1072,14 @@ pub struct Acls { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Dnsbl { pub enabled: i32, - pub safesearch: Option, + pub safesearch: MaybeString, #[yaserde(rename = "type")] - pub r#type: Option, - pub lists: Option, - pub whitelists: Option, - pub blocklists: Option, - pub wildcards: Option, - pub address: Option, + pub r#type: MaybeString, + pub lists: MaybeString, + pub whitelists: MaybeString, + pub blocklists: MaybeString, + pub wildcards: MaybeString, + pub address: MaybeString, pub nxdomain: i32, } @@ -1145,8 +1102,8 @@ pub struct Host { pub hostname: String, pub domain: String, pub rr: String, - pub mxprio: Option, - pub mx: Option, + pub mxprio: MaybeString, + pub mx: MaybeString, pub server: String, pub description: String, } @@ -1187,12 +1144,12 @@ pub struct WireguardServerItem { pub pubkey: String, pub privkey: String, pub port: i32, - pub mtu: Option, - pub dns: Option, + pub mtu: MaybeString, + pub dns: MaybeString, pub tunneladdress: String, pub disableroutes: i32, - pub gateway: Option, - pub carp_depend_on: Option, + pub gateway: MaybeString, + pub carp_depend_on: MaybeString, pub peers: String, } @@ -1215,11 +1172,11 @@ pub struct WireguardClientItem { pub enabled: i32, pub name: String, pub pubkey: String, - pub psk: Option, + pub psk: MaybeString, pub tunneladdress: String, - pub serveraddress: Option, - pub serverport: Option, - pub keepalive: Option, + pub serveraddress: MaybeString, + pub serverport: MaybeString, + pub keepalive: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1227,16 +1184,16 @@ pub struct Swanctl { #[yaserde(attribute)] pub version: String, #[yaserde(rename = "Connections")] - pub connections: Option, - pub locals: Option, - pub remotes: Option, - pub children: Option, + pub connections: MaybeString, + pub locals: MaybeString, + pub remotes: MaybeString, + pub children: MaybeString, #[yaserde(rename = "Pools")] - pub pools: Option, + pub pools: MaybeString, #[yaserde(rename = "VTIs")] - pub vtis: Option, + pub vtis: MaybeString, #[yaserde(rename = "SPDs")] - pub spds: Option, + pub spds: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1269,15 +1226,15 @@ pub struct Account { pub uuid: String, pub enabled: i32, pub service: String, - pub protocol: Option, - pub server: Option, + pub protocol: MaybeString, + pub server: MaybeString, pub username: String, pub password: String, #[yaserde(rename = "resourceId")] - pub resource_id: Option, + pub resource_id: MaybeString, pub hostnames: String, pub wildcard: i32, - pub zone: Option, + pub zone: MaybeString, pub checkip: String, #[yaserde(rename = "checkip_timeout")] pub checkip_timeout: i32, @@ -1292,9 +1249,9 @@ pub struct Account { pub struct ConfigOpenVPN { #[yaserde(attribute)] pub version: String, - pub Overwrites: Option, - pub Instances: Option, - pub StaticKeys: Option, + pub Overwrites: MaybeString, + pub Instances: MaybeString, + pub StaticKeys: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1313,17 +1270,17 @@ pub struct HAProxy { pub backends: HAProxyBackends, pub servers: HAProxyServers, pub healthchecks: HAProxyHealthChecks, - pub acls: Option, - pub actions: Option, - pub luas: Option, - pub fcgis: Option, - pub errorfiles: Option, - pub mapfiles: Option, - pub groups: Option, - pub users: Option, - pub cpus: Option, - pub resolvers: Option, - pub mailers: Option, + pub acls: MaybeString, + pub actions: MaybeString, + pub luas: MaybeString, + pub fcgis: MaybeString, + pub errorfiles: MaybeString, + pub mapfiles: MaybeString, + pub groups: MaybeString, + pub users: MaybeString, + pub cpus: MaybeString, + pub resolvers: MaybeString, + pub mailers: MaybeString, pub maintenance: Maintenance, } @@ -1338,19 +1295,19 @@ pub struct CronJobs { #[yaserde(rename = "syncCerts")] pub sync_certs: u32, #[yaserde(rename = "syncCertsCron")] - pub sync_certs_cron: Option, + pub sync_certs_cron: MaybeString, #[yaserde(rename = "updateOcsp")] pub update_ocsp: u32, #[yaserde(rename = "updateOcspCron")] - pub update_ocsp_cron: Option, + pub update_ocsp_cron: MaybeString, #[yaserde(rename = "reloadService")] pub reload_service: u32, #[yaserde(rename = "reloadServiceCron")] - pub reload_service_cron: Option, + pub reload_service_cron: MaybeString, #[yaserde(rename = "restartService")] pub restart_service: u32, #[yaserde(rename = "restartServiceCron")] - pub restart_service_cron: Option, + pub restart_service_cron: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1358,7 +1315,7 @@ pub struct HaProxyGeneral { pub enabled: i32, pub gracefulStop: i32, pub hardStopAfter: String, - pub closeSpreadTime: Option, + pub closeSpreadTime: MaybeString, pub seamlessReload: i32, pub storeOcsp: i32, pub showIntro: i32, @@ -1373,18 +1330,18 @@ pub struct HaProxyGeneral { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Peers { pub enabled: i32, - pub name1: Option, - pub listen1: Option, + pub name1: MaybeString, + pub listen1: MaybeString, pub port1: i32, - pub name2: Option, - pub listen2: Option, + pub name2: MaybeString, + pub listen2: MaybeString, pub port2: i32, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Tuning { pub root: i32, - pub maxConnections: Option, + pub maxConnections: MaybeString, pub nbthread: i32, pub sslServerVerify: String, pub maxDHSize: i32, @@ -1392,28 +1349,28 @@ pub struct Tuning { pub spreadChecks: i32, pub bogusProxyEnabled: i32, pub luaMaxMem: i32, - pub customOptions: Option, + pub customOptions: MaybeString, #[yaserde(rename = "ssl_defaultsEnabled")] pub ssl_defaults_enabled: i32, pub ssl_bindOptions: String, pub ssl_minVersion: String, - pub ssl_maxVersion: Option, + pub ssl_maxVersion: MaybeString, pub ssl_cipherList: String, pub ssl_cipherSuites: String, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct HaProxyDefaults { - pub maxConnections: Option, - pub maxConnectionsServers: Option, + pub maxConnections: MaybeString, + pub maxConnectionsServers: MaybeString, pub timeoutClient: String, pub timeoutConnect: String, - pub timeoutCheck: Option, + pub timeoutCheck: MaybeString, pub timeoutServer: String, pub retries: i32, pub redispatch: String, pub init_addr: String, - pub customOptions: Option, + pub customOptions: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1421,7 +1378,7 @@ pub struct HaProxyLogging { pub host: String, pub facility: String, pub level: String, - pub length: Option, + pub length: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1429,12 +1386,12 @@ pub struct Stats { pub enabled: i32, pub port: i32, pub remoteEnabled: i32, - pub remoteBind: Option, + pub remoteBind: MaybeString, pub authEnabled: i32, - pub users: Option, - pub allowedUsers: Option, - pub allowedGroups: Option, - pub customOptions: Option, + pub users: MaybeString, + pub allowedUsers: MaybeString, + pub allowedGroups: MaybeString, + pub customOptions: MaybeString, pub prometheus_enabled: i32, pub prometheus_bind: String, pub prometheus_path: String, @@ -1445,7 +1402,7 @@ pub struct HaProxyCache { pub enabled: i32, pub totalMaxSize: i32, pub maxAge: i32, - pub maxObjectSize: Option, + pub maxObjectSize: MaybeString, pub processVary: i32, pub maxSecondaryEntries: i32, } @@ -1465,17 +1422,17 @@ pub struct Frontend { pub name: String, pub description: String, pub bind: String, - pub bindOptions: Option, + pub bindOptions: MaybeString, pub mode: String, pub defaultBackend: String, pub ssl_enabled: i32, - pub ssl_certificates: Option, - pub ssl_default_certificate: Option, - pub ssl_customOptions: Option, + pub ssl_certificates: MaybeString, + pub ssl_default_certificate: MaybeString, + pub ssl_customOptions: MaybeString, pub ssl_advancedEnabled: i32, pub ssl_bindOptions: String, pub ssl_minVersion: String, - pub ssl_maxVersion: Option, + pub ssl_maxVersion: MaybeString, pub ssl_cipherList: String, pub ssl_cipherSuites: String, pub ssl_hstsEnabled: i32, @@ -1484,29 +1441,29 @@ pub struct Frontend { pub ssl_hstsMaxAge: i32, pub ssl_clientAuthEnabled: i32, pub ssl_clientAuthVerify: String, - pub ssl_clientAuthCAs: Option, - pub ssl_clientAuthCRLs: Option, + pub ssl_clientAuthCAs: MaybeString, + pub ssl_clientAuthCRLs: MaybeString, pub basicAuthEnabled: i32, - pub basicAuthUsers: Option, - pub basicAuthGroups: Option, - pub tuning_maxConnections: Option, - pub tuning_timeoutClient: Option, - pub tuning_timeoutHttpReq: Option, - pub tuning_timeoutHttpKeepAlive: Option, - pub linkedCpuAffinityRules: Option, - pub tuning_shards: Option, + pub basicAuthUsers: MaybeString, + pub basicAuthGroups: MaybeString, + pub tuning_maxConnections: MaybeString, + pub tuning_timeoutClient: MaybeString, + pub tuning_timeoutHttpReq: MaybeString, + pub tuning_timeoutHttpKeepAlive: MaybeString, + pub linkedCpuAffinityRules: MaybeString, + pub tuning_shards: MaybeString, pub logging_dontLogNull: i32, pub logging_dontLogNormal: i32, pub logging_logSeparateErrors: i32, pub logging_detailedLog: i32, pub logging_socketStats: i32, - pub stickiness_pattern: Option, - pub stickiness_dataTypes: Option, + pub stickiness_pattern: MaybeString, + pub stickiness_dataTypes: MaybeString, pub stickiness_expire: String, pub stickiness_size: String, pub stickiness_counter: i32, pub stickiness_counter_key: String, - pub stickiness_length: Option, + pub stickiness_length: MaybeString, pub stickiness_connRatePeriod: String, pub stickiness_sessRatePeriod: String, pub stickiness_httpReqRatePeriod: String, @@ -1520,9 +1477,9 @@ pub struct Frontend { pub prometheus_enabled: i32, pub prometheus_path: String, pub connectionBehaviour: String, - pub customOptions: Option, - pub linkedActions: Option, - pub linkedErrorfiles: Option, + pub customOptions: MaybeString, + pub linkedActions: MaybeString, + pub linkedErrorfiles: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1542,7 +1499,7 @@ pub struct Backend { #[yaserde(rename = "name")] pub name: String, #[yaserde(rename = "description")] - pub description: Option, + pub description: MaybeString, #[yaserde(rename = "mode")] pub mode: String, #[yaserde(rename = "algorithm")] @@ -1550,35 +1507,35 @@ pub struct Backend { #[yaserde(rename = "random_draws")] pub random_draws: Option, #[yaserde(rename = "proxyProtocol")] - pub proxy_protocol: Option, + pub proxy_protocol: MaybeString, #[yaserde(rename = "linkedServers")] - pub linked_servers: Option, + pub linked_servers: MaybeString, #[yaserde(rename = "linkedFcgi")] - pub linked_fcgi: Option, + pub linked_fcgi: MaybeString, #[yaserde(rename = "linkedResolver")] - pub linked_resolver: Option, + pub linked_resolver: MaybeString, #[yaserde(rename = "resolverOpts")] - pub resolver_opts: Option, + pub resolver_opts: MaybeString, #[yaserde(rename = "resolvePrefer")] - pub resolve_prefer: Option, + pub resolve_prefer: MaybeString, #[yaserde(rename = "source")] - pub source: Option, + pub source: MaybeString, #[yaserde(rename = "healthCheckEnabled")] pub health_check_enabled: u8, #[yaserde(rename = "healthCheck")] - pub health_check: Option, + pub health_check: MaybeString, #[yaserde(rename = "healthCheckLogStatus")] pub health_check_log_status: u8, #[yaserde(rename = "checkInterval")] - pub check_interval: Option, + pub check_interval: MaybeString, #[yaserde(rename = "checkDownInterval")] - pub check_down_interval: Option, + pub check_down_interval: MaybeString, #[yaserde(rename = "healthCheckFall")] - pub health_check_fall: Option, + pub health_check_fall: MaybeString, #[yaserde(rename = "healthCheckRise")] - pub health_check_rise: Option, + pub health_check_rise: MaybeString, #[yaserde(rename = "linkedMailer")] - pub linked_mailer: Option, + pub linked_mailer: MaybeString, #[yaserde(rename = "http2Enabled")] pub http2_enabled: u8, #[yaserde(rename = "http2Enabled_nontls")] @@ -1590,21 +1547,21 @@ pub struct Backend { #[yaserde(rename = "persistence_cookiemode")] pub persistence_cookiemode: String, #[yaserde(rename = "persistence_cookiename")] - pub persistence_cookiename: Option, + pub persistence_cookiename: MaybeString, #[yaserde(rename = "persistence_stripquotes")] pub persistence_stripquotes: u8, #[yaserde(rename = "stickiness_pattern")] pub stickiness_pattern: String, #[yaserde(rename = "stickiness_dataTypes")] - pub stickiness_data_types: Option, + pub stickiness_data_types: MaybeString, #[yaserde(rename = "stickiness_expire")] pub stickiness_expire: String, #[yaserde(rename = "stickiness_size")] pub stickiness_size: String, #[yaserde(rename = "stickiness_cookiename")] - pub stickiness_cookiename: Option, + pub stickiness_cookiename: MaybeString, #[yaserde(rename = "stickiness_cookielength")] - pub stickiness_cookielength: Option, + pub stickiness_cookielength: MaybeString, #[yaserde(rename = "stickiness_connRatePeriod")] pub stickiness_conn_rate_period: String, #[yaserde(rename = "stickiness_sessRatePeriod")] @@ -1620,31 +1577,31 @@ pub struct Backend { #[yaserde(rename = "basicAuthEnabled")] pub basic_auth_enabled: u8, #[yaserde(rename = "basicAuthUsers")] - pub basic_auth_users: Option, + pub basic_auth_users: MaybeString, #[yaserde(rename = "basicAuthGroups")] - pub basic_auth_groups: Option, + pub basic_auth_groups: MaybeString, #[yaserde(rename = "tuning_timeoutConnect")] - pub tuning_timeout_connect: Option, + pub tuning_timeout_connect: MaybeString, #[yaserde(rename = "tuning_timeoutCheck")] - pub tuning_timeout_check: Option, + pub tuning_timeout_check: MaybeString, #[yaserde(rename = "tuning_timeoutServer")] - pub tuning_timeout_server: Option, + pub tuning_timeout_server: MaybeString, #[yaserde(rename = "tuning_retries")] - pub tuning_retries: Option, + pub tuning_retries: MaybeString, #[yaserde(rename = "customOptions")] - pub custom_options: Option, + pub custom_options: MaybeString, #[yaserde(rename = "tuning_defaultserver")] - pub tuning_defaultserver: Option, + pub tuning_defaultserver: MaybeString, #[yaserde(rename = "tuning_noport")] pub tuning_noport: u8, #[yaserde(rename = "tuning_httpreuse")] - pub tuning_httpreuse: Option, + pub tuning_httpreuse: MaybeString, #[yaserde(rename = "tuning_caching")] pub tuning_caching: u8, #[yaserde(rename = "linkedActions")] - pub linked_actions: Option, + pub linked_actions: MaybeString, #[yaserde(rename = "linkedErrorfiles")] - pub linked_errorfiles: Option, + pub linked_errorfiles: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1664,13 +1621,13 @@ pub struct HAProxyServer { #[yaserde(rename = "name")] pub name: String, #[yaserde(rename = "description")] - pub description: Option, + pub description: MaybeString, #[yaserde(rename = "address")] pub address: String, #[yaserde(rename = "port")] pub port: u16, #[yaserde(rename = "checkport")] - pub checkport: Option, + pub checkport: MaybeString, #[yaserde(rename = "mode")] pub mode: String, #[yaserde(rename = "multiplexer_protocol")] @@ -1678,41 +1635,41 @@ pub struct HAProxyServer { #[yaserde(rename = "type")] pub server_type: String, #[yaserde(rename = "serviceName")] - pub service_name: Option, + pub service_name: MaybeString, #[yaserde(rename = "number")] - pub number: Option, + pub number: MaybeString, #[yaserde(rename = "linkedResolver")] - pub linked_resolver: Option, + pub linked_resolver: MaybeString, #[yaserde(rename = "resolverOpts")] - pub resolver_opts: Option, + pub resolver_opts: MaybeString, #[yaserde(rename = "resolvePrefer")] - pub resolve_prefer: Option, + pub resolve_prefer: MaybeString, #[yaserde(rename = "ssl")] pub ssl: u8, #[yaserde(rename = "sslSNI")] - pub ssl_sni: Option, + pub ssl_sni: MaybeString, #[yaserde(rename = "sslVerify")] pub ssl_verify: u8, #[yaserde(rename = "sslCA")] - pub ssl_ca: Option, + pub ssl_ca: MaybeString, #[yaserde(rename = "sslCRL")] - pub ssl_crl: Option, + pub ssl_crl: MaybeString, #[yaserde(rename = "sslClientCertificate")] - pub ssl_client_certificate: Option, + pub ssl_client_certificate: MaybeString, #[yaserde(rename = "maxConnections")] - pub max_connections: Option, + pub max_connections: MaybeString, #[yaserde(rename = "weight")] pub weight: u32, #[yaserde(rename = "checkInterval")] - pub check_interval: Option, + pub check_interval: MaybeString, #[yaserde(rename = "checkDownInterval")] - pub check_down_interval: Option, + pub check_down_interval: MaybeString, #[yaserde(rename = "source")] - pub source: Option, + pub source: MaybeString, #[yaserde(rename = "advanced")] - pub advanced: Option, + pub advanced: MaybeString, #[yaserde(rename = "unix_socket")] - pub unix_socket: Option, + pub unix_socket: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1726,43 +1683,43 @@ pub struct HAProxyHealthCheck { #[yaserde(attribute)] pub uuid: String, pub name: String, - pub description: Option, + pub description: MaybeString, #[yaserde(rename = "type")] pub health_check_type: String, pub interval: String, pub ssl: String, #[yaserde(rename = "sslSNI")] - pub ssl_sni: Option, + pub ssl_sni: MaybeString, pub force_ssl: u8, - pub checkport: Option, + pub checkport: MaybeString, pub http_method: String, pub http_uri: String, - pub http_version: Option, + pub http_version: MaybeString, #[yaserde(rename = "http_host")] - pub http_host: Option, + pub http_host: MaybeString, #[yaserde(rename = "http_expressionEnabled")] pub http_expression_enabled: Option, - pub http_expression: Option, - pub http_negate: Option, - pub http_value: Option, - pub tcp_enabled: Option, + pub http_expression: MaybeString, + pub http_negate: MaybeString, + pub http_value: MaybeString, + pub tcp_enabled: MaybeString, #[yaserde(rename = "tcp_sendValue")] - pub tcp_send_value: Option, + pub tcp_send_value: MaybeString, #[yaserde(rename = "tcp_matchType")] - pub tcp_match_type: Option, + pub tcp_match_type: MaybeString, #[yaserde(rename = "tcp_matchValue")] - pub tcp_match_value: Option, - pub tcp_negate: Option, + pub tcp_match_value: MaybeString, + pub tcp_negate: MaybeString, #[yaserde(rename = "agentPort")] - pub agent_port: Option, - pub mysql_user: Option, - pub mysql_post41: Option, - pub pgsql_user: Option, + pub agent_port: MaybeString, + pub mysql_user: MaybeString, + pub mysql_post41: MaybeString, + pub pgsql_user: MaybeString, #[yaserde(alias = "smtpDomain")] - pub smtp_domain: Option, - pub esmtp_domain: Option, + pub smtp_domain: MaybeString, + pub esmtp_domain: MaybeString, #[yaserde(rename = "dbUser")] - pub db_user: Option, + pub db_user: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1770,7 +1727,7 @@ pub struct StaticRoutes { #[yaserde(attribute)] pub version: String, #[yaserde(rename = "route")] - pub route: Option, // Assuming it can be empty, use Option + pub route: MaybeString, // Assuming it can be empty, use Option } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1779,7 +1736,7 @@ pub struct Ca {} // Empty struct for #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Gateways { #[yaserde(rename = "gateway_item")] - pub gateway_item: Option, // Assuming it can be empty, use Option + pub gateway_item: MaybeString, // Assuming it can be empty, use Option } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1816,8 +1773,8 @@ pub struct Vip { pub gateway: String, pub noexpand: u32, pub nobind: u32, - pub password: Option, - pub vhid: Option, + pub password: MaybeString, + pub vhid: MaybeString, pub advbase: u32, pub advskew: u32, pub descr: String, @@ -1826,12 +1783,11 @@ pub struct Vip { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct OpenVpn { #[yaserde(rename = "openvpn-server")] - pub openvpn_server: Option, + pub openvpn_server: MaybeString, #[yaserde(rename = "openvpn-client")] - pub openvpn_client: Option, + pub openvpn_client: MaybeString, } - #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Ppps { pub ppp: Ppp, @@ -1858,18 +1814,18 @@ pub struct Dyndnses { pub struct Dyndns { #[yaserde(rename = "type")] pub r#type: String, - pub username: Option, + pub username: MaybeString, pub password: String, pub host: String, - pub mx: Option, + pub mx: MaybeString, pub interface: String, - pub zoneid: Option, - pub resourceid: Option, - pub ttl: Option, - pub updateurl: Option, - pub resultmatch: Option, + pub zoneid: MaybeString, + pub resourceid: MaybeString, + pub ttl: MaybeString, + pub updateurl: MaybeString, + pub resultmatch: MaybeString, pub requestif: String, - pub descr: Option, + pub descr: MaybeString, pub id: u32, } @@ -1877,22 +1833,22 @@ pub struct Dyndns { pub struct Vlans { #[yaserde(attribute)] pub version: String, - pub vlan: Option, + pub vlan: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Bridges { - pub bridged: Option, + pub bridged: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Gifs { - pub gif: Option, + pub gif: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Gres { - pub gre: Option, + pub gre: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] @@ -1903,7 +1859,7 @@ pub struct Laggs { #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)] pub struct Wireless { - pub clone: Option, + pub clone: MaybeString, } #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]