use crate::{arg_of, args_of, child_block, named_children};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct AutoConfigureProfile {
pub name: String,
pub accept: Vec<String>,
pub access_profile: Option<String>,
pub ranges: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct AutoConfigureRanges {
pub access_profile: Option<String>,
pub dynamic_profiles: Vec<AutoConfigureProfile>,
pub has_authentication: bool,
}
pub(super) fn parse_ranges(ranges: &ConfigLine) -> AutoConfigureRanges {
AutoConfigureRanges {
access_profile: arg_of(ranges, "access-profile").map(str::to_string),
dynamic_profiles: named_children(ranges, "dynamic-profile")
.map(|(name, profile)| AutoConfigureProfile {
name: name.to_string(),
accept: args_of(profile, "accept").into_iter().map(str::to_string).collect(),
access_profile: arg_of(profile, "access-profile").map(str::to_string),
ranges: arg_of(profile, "ranges").map(str::to_string),
})
.collect(),
has_authentication: child_block(ranges, "authentication").is_some(),
}
}