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

Function invoke_set

lib/dsc-lib/src/dscresources/command_resource.rs:106–332  ·  view source on GitHub ↗
(resource: &DscResource, desired: &str, skip_test: bool, execution_type: &ExecutionKind, target_resource: Option<&DscResource>)

Source from the content-addressed store, hash-verified

104/// Error returned if the resource does not successfully set the desired state
105#[allow(clippy::too_many_lines)]
106pub fn invoke_set(resource: &DscResource, desired: &str, skip_test: bool, execution_type: &ExecutionKind, target_resource: Option<&DscResource>) -> Result<SetResult, DscError> {
107 debug!("{}", t!("dscresources.commandResource.invokeSet", resource = &resource.type_name));
108 let Some(manifest) = &resource.manifest else {
109 return Err(DscError::MissingManifest(resource.type_name.to_string()));
110 };
111 let operation_type: String;
112 let mut is_synthetic_what_if = false;
113 let resource_type = match target_resource {
114 Some(r) => r.type_name.clone(),
115 None => resource.type_name.clone(),
116 };
117 let path = target_resource.map(|target_resource| target_resource.path.clone());
118 let command_resource_info = CommandResourceInfo {
119 type_name: resource_type.clone(),
120 path,
121 };
122
123 let set_method = match execution_type {
124 ExecutionKind::Actual => {
125 operation_type = "set".to_string();
126 &manifest.set
127 },
128 ExecutionKind::WhatIf => {
129 operation_type = "whatif".to_string();
130 // Check if set supports native what-if
131 let has_native_whatif = manifest.set.as_ref().is_some_and(|set| {
132 let (_, supports_whatif) = process_set_delete_args(
133 set.args.as_ref(),
134 "",
135 &command_resource_info,
136 execution_type
137 );
138 supports_whatif
139 });
140
141 if has_native_whatif {
142 &manifest.set
143 } else if manifest.what_if.is_some() {
144 warn!("{}", t!("dscresources.commandResource.whatIfWarning", resource = &resource_type));
145 &manifest.what_if
146 } else {
147 is_synthetic_what_if = true;
148 &manifest.set
149 }
150 }
151 };
152 let Some(set) = set_method.as_ref() else {
153 return Err(DscError::NotImplemented("set".to_string()));
154 };
155 validate_security_context(&set.require_security_context, &resource_type, "set")?;
156 verify_json_from_manifest(resource, desired, target_resource)?;
157
158 // if resource doesn't implement a pre-test, we execute test first to see if a set is needed
159 if !skip_test && set.pre_test != Some(true) {
160 info!("{}", t!("dscresources.commandResource.noPretest", resource = &resource.type_name));
161 let test_result = invoke_test(resource, desired, target_resource)?;
162 if is_synthetic_what_if {
163 return Ok(test_result.into());

Callers 1

setMethod · 0.70

Calls 15

process_set_delete_argsFunction · 0.85
invoke_testFunction · 0.85
get_in_desired_stateFunction · 0.85
process_get_argsFunction · 0.85
get_command_inputFunction · 0.85
CommandEnum · 0.85
json_to_hashmapFunction · 0.85
get_diffFunction · 0.85
removeMethod · 0.80
redactFunction · 0.70

Tested by

no test coverage detected