asterust_junos/system/services/
telnet.rs1use crate::{arg_of, args_of, list_values};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, Default, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct TelnetService {
15 pub authentication_order: Vec<String>,
17 pub connection_limit: Option<String>,
18 pub rate_limit: Option<String>,
19}
20
21pub(super) fn parse_telnet(telnet: &ConfigLine) -> TelnetService {
22 TelnetService {
23 authentication_order: args_of(telnet, "authentication-order")
24 .into_iter()
25 .flat_map(list_values)
26 .collect(),
27 connection_limit: arg_of(telnet, "connection-limit").map(str::to_string),
28 rate_limit: arg_of(telnet, "rate-limit").map(str::to_string),
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use crate::system::system;
35 use asterust::config::juniper;
36
37 #[test]
39 fn extracts_telnet_options() {
40 let telnet = system(&juniper::parse_braces(
41 "system {\n services {\n telnet {\n authentication-order [ tacplus password ];\n connection-limit 10;\n rate-limit 5;\n }\n }\n}\n",
42 ))
43 .unwrap()
44 .services
45 .unwrap()
46 .telnet_service
47 .unwrap();
48 assert_eq!(telnet.authentication_order, ["tacplus", "password"]);
49 assert_eq!(telnet.connection_limit.as_deref(), Some("10"));
50 assert_eq!(telnet.rate_limit.as_deref(), Some("5"));
51 }
52
53 #[test]
54 fn bare_telnet_has_no_options() {
55 let services = system(&juniper::parse_braces(
56 "system {\n services {\n telnet;\n }\n}\n",
57 ))
58 .unwrap()
59 .services
60 .unwrap();
61 assert!(services.telnet);
62 assert_eq!(services.telnet_service, Some(Default::default()));
63 }
64}