asterust_junos/system/services/
static_subscribers.rs1use crate::{arg_of, args_of, child_block, named_children, secret_value, Secret};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct StaticSubscriberProfile {
15 pub name: String,
16 pub aggregate_clients: Option<String>,
18}
19
20#[derive(Clone, Debug, PartialEq, Eq)]
22#[non_exhaustive]
23pub struct StaticSubscriberGroup {
24 pub name: String,
25 pub access_profile: Option<String>,
26 pub password: Option<Secret>,
28 pub dynamic_profiles: Vec<StaticSubscriberProfile>,
29 pub interfaces: Vec<String>,
32}
33
34#[derive(Clone, Debug, PartialEq, Eq)]
36#[non_exhaustive]
37pub struct StaticSubscribers {
38 pub access_profile: Option<String>,
39 pub service_profile: Option<String>,
40 pub password: Option<Secret>,
42 pub groups: Vec<StaticSubscriberGroup>,
43}
44
45fn password_of(line: &ConfigLine) -> Option<Secret> {
47 secret_value(child_block(line, "authentication").and_then(|auth| arg_of(auth, "password")))
48}
49
50pub(super) fn parse_static_subscribers(subscribers: &ConfigLine) -> StaticSubscribers {
51 StaticSubscribers {
52 access_profile: arg_of(subscribers, "access-profile").map(str::to_string),
53 service_profile: arg_of(subscribers, "service-profile").map(str::to_string),
54 password: password_of(subscribers),
55 groups: named_children(subscribers, "group")
56 .map(|(name, group)| StaticSubscriberGroup {
57 name: name.to_string(),
58 access_profile: arg_of(group, "access-profile").map(str::to_string),
59 password: password_of(group),
60 dynamic_profiles: named_children(group, "dynamic-profile")
61 .map(|(name, profile)| StaticSubscriberProfile {
62 name: name.to_string(),
63 aggregate_clients: arg_of(profile, "aggregate-clients").map(str::to_string),
64 })
65 .collect(),
66 interfaces: args_of(group, "interface").into_iter().map(str::to_string).collect(),
67 })
68 .collect(),
69 }
70}