Write configuration map to config text string # Errors This function will return an error if formatting fails.
(global_map: &Map<String, Value>)
| 179 | /// |
| 180 | /// This function will return an error if formatting fails. |
| 181 | pub fn write_config_map_to_text(global_map: &Map<String, Value>) -> Result<String, SshdConfigError> { |
| 182 | let match_map = global_map.get("match"); |
| 183 | let mut config_text = String::new(); |
| 184 | |
| 185 | for (key, value) in global_map { |
| 186 | let key_lower = key.to_lowercase(); |
| 187 | |
| 188 | if key_lower == "match" { |
| 189 | continue; // match blocks are handled after global settings |
| 190 | } |
| 191 | |
| 192 | let sshd_config_value = SshdConfigValue::try_new(key, value, None, true)?; |
| 193 | sshd_config_value.write_to_config(&mut config_text)?; |
| 194 | } |
| 195 | |
| 196 | if let Some(match_map) = match_map { |
| 197 | if let Value::Array(arr) = match_map { |
| 198 | for item in arr { |
| 199 | let formatted = format_match_block(item)?; |
| 200 | writeln!(&mut config_text, "Match {formatted}")?; |
| 201 | } |
| 202 | } else { |
| 203 | let formatted = format_match_block(match_map)?; |
| 204 | writeln!(&mut config_text, "Match {formatted}")?; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | Ok(config_text) |
| 209 | } |