Skip to main content

asterust_junos/system/login/
user.rs

1//! `user`
2//! `system { login { user <name> { ... } } }`.
3//!
4//! # See also
5//!
6//! - [user (Access)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/user-edit-system-login.html)
7
8use crate::system::authentication_methods;
9use crate::system::authentication_secret::authentication_secrets;
10use crate::system::AuthenticationSecret;
11use crate::{arg_of, child_block};
12use asterust::config::ConfigLine;
13
14/// A login `user`. Passwords and keys are read only with the `secrets` feature; `authentication_methods` says which
15/// are present.
16#[derive(Clone, Debug, PartialEq, Eq)]
17#[non_exhaustive]
18pub struct LoginUser {
19    pub name: String,
20    pub class: Option<String>,
21    pub uid: Option<String>,
22    pub full_name: Option<String>,
23    /// One entry per authentication statement, e.g. `"encrypted-password"`, `"ssh-rsa"`.
24    pub authentication_methods: Vec<String>,
25    /// The passwords and keys; empty unless the `secrets` feature is enabled.
26    pub authentication_secrets: Vec<AuthenticationSecret>,
27}
28
29pub(super) fn parse_user(name: &str, user: &ConfigLine) -> LoginUser {
30    LoginUser {
31        name: name.to_string(),
32        class: arg_of(user, "class").map(str::to_string),
33        uid: arg_of(user, "uid").map(str::to_string),
34        full_name: arg_of(user, "full-name").map(str::to_string),
35        authentication_methods: child_block(user, "authentication")
36            .map(authentication_methods)
37            .unwrap_or_default(),
38        authentication_secrets: child_block(user, "authentication")
39            .map(authentication_secrets)
40            .unwrap_or_default(),
41    }
42}