asterust_junos/system/services/
static_subscribers.rs1use crate::{arg_of, args_of, child_block, has_leaf, named_children, secret_value, Secret};
15use asterust::config::ConfigLine;
16
17#[derive(Clone, Debug, PartialEq, Eq)]
19#[non_exhaustive]
20pub struct StaticSubscriberUsername {
21 pub delimiter: Option<String>,
22 pub domain_name: Option<String>,
23 pub interface: bool,
24 pub logical_system_name: bool,
25 pub routing_instance_name: bool,
26 pub user_prefix: Option<String>,
27 pub vlan_tags: bool,
28}
29
30#[derive(Clone, Debug, PartialEq, Eq)]
32#[non_exhaustive]
33pub struct StaticSubscriberProfile {
34 pub name: String,
35 pub aggregate_clients: Option<String>,
37}
38
39#[derive(Clone, Debug, PartialEq, Eq)]
41#[non_exhaustive]
42pub struct StaticSubscriberGroup {
43 pub name: String,
44 pub access_profile: Option<String>,
45 pub password: Option<Secret>,
47 pub dynamic_profiles: Vec<StaticSubscriberProfile>,
48 pub service_profile: Option<String>,
49 pub username_include: Option<StaticSubscriberUsername>,
50 pub interfaces: Vec<String>,
53}
54
55#[derive(Clone, Debug, PartialEq, Eq)]
57#[non_exhaustive]
58pub struct StaticSubscribers {
59 pub access_profile: Option<String>,
60 pub service_profile: Option<String>,
61 pub password: Option<Secret>,
63 pub username_include: Option<StaticSubscriberUsername>,
64 pub dynamic_profiles: Vec<StaticSubscriberProfile>,
65 pub groups: Vec<StaticSubscriberGroup>,
66}
67
68fn password_of(line: &ConfigLine) -> Option<Secret> {
70 secret_value(child_block(line, "authentication").and_then(|auth| arg_of(auth, "password")))
71}
72
73fn username_include(line: &ConfigLine) -> Option<StaticSubscriberUsername> {
74 let include = child_block(child_block(line, "authentication")?, "username-include")?;
75 Some(StaticSubscriberUsername {
76 delimiter: arg_of(include, "delimiter").map(str::to_string),
77 domain_name: arg_of(include, "domain-name").map(str::to_string),
78 interface: has_leaf(include, "interface"),
79 logical_system_name: has_leaf(include, "logical-system-name"),
80 routing_instance_name: has_leaf(include, "routing-instance-name"),
81 user_prefix: arg_of(include, "user-prefix").map(str::to_string),
82 vlan_tags: has_leaf(include, "vlan-tags"),
83 })
84}
85
86fn dynamic_profiles(line: &ConfigLine) -> Vec<StaticSubscriberProfile> {
87 named_children(line, "dynamic-profile")
88 .map(|(name, profile)| StaticSubscriberProfile {
89 name: name.to_string(),
90 aggregate_clients: arg_of(profile, "aggregate-clients").map(str::to_string),
91 })
92 .collect()
93}
94
95pub(super) fn parse_static_subscribers(subscribers: &ConfigLine) -> StaticSubscribers {
96 StaticSubscribers {
97 access_profile: arg_of(subscribers, "access-profile").map(str::to_string),
98 service_profile: arg_of(subscribers, "service-profile").map(str::to_string),
99 password: password_of(subscribers),
100 username_include: username_include(subscribers),
101 dynamic_profiles: dynamic_profiles(subscribers),
102 groups: named_children(subscribers, "group")
103 .map(|(name, group)| StaticSubscriberGroup {
104 name: name.to_string(),
105 access_profile: arg_of(group, "access-profile").map(str::to_string),
106 password: password_of(group),
107 dynamic_profiles: dynamic_profiles(group),
108 service_profile: arg_of(group, "service-profile").map(str::to_string),
109 username_include: username_include(group),
110 interfaces: args_of(group, "interface").into_iter().map(str::to_string).collect(),
111 })
112 .collect(),
113 }
114}