Handle single name-value keyword entry operations (add or remove).
(input: &str, cmd_info: &CommandInfo)
| 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> { |
| 73 | let keyword_input: RepeatInput = serde_json::from_str(input) |
| 74 | .map_err(|e| SshdConfigError::InvalidInput(t!("set.failedToParse", input = e.to_string()).to_string()))?; |
| 75 | |
| 76 | let (keyword, entry_value) = extract_single_keyword(keyword_input.additional_properties)?; |
| 77 | |
| 78 | let mut existing_config = get_existing_config(cmd_info)?; |
| 79 | |
| 80 | // parses entry for name-value keywords, like subsystem, for now |
| 81 | // different keywords will likely need to be serialized into different structs |
| 82 | // and likely need to have different add/update/remove functions |
| 83 | let entry: NameValueEntry = serde_json::from_value(entry_value) |
| 84 | .map_err(|e| SshdConfigError::InvalidInput(t!("set.failedToParse", input = e.to_string()).to_string()))?; |
| 85 | |
| 86 | if keyword_input.exist { |
| 87 | add_or_update_entry(&mut existing_config, &keyword, &entry)?; |
| 88 | } else { |
| 89 | remove_entry(&mut existing_config, &keyword, &entry.name); |
| 90 | } |
| 91 | |
| 92 | write_and_validate_config(&mut existing_config, cmd_info.metadata.filepath.as_ref())?; |
| 93 | Ok(Map::new()) |
| 94 | } |
| 95 | |
| 96 | /// Handle list name-value keyword operations with purge support. |
| 97 | fn set_sshd_config_repeat_list(input: &str, cmd_info: &CommandInfo) -> Result<Map<String, Value>, SshdConfigError> { |
no test coverage detected