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