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

Function invoke_delete

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

Invoke the delete operation against a command resource. # Arguments `resource` - The resource manifest for the command resource. `cwd` - The current working directory. `filter` - The filter to apply to the resource in JSON. `execution_type` - Whether this is an actual delete or what-if. # Errors Error is returned if the underlying command returns a non-zero exit code.

(resource: &DscResource, filter: &str, target_resource: Option<&DscResource>, execution_type: &ExecutionKind)

Source from the content-addressed store, hash-verified

501///
502/// Error is returned if the underlying command returns a non-zero exit code.
503pub fn invoke_delete(resource: &DscResource, filter: &str, target_resource: Option<&DscResource>, execution_type: &ExecutionKind) -> Result<DeleteResultKind, DscError> {
504 let Some(manifest) = &resource.manifest else {
505 return Err(DscError::MissingManifest(resource.type_name.to_string()));
506 };
507 let Some(delete) = &manifest.delete else {
508 return Err(DscError::NotImplemented("delete".to_string()));
509 };
510
511 verify_json_from_manifest(resource, filter, target_resource)?;
512
513 let resource_type = match target_resource {
514 Some(r) => r.type_name.clone(),
515 None => resource.type_name.clone(),
516 };
517 validate_security_context(&delete.require_security_context, &resource_type, "delete")?;
518 let path = target_resource.map(|target_resource| target_resource.path.clone());
519 let command_resource_info = CommandResourceInfo {
520 type_name: resource_type.clone(),
521 path,
522 };
523 let (args, supports_whatif) = process_set_delete_args(delete.args.as_ref(), filter, &command_resource_info, execution_type);
524 if execution_type == &ExecutionKind::WhatIf && !supports_whatif {
525 // perform a synthetic what-if by calling test and wrapping the TestResult in DeleteResultKind::SyntheticWhatIf
526 let test_result = invoke_test(resource, filter, target_resource)?;
527 return Ok(DeleteResultKind::SyntheticWhatIf(test_result));
528 }
529 let command_input = get_command_input(delete.input.as_ref(), filter)?;
530
531 info!("{}", t!("dscresources.commandResource.invokeDeleteUsing", resource = resource_type, executable = &delete.executable));
532 let (_exit_code, stdout, _stderr) = invoke_command(&delete.executable, args, command_input.stdin.as_deref(), Some(&resource.directory), command_input.env, manifest.exit_codes.as_ref())?;
533 let result = if execution_type == &ExecutionKind::WhatIf {
534 let delete_result: DeleteResult = serde_json::from_str(&stdout)?;
535 DeleteResultKind::ResourceWhatIf(delete_result)
536 } else {
537 DeleteResultKind::ResourceActual
538 };
539 Ok(result)
540}
541
542/// Invoke the validate operation against a command resource.
543///

Callers 1

deleteMethod · 0.85

Calls 8

process_set_delete_argsFunction · 0.85
invoke_testFunction · 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