asterust_junos/policy_options/
community.rs1use crate::{active_children, has_leaf, list_values, split_keyword, split_name};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct Community {
15 pub name: String,
16 pub members: Vec<String>,
17 pub invert_match: bool,
18 pub dynamic_db: bool,
20}
21
22pub(super) fn parse_community(line: &ConfigLine) -> Option<Community> {
24 let (name, rest) = split_name(line.arg("community")?);
25 let (keyword, members) = split_keyword(rest);
26 let mut community = Community {
27 name: name.to_string(),
28 members: if keyword == "members" {
29 list_values(members)
30 } else {
31 Vec::new()
32 },
33 invert_match: false,
34 dynamic_db: has_leaf(line, "dynamic-db"),
35 };
36 for child in active_children(line) {
37 if let Some(members) = child.arg("members") {
38 community.members.extend(list_values(members));
39 } else if child.text == "invert-match" {
40 community.invert_match = true;
41 }
42 }
43 Some(community)
44}