asterust-junos 0.5.1

Typed Juniper JunOS config views (interfaces, OSPF, BGP, IS-IS, routing instances, policy options, firewall filters, system) extracted from an asterust config tree.
Documentation
//! `session` and `session-group`
//! `protocols { ldp { session <address> { ... } session-group <prefix> { ... } } }`.
//!
//! # See also
//!
//! - [session-group](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/session-group-edit-protocols-ldp.html)
//! - [downstream-on-demand](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/downstream-on-demand-edit-protocols-ldp-session.html)
//! - [authentication-key (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/authentication-key-edit-protocols-ldp.html)
//! - [authentication-key-chain (Protocols LDP)](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/authentication-key-chain-edit-protocols-ldp.html)
//! - [transport-address](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/transport-address-edit-protocols-ldp.html)
//! - [LDP Configuration](https://networkingdocs.hpe.com/documentation/us/en/software/junos/mpls/topics/topic-map/ldp-configuration.html)

use crate::{arg_of, toggle};
use asterust::config::ConfigLine;

/// A `session <address>` or `session-group <prefix>` entry of LDP. The `authentication-key` is read only with the
/// `secrets` feature.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct LdpSession {
    /// The neighbor address, or the prefix of a session group.
    pub name: String,
    pub authentication_algorithm: Option<String>,
    /// An `authentication-key` is configured.
    pub has_authentication_key: bool,
    /// The `authentication-key`; `None` unless the `secrets` feature is enabled.
    pub authentication_key: Option<crate::Secret>,
    pub authentication_key_chain: Option<String>,
    pub downstream_on_demand: bool,
    /// `Some(true)` for `mtu-discovery`, `Some(false)` for `no-mtu-discovery`.
    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"),
    }
}