(match_obj: &Value)
| 139 | } |
| 140 | |
| 141 | fn format_match_block(match_obj: &Value) -> Result<String, SshdConfigError> { |
| 142 | let match_block = match serde_json::from_value::<MatchBlock>(match_obj.clone()) { |
| 143 | Ok(result) => { |
| 144 | result |
| 145 | } |
| 146 | Err(e) => { |
| 147 | return Err(SshdConfigError::ParserError(t!("formatter.deserializeFailed", error = e).to_string())); |
| 148 | } |
| 149 | }; |
| 150 | |
| 151 | if match_block.criteria.is_empty() { |
| 152 | return Err(SshdConfigError::InvalidInput(t!("formatter.matchBlockMissingCriteria").to_string())); |
| 153 | } |
| 154 | |
| 155 | let mut match_parts = vec![]; |
| 156 | let mut result = vec![]; |
| 157 | |
| 158 | for (key, value) in &match_block.criteria { |
| 159 | // all match criteria values are comma-separated |
| 160 | let sshd_config_value = SshdConfigValue::try_new(key, value, Some(ValueSeparator::Comma), true)?; |
| 161 | match_parts.push(format!("{key} {sshd_config_value}")); |
| 162 | } |
| 163 | |
| 164 | // Write the Match line with the formatted criteria(s) |
| 165 | result.push(match_parts.join(" ")); |
| 166 | |
| 167 | // Format other keywords in the match block |
| 168 | for (key, value) in &match_block.contents { |
| 169 | let sshd_config_value = SshdConfigValue::try_new(key, value, None, true)?; |
| 170 | result.push(format!("\t{key} {sshd_config_value}")); |
| 171 | } |
| 172 | |
| 173 | Ok(result.join("\n")) |
| 174 | } |
| 175 | |
| 176 | /// Write configuration map to config text string |
| 177 | /// |
no test coverage detected