MCPcopy Create free account
hub / github.com/PowerShell/DSC / write_config_map_to_text

Function write_config_map_to_text

resources/sshdconfig/src/formatter.rs:181–209  ·  view source on GitHub ↗

Write configuration map to config text string # Errors This function will return an error if formatting fails.

(global_map: &Map<String, Value>)

Source from the content-addressed store, hash-verified

179///
180/// This function will return an error if formatting fails.
181pub 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}

Callers 2

subsystem_roundtripFunction · 0.85

Calls 4

format_match_blockFunction · 0.85
write_to_configMethod · 0.80
newFunction · 0.50
getMethod · 0.45

Tested by 1

subsystem_roundtripFunction · 0.68