(cmd_info: &mut CommandInfo)
| 180 | } |
| 181 | |
| 182 | fn set_sshd_config(cmd_info: &mut CommandInfo) -> Result<(), SshdConfigError> { |
| 183 | // this should be its own helper function that checks that the value makes sense for the key type |
| 184 | // i.e. if the key can be repeated or have multiple values, etc. |
| 185 | // or if the value is something besides a string (like an object to convert back into a comma-separated list) |
| 186 | let mut config_to_write = if cmd_info.purge { |
| 187 | cmd_info.input.clone() |
| 188 | } else { |
| 189 | let mut get_cmd_info = cmd_info.clone(); |
| 190 | get_cmd_info.include_defaults = false; |
| 191 | get_cmd_info.input = Map::new(); |
| 192 | |
| 193 | let mut existing_config = match get_sshd_settings(&get_cmd_info, true) { |
| 194 | Ok(config) => config, |
| 195 | Err(SshdConfigError::FileNotFound(_)) => { |
| 196 | return Err(SshdConfigError::InvalidInput( |
| 197 | t!("set.purgeFalseRequiresExistingFile").to_string() |
| 198 | )); |
| 199 | } |
| 200 | Err(e) => return Err(e), |
| 201 | }; |
| 202 | for (key, value) in &cmd_info.input { |
| 203 | if value.is_null() { |
| 204 | existing_config.remove(key); |
| 205 | } else { |
| 206 | existing_config.insert(key.clone(), value.clone()); |
| 207 | } |
| 208 | } |
| 209 | existing_config |
| 210 | }; |
| 211 | |
| 212 | write_and_validate_config(&mut config_to_write, cmd_info.metadata.filepath.as_ref()) |
| 213 | } |
| 214 | |
| 215 | /// Write configuration to file after validation. |
| 216 | fn write_and_validate_config(config: &mut Map<String, Value>, filepath: Option<&PathBuf>) -> Result<(), SshdConfigError> { |
no test coverage detected