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
//! `password-options`
//! `system { password-options { ... } }`.
//!
//! # See also
//!
//! - [password-options](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/password-options-edit-system.html)

use crate::has_leaf;
use asterust::config::ConfigLine;

/// The `system password-options` settings for local authentication.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct PasswordOptions {
    /// Combine the TACACS+ authorization of a locally authenticated user with its local one.
    pub tacplus_authorization: bool,
}

pub(super) fn parse_password_options(options: &ConfigLine) -> PasswordOptions {
    PasswordOptions {
        tacplus_authorization: has_leaf(options, "tacplus-authorization"),
    }
}

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

    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
    #[test]
    fn extracts_password_options() {
        let options = system(&juniper::parse_braces(
            "system {\n    password-options {\n        tacplus-authorization;\n    }\n}\n",
        ))
        .unwrap()
        .password_options
        .unwrap();
        assert!(options.tacplus_authorization);
    }

    #[test]
    fn no_password_options_is_none() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert!(system.password_options.is_none());
    }
}