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, child_block, named_children, secret_value, Secret};
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`.
21#[derive(Clone, Debug, PartialEq, Eq)]
22#[non_exhaustive]
23pub struct StaticSubscriberGroup {
24    pub name: String,
25    pub access_profile: Option<String>,
26    /// The `authentication { password ...; }`; `None` unless the `secrets` feature is enabled.
27    pub password: Option<Secret>,
28    pub dynamic_profiles: Vec<StaticSubscriberProfile>,
29    /// Each `interface` as written, e.g. `"ge-1/0/0.100 upto ge-1/0/0.200"` or `"ge-1/0/0.5
30    /// exclude"`.
31    pub interfaces: Vec<String>,
32}
33
34/// The `system services static-subscribers` settings.
35#[derive(Clone, Debug, PartialEq, Eq)]
36#[non_exhaustive]
37pub struct StaticSubscribers {
38    pub access_profile: Option<String>,
39    pub service_profile: Option<String>,
40    /// The `authentication { password ...; }`; `None` unless the `secrets` feature is enabled.
41    pub password: Option<Secret>,
42    pub groups: Vec<StaticSubscriberGroup>,
43}
44
45/// The password of the `authentication` block of `line`.
46fn 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}