Parse and validate an array of name-value entries. This function converts JSON values into `NameValueEntry` structs and validates that each entry has both a non-empty name and a non-empty value field. # Parameters `entries_array` - A slice of JSON values representing name-value entries # Returns Returns `Ok(Vec )` containing the parsed and validated entries. # Errors Returns
(entries_array: &[Value])
| 204 | /// * Returns `SshdConfigError::InvalidInput` if an entry has an empty name field |
| 205 | /// * Returns `SshdConfigError::InvalidInput` if an entry has a missing or empty value field |
| 206 | pub fn parse_and_validate_entries(entries_array: &[Value]) -> Result<Vec<NameValueEntry>, SshdConfigError> { |
| 207 | let mut entries: Vec<NameValueEntry> = Vec::new(); |
| 208 | |
| 209 | for entry_value in entries_array { |
| 210 | let entry: NameValueEntry = serde_json::from_value(entry_value.clone()) |
| 211 | .map_err(|e| SshdConfigError::InvalidInput(t!("repeat_keyword.failedToParse", input = e.to_string()).to_string()))?; |
| 212 | |
| 213 | // Validate required name field |
| 214 | if entry.name.is_empty() { |
| 215 | return Err(SshdConfigError::InvalidInput( |
| 216 | t!("repeat_keyword.entryNameRequired").to_string() |
| 217 | )); |
| 218 | } |
| 219 | |
| 220 | // Validate value field is present |
| 221 | if entry.value.is_none() || entry.value.as_ref().unwrap().is_empty() { |
| 222 | return Err(SshdConfigError::InvalidInput( |
| 223 | t!("repeat_keyword.entryValueRequired", name = entry.name).to_string() |
| 224 | )); |
| 225 | } |
| 226 | |
| 227 | entries.push(entry); |
| 228 | } |
| 229 | |
| 230 | Ok(entries) |
| 231 | } |
| 232 | |
| 233 | /// Find the index of a name-value entry in a keyword array by matching the name field (case-sensitive). |
| 234 | /// |
no test coverage detected