Skip to main content

asterust_junos/system/services/
static_subscribers.rs

1//! `system { services { static-subscribers { ... } } }`.
2
3use crate::{arg_of, args_of, named_children};
4use asterust::config::ConfigLine;
5
6/// A `dynamic-profile <name>` of a static-subscribers group.
7#[derive(Clone, Debug, PartialEq, Eq)]
8#[non_exhaustive]
9pub struct StaticSubscriberProfile {
10    pub name: String,
11    /// `merge` or `replace`.
12    pub aggregate_clients: Option<String>,
13}
14
15/// A `group <name>` under `static-subscribers`. Authentication settings are not extracted.
16#[derive(Clone, Debug, PartialEq, Eq)]
17#[non_exhaustive]
18pub struct StaticSubscriberGroup {
19    pub name: String,
20    pub access_profile: Option<String>,
21    pub dynamic_profiles: Vec<StaticSubscriberProfile>,
22    /// Each `interface` as written, e.g. `"ge-1/0/0.100 upto ge-1/0/0.200"` or `"ge-1/0/0.5 exclude"`.
23    pub interfaces: Vec<String>,
24}
25
26/// The `system services static-subscribers` settings. Authentication settings, which include a password, are not
27/// extracted.
28#[derive(Clone, Debug, PartialEq, Eq)]
29#[non_exhaustive]
30pub struct StaticSubscribers {
31    pub access_profile: Option<String>,
32    pub service_profile: Option<String>,
33    pub groups: Vec<StaticSubscriberGroup>,
34}
35
36pub(super) fn parse_static_subscribers(subscribers: &ConfigLine) -> StaticSubscribers {
37    StaticSubscribers {
38        access_profile: arg_of(subscribers, "access-profile").map(str::to_string),
39        service_profile: arg_of(subscribers, "service-profile").map(str::to_string),
40        groups: named_children(subscribers, "group")
41            .map(|(name, group)| StaticSubscriberGroup {
42                name: name.to_string(),
43                access_profile: arg_of(group, "access-profile").map(str::to_string),
44                dynamic_profiles: named_children(group, "dynamic-profile")
45                    .map(|(name, profile)| StaticSubscriberProfile {
46                        name: name.to_string(),
47                        aggregate_clients: arg_of(profile, "aggregate-clients").map(str::to_string),
48                    })
49                    .collect(),
50                interfaces: args_of(group, "interface").into_iter().map(str::to_string).collect(),
51            })
52            .collect(),
53    }
54}