Skip to main content

asterust_junos/system/
tacplus_options.rs

1//! `tacplus-options`
2//! `system { tacplus-options { ... } }`.
3//!
4//! # See also
5//!
6//! - [tacplus-options](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/tacplus-options-edit-system.html)
7
8use crate::{arg_of, has_leaf, toggle};
9use asterust::config::ConfigLine;
10
11/// The `system tacplus-options` settings.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct TacplusOptions {
15    pub exclude_cmd_attribute: bool,
16    pub no_cmd_attribute_value: bool,
17    /// Minutes between fetches of the authorization profile.
18    pub authorization_time_interval: Option<String>,
19    pub enhanced_accounting: bool,
20    /// `Some(true)` for `strict-authorization`, `Some(false)` for `no-strict-authorization`.
21    pub strict_authorization: Option<bool>,
22    pub service_name: Option<String>,
23    pub timestamp_and_timezone: bool,
24}
25
26pub(super) fn parse_tacplus_options(options: &ConfigLine) -> TacplusOptions {
27    TacplusOptions {
28        exclude_cmd_attribute: has_leaf(options, "exclude-cmd-attribute"),
29        no_cmd_attribute_value: has_leaf(options, "no-cmd-attribute-value"),
30        authorization_time_interval: arg_of(options, "authorization-time-interval").map(str::to_string),
31        enhanced_accounting: has_leaf(options, "enhanced-accounting"),
32        strict_authorization: toggle(options, "strict-authorization"),
33        service_name: arg_of(options, "service-name").map(str::to_string),
34        timestamp_and_timezone: has_leaf(options, "timestamp-and-timezone"),
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use crate::system::system;
41    use asterust::config::juniper;
42
43    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
44    #[test]
45    fn extracts_tacplus_options() {
46        let options = system(&juniper::parse_braces(
47            r#"
48system {
49    tacplus-options {
50        exclude-cmd-attribute;
51        authorization-time-interval 30;
52        enhanced-accounting;
53        strict-authorization;
54        service-name junos-exec;
55        timestamp-and-timezone;
56    }
57}
58"#,
59        ))
60        .unwrap()
61        .tacplus_options
62        .unwrap();
63        assert!(options.exclude_cmd_attribute);
64        assert!(!options.no_cmd_attribute_value);
65        assert_eq!(options.authorization_time_interval.as_deref(), Some("30"));
66        assert!(options.enhanced_accounting);
67        assert_eq!(options.strict_authorization, Some(true));
68        assert_eq!(options.service_name.as_deref(), Some("junos-exec"));
69        assert!(options.timestamp_and_timezone);
70    }
71
72    #[test]
73    fn reads_no_strict_authorization() {
74        let options = system(&juniper::parse_braces(
75            "system {\n    tacplus-options {\n        no-cmd-attribute-value;\n        no-strict-authorization;\n    }\n}\n",
76        ))
77        .unwrap()
78        .tacplus_options
79        .unwrap();
80        assert!(options.no_cmd_attribute_value);
81        assert_eq!(options.strict_authorization, Some(false));
82        assert_eq!(options.service_name, None);
83    }
84
85    #[test]
86    fn no_tacplus_options_is_none() {
87        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
88        assert!(system.tacplus_options.is_none());
89    }
90}