Skip to main content

asterust_junos/system/services/
netconf.rs

1//! `system { services { netconf { ... } } }`.
2
3use crate::{arg_of, child_block, has_leaf};
4use asterust::config::ConfigLine;
5
6/// The `netconf ssh` block.
7#[derive(Clone, Debug, PartialEq, Eq)]
8#[non_exhaustive]
9pub struct NetconfSsh {
10    pub port: Option<String>,
11    pub connection_limit: Option<String>,
12    pub rate_limit: Option<String>,
13}
14
15/// The `system services netconf` settings.
16#[derive(Clone, Debug, PartialEq, Eq)]
17#[non_exhaustive]
18pub struct Netconf {
19    pub ssh: Option<NetconfSsh>,
20    pub rfc_compliant: bool,
21}
22
23pub(super) fn parse_netconf(netconf: &ConfigLine) -> Netconf {
24    Netconf {
25        ssh: child_block(netconf, "ssh").map(|ssh| NetconfSsh {
26            port: arg_of(ssh, "port").map(str::to_string),
27            connection_limit: arg_of(ssh, "connection-limit").map(str::to_string),
28            rate_limit: arg_of(ssh, "rate-limit").map(str::to_string),
29        }),
30        rfc_compliant: has_leaf(netconf, "rfc-compliant"),
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use crate::system::system;
37    use asterust::config::juniper;
38
39    #[test]
40    fn bare_netconf_ssh_has_no_settings() {
41        let netconf = system(&juniper::parse_braces(
42            "system {\n    services {\n        netconf {\n            ssh;\n        }\n    }\n}\n",
43        ))
44        .unwrap()
45        .services
46        .unwrap()
47        .netconf
48        .unwrap();
49        let ssh = netconf.ssh.unwrap();
50        assert_eq!(ssh.port, None);
51        assert!(!netconf.rfc_compliant);
52    }
53}