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

Function invoke_get

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

Invoke the get operation on a resource # Arguments `resource` - The resource manifest `filter` - The filter to apply to the resource in JSON # Errors Error returned if the resource does not successfully get the current state

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

Source from the content-addressed store, hash-verified

42///
43/// Error returned if the resource does not successfully get the current state
44pub fn invoke_get(resource: &DscResource, filter: &str, target_resource: Option<&DscResource>) -> Result<GetResult, DscError> {
45 debug!("{}", t!("dscresources.commandResource.invokeGet", resource = &resource.type_name));
46 let Some(manifest) = &resource.manifest else {
47 return Err(DscError::MissingManifest(resource.type_name.to_string()));
48 };
49 let mut command_input = CommandInput { env: None, stdin: None };
50 let Some(get) = &manifest.get else {
51 return Err(DscError::NotImplemented("get".to_string()));
52 };
53 let resource_type = match target_resource {
54 Some(r) => r.type_name.clone(),
55 None => resource.type_name.clone(),
56 };
57 validate_security_context(&get.require_security_context, &resource_type, "get")?;
58 let path = target_resource.map(|target_resource| target_resource.path.clone());
59 let command_resource_info = CommandResourceInfo {
60 type_name: resource_type.clone(),
61 path,
62 };
63 let args = process_get_args(get.args.as_ref(), filter, &command_resource_info);
64 if !filter.is_empty() {
65 verify_json_from_manifest(resource, filter, target_resource)?;
66 command_input = get_command_input(get.input.as_ref(), filter)?;
67 }
68
69 info!("{}", t!("dscresources.commandResource.invokeGetUsing", resource = &resource.type_name, executable = &get.executable));
70 let (_exit_code, stdout, stderr) = invoke_command(&get.executable, args, command_input.stdin.as_deref(), Some(&resource.directory), command_input.env, manifest.exit_codes.as_ref())?;
71 if resource.kind == Kind::Resource {
72 debug!("{}", t!("dscresources.commandResource.verifyOutputUsing", resource = &resource.type_name, executable = &get.executable));
73 verify_json_from_manifest(resource, &stdout, target_resource)?;
74 }
75
76 let result: GetResult = if let Ok(group_response) = serde_json::from_str::<Vec<ResourceGetResult>>(&stdout) {
77 trace!("{}", t!("dscresources.commandResource.groupGetResponse", response = &group_response : {:?}));
78 GetResult::Group(group_response)
79 } else {
80 let result: Value = match serde_json::from_str(&stdout) {
81 Ok(r) => {r},
82 Err(err) => {
83 return Err(DscError::Operation(t!("dscresources.commandResource.failedParseJson", executable = &get.executable, stdout = stdout, stderr = stderr, err = err).to_string()))
84 }
85 };
86 GetResult::Resource(ResourceGetResponse{
87 actual_state: result,
88 })
89 };
90
91 Ok(result)
92}
93
94/// Invoke the set operation on a resource
95///

Callers 5

getMethod · 0.70
invoke_setFunction · 0.70
invoke_testFunction · 0.70
invoke_synthetic_testFunction · 0.70
invoke_exportFunction · 0.70

Calls 10

process_get_argsFunction · 0.85
get_command_inputFunction · 0.85
invoke_commandFunction · 0.70
from_strFunction · 0.50
OperationEnum · 0.50
ResourceClass · 0.50
as_refMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected