asterust-junos 0.5.13

Typed Juniper JunOS config views (interfaces, protocols, routing instances and options, policy options, firewall filters, class of service, system, services) extracted from an asterust config tree.
Documentation
//! `extensible-subscriber-services`
//! `system { services { extensible-subscriber-services { ... } } }`.
//!
//! # See also
//!
//! - [access-profile (Extensible Subscriber Services Manager)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/access-profile-essmd.html)
//! - [commit-interval](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/commit-interval-edit-system-essmd.html)
//! - [dictionary](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/dictionary-essmd.html)
//! - [flat-file-profile (Extensible Subscriber Services)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/flat-file-profile-essmd.html)
//! - [logical-interface-unit-range](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/logical-interface-unit-range-essmd.html)
//! - [maximum-subscribers](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/maximum-subscribers-essmd.html)

use crate::{arg_of, child_block};
use asterust::config::ConfigLine;

/// The `system services extensible-subscriber-services` settings.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct ExtensibleSubscriberServices {
    pub access_profile: Option<String>,
    /// Seconds between commits of op script configurations.
    pub commit_interval: Option<String>,
    pub dictionary: Option<String>,
    pub flat_file_profile: Option<String>,
    /// From `logical-interface-unit-range { low }`.
    pub logical_interface_unit_low: Option<String>,
    /// From `logical-interface-unit-range { high }`.
    pub logical_interface_unit_high: Option<String>,
    pub maximum_subscribers: Option<String>,
}

pub(super) fn parse_extensible_subscriber_services(essmd: &ConfigLine) -> ExtensibleSubscriberServices {
    let range = child_block(essmd, "logical-interface-unit-range");
    let field = |keyword: &str| arg_of(essmd, keyword).map(str::to_string);
    ExtensibleSubscriberServices {
        access_profile: field("access-profile"),
        commit_interval: field("commit-interval"),
        dictionary: field("dictionary"),
        flat_file_profile: field("flat-file-profile"),
        logical_interface_unit_low: range.and_then(|r| arg_of(r, "low")).map(str::to_string),
        logical_interface_unit_high: range.and_then(|r| arg_of(r, "high")).map(str::to_string),
        maximum_subscribers: field("maximum-subscribers"),
    }
}

#[cfg(test)]
mod tests {
    use crate::system::system;
    use asterust::config::juniper;

    // Not from documentation: written from the CLI Reference syntax pages. See the README "Sources".
    #[test]
    fn extracts_the_extensible_subscriber_services() {
        let essmd = system(&juniper::parse_braces(
            r#"
system {
    services {
        extensible-subscriber-services {
            access-profile ess-access;
            commit-interval 60;
            dictionary /var/etc/ess.dict;
            flat-file-profile ess-flat;
            logical-interface-unit-range {
                low 1000;
                high 2000;
            }
            maximum-subscribers 5000;
        }
    }
}
"#,
        ))
        .unwrap()
        .services
        .unwrap()
        .extensible_subscriber_services
        .unwrap();
        assert_eq!(essmd.access_profile.as_deref(), Some("ess-access"));
        assert_eq!(essmd.commit_interval.as_deref(), Some("60"));
        assert_eq!(essmd.dictionary.as_deref(), Some("/var/etc/ess.dict"));
        assert_eq!(essmd.flat_file_profile.as_deref(), Some("ess-flat"));
        assert_eq!(essmd.logical_interface_unit_low.as_deref(), Some("1000"));
        assert_eq!(essmd.logical_interface_unit_high.as_deref(), Some("2000"));
        assert_eq!(essmd.maximum_subscribers.as_deref(), Some("5000"));
    }

    #[test]
    fn no_extensible_subscriber_services_is_none() {
        let services = system(&juniper::parse_braces(
            "system {\n    services {\n        telnet;\n    }\n}\n",
        ))
        .unwrap()
        .services
        .unwrap();
        assert!(services.extensible_subscriber_services.is_none());
    }
}