asterust_junos/system/
authentication_secret.rs1use crate::{active_children, secret_value, split_keyword, split_name, Secret};
4use asterust::config::ConfigLine;
5
6#[derive(Clone, Debug, PartialEq, Eq)]
8#[non_exhaustive]
9pub struct AuthenticationSecret {
10 pub method: String,
12 pub value: Secret,
13}
14
15fn from_statement(statement: &str) -> Option<AuthenticationSecret> {
17 let (method, rest) = split_keyword(statement);
18 let value = secret_value((!rest.is_empty()).then(|| split_name(rest).0))?;
19 Some(AuthenticationSecret {
20 method: method.to_string(),
21 value,
22 })
23}
24
25pub(super) fn authentication_secrets(auth: &ConfigLine) -> Vec<AuthenticationSecret> {
27 active_children(auth).filter_map(|c| from_statement(&c.text)).collect()
28}
29
30pub(super) fn password_secrets(system: &ConfigLine, keyword: &str) -> Vec<AuthenticationSecret> {
33 let mut secrets = Vec::new();
34 for child in active_children(system) {
35 if child.text == keyword {
36 secrets.extend(authentication_secrets(child));
37 } else if let Some(secret) = child.arg(keyword).and_then(from_statement) {
38 secrets.push(secret);
39 }
40 }
41 secrets
42}