Skip to main content

asterust_junos/system/services/
static_subscribers.rs

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