use crate::{arg_of, toggle};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct LdpSession {
pub name: String,
pub authentication_algorithm: Option<String>,
pub has_authentication_key: bool,
pub authentication_key: Option<crate::Secret>,
pub authentication_key_chain: Option<String>,
pub downstream_on_demand: bool,
pub mtu_discovery: Option<bool>,
pub transport_address: Option<String>,
}
pub(super) fn parse_session(name: &str, session: &ConfigLine) -> LdpSession {
let field = |keyword: &str| arg_of(session, keyword).map(str::to_string);
LdpSession {
name: name.to_string(),
authentication_algorithm: field("authentication-algorithm"),
has_authentication_key: arg_of(session, "authentication-key").is_some(),
authentication_key: crate::secret_value(arg_of(session, "authentication-key")),
authentication_key_chain: field("authentication-key-chain"),
downstream_on_demand: crate::has_leaf(session, "downstream-on-demand"),
mtu_discovery: toggle(session, "mtu-discovery"),
transport_address: field("transport-address"),
}
}