Invoke the set command. # Errors This function will return an error if the desired settings cannot be applied.
(input: &str, setting: &Setting)
| 32 | /// |
| 33 | /// This function will return an error if the desired settings cannot be applied. |
| 34 | pub fn invoke_set(input: &str, setting: &Setting) -> Result<Map<String, Value>, SshdConfigError> { |
| 35 | match setting { |
| 36 | Setting::SshdConfig => { |
| 37 | debug!("{} {:?}", t!("set.settingSshdConfig").to_string(), setting); |
| 38 | let mut cmd_info = build_command_info(Some(&input.to_string()), false)?; |
| 39 | match set_sshd_config(&mut cmd_info) { |
| 40 | Ok(()) => Ok(Map::new()), |
| 41 | Err(e) => Err(e), |
| 42 | } |
| 43 | }, |
| 44 | Setting::SshdConfigRepeat => { |
| 45 | debug!("{} {:?}", t!("set.settingSshdConfig").to_string(), setting); |
| 46 | let cmd_info = build_command_info(Some(&input.to_string()), false)?; |
| 47 | set_sshd_config_repeat(input, &cmd_info) |
| 48 | }, |
| 49 | Setting::SshdConfigRepeatList => { |
| 50 | debug!("{} {:?}", t!("set.settingSshdConfig").to_string(), setting); |
| 51 | let cmd_info = build_command_info(Some(&input.to_string()), false)?; |
| 52 | set_sshd_config_repeat_list(input, &cmd_info) |
| 53 | }, |
| 54 | Setting::WindowsGlobal => { |
| 55 | debug!("{} {:?}", t!("set.settingDefaultShell").to_string(), setting); |
| 56 | match serde_json::from_str::<DefaultShell>(input) { |
| 57 | Ok(default_shell) => { |
| 58 | debug!("{}", t!("set.defaultShellDebug", shell = format!("{:?}", default_shell))); |
| 59 | // if default_shell.shell is Some, we should pass that into set default shell |
| 60 | // otherwise pass in an empty string |
| 61 | let shell: String = default_shell.shell.clone().unwrap_or_default(); |
| 62 | set_default_shell(shell, default_shell.cmd_option, default_shell.escape_arguments)?; |
| 63 | Ok(Map::new()) |
| 64 | }, |
| 65 | Err(e) => Err(SshdConfigError::InvalidInput(t!("set.failedToParseDefaultShell", error = e).to_string())), |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /// Handle single name-value keyword entry operations (add or remove). |
| 72 | fn set_sshd_config_repeat(input: &str, cmd_info: &CommandInfo) -> Result<Map<String, Value>, SshdConfigError> { |
no test coverage detected