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>)
| 555 | /// |
| 556 | /// Error is returned if the underlying command returns a non-zero exit code. |
| 557 | pub 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 | /// |
no test coverage detected