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

Function invoke_validate

lib/dsc-lib/src/dscresources/command_resource.rs:557–583  ·  view source on GitHub ↗

Invoke the validate operation against a command resource. # Arguments `resource` - The resource manifest for the command resource. `cwd` - The current working directory. `config` - The configuration to validate in JSON. # Returns `ValidateResult` - The result of the validate operation. # Errors Error is returned if the underlying command returns a non-zero exit code.

(resource: &DscResource, config: &str, target_resource: Option<&DscResource>)

Source from the content-addressed store, hash-verified

555///
556/// Error is returned if the underlying command returns a non-zero exit code.
557pub fn invoke_validate(resource: &DscResource, config: &str, target_resource: Option<&DscResource>) -> Result<ValidateResult, DscError> {
558 trace!("{}", t!("dscresources.commandResource.invokeValidateConfig", resource = &resource.type_name, config = &config));
559 let Some(manifest) = &resource.manifest else {
560 return Err(DscError::MissingManifest(resource.type_name.to_string()));
561 };
562 // TODO: use schema to validate config if validate is not implemented
563 let Some(validate) = manifest.validate.as_ref() else {
564 return Err(DscError::NotImplemented("validate".to_string()));
565 };
566
567 let resource_type = match target_resource {
568 Some(r) => r.type_name.clone(),
569 None => resource.type_name.clone(),
570 };
571 let path = target_resource.map(|target_resource| target_resource.path.clone());
572 let command_resource_info = CommandResourceInfo {
573 type_name: resource_type.clone(),
574 path,
575 };
576 let args = process_get_args(validate.args.as_ref(), config, &command_resource_info);
577 let command_input = get_command_input(validate.input.as_ref(), config)?;
578
579 info!("{}", t!("dscresources.commandResource.invokeValidateUsing", resource = resource_type, executable = &validate.executable));
580 let (_exit_code, stdout, _stderr) = invoke_command(&validate.executable, args, command_input.stdin.as_deref(), Some(&resource.directory), command_input.env, manifest.exit_codes.as_ref())?;
581 let result: ValidateResult = serde_json::from_str(&stdout)?;
582 Ok(result)
583}
584
585/// Get the JSON schema for a resource
586///

Callers 2

validateMethod · 0.85

Calls 5

process_get_argsFunction · 0.85
get_command_inputFunction · 0.85
invoke_commandFunction · 0.70
from_strFunction · 0.50
as_refMethod · 0.45

Tested by

no test coverage detected