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::{arg_of, child_block};
10use asterust::config::ConfigLine;
11
12/// A login `user`. Passwords and keys are not extracted, only which authentication methods are
13/// present.
14#[derive(Clone, Debug, PartialEq, Eq)]
15#[non_exhaustive]
16pub struct LoginUser {
17    pub name: String,
18    pub class: Option<String>,
19    pub uid: Option<String>,
20    pub full_name: Option<String>,
21    /// One entry per authentication statement, e.g. `"encrypted-password"`, `"ssh-rsa"`.
22    pub authentication_methods: Vec<String>,
23}
24
25pub(super) fn parse_user(name: &str, user: &ConfigLine) -> LoginUser {
26    LoginUser {
27        name: name.to_string(),
28        class: arg_of(user, "class").map(str::to_string),
29        uid: arg_of(user, "uid").map(str::to_string),
30        full_name: arg_of(user, "full-name").map(str::to_string),
31        authentication_methods: child_block(user, "authentication")
32            .map(authentication_methods)
33            .unwrap_or_default(),
34    }
35}