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

Function set_sshd_config

resources/sshdconfig/src/set.rs:182–213  ·  view source on GitHub ↗
(cmd_info: &mut CommandInfo)

Source from the content-addressed store, hash-verified

180}
181
182fn set_sshd_config(cmd_info: &mut CommandInfo) -> Result<(), SshdConfigError> {
183 // this should be its own helper function that checks that the value makes sense for the key type
184 // i.e. if the key can be repeated or have multiple values, etc.
185 // or if the value is something besides a string (like an object to convert back into a comma-separated list)
186 let mut config_to_write = if cmd_info.purge {
187 cmd_info.input.clone()
188 } else {
189 let mut get_cmd_info = cmd_info.clone();
190 get_cmd_info.include_defaults = false;
191 get_cmd_info.input = Map::new();
192
193 let mut existing_config = match get_sshd_settings(&get_cmd_info, true) {
194 Ok(config) => config,
195 Err(SshdConfigError::FileNotFound(_)) => {
196 return Err(SshdConfigError::InvalidInput(
197 t!("set.purgeFalseRequiresExistingFile").to_string()
198 ));
199 }
200 Err(e) => return Err(e),
201 };
202 for (key, value) in &cmd_info.input {
203 if value.is_null() {
204 existing_config.remove(key);
205 } else {
206 existing_config.insert(key.clone(), value.clone());
207 }
208 }
209 existing_config
210 };
211
212 write_and_validate_config(&mut config_to_write, cmd_info.metadata.filepath.as_ref())
213}
214
215/// Write configuration to file after validation.
216fn write_and_validate_config(config: &mut Map<String, Value>, filepath: Option<&PathBuf>) -> Result<(), SshdConfigError> {

Callers 1

invoke_setFunction · 0.85

Calls 5

get_sshd_settingsFunction · 0.85
removeMethod · 0.80
newFunction · 0.50
as_refMethod · 0.45

Tested by

no test coverage detected