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

Function build_command_info

resources/sshdconfig/src/util.rs:191–220  ·  view source on GitHub ↗

Extract _metadata field from the input string, if it can be parsed as JSON. # Errors This function will return an error if it fails to parse the input string and if the _metadata field exists, extract it.

(input: Option<&String>, is_get: bool)

Source from the content-addressed store, hash-verified

189///
190/// This function will return an error if it fails to parse the input string and if the _metadata field exists, extract it.
191pub fn build_command_info(input: Option<&String>, is_get: bool) -> Result<CommandInfo, SshdConfigError> {
192 let mut include_defaults = is_get;
193 let mut metadata: Metadata = Metadata::new();
194 let mut purge = false;
195 let mut sshd_args: Option<SshdCommandArgs> = None;
196 let mut sshd_config: Map<String, Value> = Map::new();
197
198 if let Some(inputs) = input {
199 sshd_config = serde_json::from_str(inputs.as_str())?;
200 purge = CanonicalProperties::extract_bool(&mut sshd_config, CanonicalProperty::Purge, false)?;
201 include_defaults = CanonicalProperties::extract_bool(&mut sshd_config, CanonicalProperty::IncludeDefaults, is_get)?;
202 metadata = if let Some(value) = sshd_config.remove(CanonicalProperty::Metadata.as_str()) {
203 serde_json::from_value(value)?
204 } else {
205 Metadata::new()
206 };
207 sshd_args = metadata.filepath.clone().map(|filepath| {
208 SshdCommandArgs {
209 filepath: Some(filepath),
210 additional_args: None,
211 }
212 });
213 if is_get && !sshd_config.is_empty() {
214 warn!("{}", t!("util.getIgnoresInputFilters"));
215 sshd_config.clear();
216 }
217 }
218
219 Ok(CommandInfo::new(include_defaults, sshd_config, metadata, purge, sshd_args))
220}
221
222/// Reads `sshd_config` file.
223///

Callers 3

invoke_exportFunction · 0.85
invoke_setFunction · 0.85
invoke_getFunction · 0.85

Calls 5

as_strMethod · 0.80
removeMethod · 0.80
newFunction · 0.50
from_strFunction · 0.50
is_emptyMethod · 0.45

Tested by

no test coverage detected