use crate::{arg_of, args_of, child_block, named_children, secret_value, Secret};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct StaticSubscriberProfile {
pub name: String,
pub aggregate_clients: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct StaticSubscriberGroup {
pub name: String,
pub access_profile: Option<String>,
pub password: Option<Secret>,
pub dynamic_profiles: Vec<StaticSubscriberProfile>,
pub interfaces: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct StaticSubscribers {
pub access_profile: Option<String>,
pub service_profile: Option<String>,
pub password: Option<Secret>,
pub groups: Vec<StaticSubscriberGroup>,
}
fn password_of(line: &ConfigLine) -> Option<Secret> {
secret_value(child_block(line, "authentication").and_then(|auth| arg_of(auth, "password")))
}
pub(super) fn parse_static_subscribers(subscribers: &ConfigLine) -> StaticSubscribers {
StaticSubscribers {
access_profile: arg_of(subscribers, "access-profile").map(str::to_string),
service_profile: arg_of(subscribers, "service-profile").map(str::to_string),
password: password_of(subscribers),
groups: named_children(subscribers, "group")
.map(|(name, group)| StaticSubscriberGroup {
name: name.to_string(),
access_profile: arg_of(group, "access-profile").map(str::to_string),
password: password_of(group),
dynamic_profiles: named_children(group, "dynamic-profile")
.map(|(name, profile)| StaticSubscriberProfile {
name: name.to_string(),
aggregate_clients: arg_of(profile, "aggregate-clients").map(str::to_string),
})
.collect(),
interfaces: args_of(group, "interface").into_iter().map(str::to_string).collect(),
})
.collect(),
}
}