Skip to main content

asterust_junos/system/services/
netconf.rs

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