(resource: &DscResource, desired: &str, skip_test: bool, execution_type: &ExecutionKind, target_resource: Option<&DscResource>)
| 104 | /// Error returned if the resource does not successfully set the desired state |
| 105 | #[allow(clippy::too_many_lines)] |
| 106 | pub 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()); |
no test coverage detected