(input: Option<&String>, compare: bool)
| 10 | use crate::repeat_keyword::{find_name_value_entry_index, NameValueEntry}; |
| 11 | |
| 12 | pub fn invoke_export(input: Option<&String>, compare: bool) -> Result<Map<String, Value>, SshdConfigError> { |
| 13 | let cmd_info = build_command_info(input, false)?; |
| 14 | let mut result = get_sshd_settings(&cmd_info, false)?; |
| 15 | |
| 16 | // For sshd-config-repeat operations (single entry like subsystem) |
| 17 | // Check if the requested entry exists in the actual state |
| 18 | if compare && !cmd_info.input.is_empty() { |
| 19 | let mut exist = false; |
| 20 | |
| 21 | for (keyword, input_value) in &cmd_info.input { |
| 22 | if !CanonicalProperties::is_canonical(keyword) |
| 23 | && let Some(actual_value) = result.get(keyword) { |
| 24 | if let Value::Array(entries) = actual_value { |
| 25 | // As more keywords are supported, different structured formats may be needed. |
| 26 | if let Ok(entry) = serde_json::from_value::<NameValueEntry>(input_value.clone()) { |
| 27 | let match_value = entry.value.as_deref(); |
| 28 | if find_name_value_entry_index(entries, &entry.name, match_value).is_some() { |
| 29 | exist = true; |
| 30 | } |
| 31 | } |
| 32 | } else { |
| 33 | // Direct value comparison for non-array keywords |
| 34 | if actual_value == input_value { |
| 35 | exist = true; |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | // The only result should be the input to match the expected output for DSC |
| 40 | result.insert(keyword.clone(), input_value.clone()); |
| 41 | } |
| 42 | result.insert(CanonicalProperty::Exist.to_string(), Value::Bool(exist)); |
| 43 | } |
| 44 | Ok(result) |
| 45 | } |
no test coverage detected