@@ -9,7 +9,7 @@ use serde_json::{Map, Value};
99use std:: { collections:: HashMap , env, process:: Stdio } ;
1010use crate :: configure:: { config_doc:: ExecutionKind , config_result:: { ResourceGetResult , ResourceTestResult } } ;
1111use crate :: dscerror:: DscError ;
12- use super :: { dscresource:: get_diff, invoke_result:: { ExportResult , GetResult , ResolveResult , SetResult , TestResult , ValidateResult , ResourceGetResponse , ResourceSetResponse , ResourceTestResponse , get_in_desired_state} , resource_manifest:: { ArgKind , InputKind , Kind , ResourceManifest , ReturnKind , SchemaKind } } ;
12+ use super :: { dscresource:: { get_diff, redact } , invoke_result:: { ExportResult , GetResult , ResolveResult , SetResult , TestResult , ValidateResult , ResourceGetResponse , ResourceSetResponse , ResourceTestResponse , get_in_desired_state} , resource_manifest:: { ArgKind , InputKind , Kind , ResourceManifest , ReturnKind , SchemaKind } } ;
1313use tracing:: { error, warn, info, debug, trace} ;
1414use tokio:: { io:: { AsyncBufReadExt , AsyncWriteExt , BufReader } , process:: Command } ;
1515
@@ -120,8 +120,9 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
120120 } ;
121121
122122 if in_desired_state && execution_type == & ExecutionKind :: Actual {
123+ let before_state = redact ( & serde_json:: from_str ( desired) ?) ;
123124 return Ok ( SetResult :: Resource ( ResourceSetResponse {
124- before_state : serde_json :: from_str ( desired ) ? ,
125+ before_state,
125126 after_state : actual_state,
126127 changed_properties : None ,
127128 } ) ) ;
@@ -152,7 +153,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
152153 else {
153154 return Err ( DscError :: Command ( resource. resource_type . clone ( ) , exit_code, stderr) ) ;
154155 } ;
155- let pre_state = if pre_state_value. is_object ( ) {
156+ let mut pre_state = if pre_state_value. is_object ( ) {
156157 let mut pre_state_map: Map < String , Value > = serde_json:: from_value ( pre_state_value) ?;
157158
158159 // if the resource is an adapter, then the `get` will return a `result`, but a full `set` expects the before state to be `resources`
@@ -200,6 +201,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
200201
201202 // for changed_properties, we compare post state to pre state
202203 let diff_properties = get_diff ( & actual_value, & pre_state) ;
204+ pre_state = redact ( & pre_state) ;
203205 Ok ( SetResult :: Resource ( ResourceSetResponse {
204206 before_state : pre_state,
205207 after_state : actual_value,
@@ -241,6 +243,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
241243 }
242244 } ;
243245 let diff_properties = get_diff ( & actual_state, & pre_state) ;
246+ pre_state = redact ( & pre_state) ;
244247 Ok ( SetResult :: Resource ( ResourceSetResponse {
245248 before_state : pre_state,
246249 after_state : actual_state,
@@ -286,7 +289,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
286289 return Ok ( TestResult :: Group ( group_test_response) ) ;
287290 }
288291
289- let expected_value: Value = serde_json:: from_str ( expected) ?;
292+ let mut expected_value: Value = serde_json:: from_str ( expected) ?;
290293 match test. returns {
291294 Some ( ReturnKind :: State ) => {
292295 let actual_value: Value = match serde_json:: from_str ( & stdout) {
@@ -297,6 +300,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
297300 } ;
298301 let in_desired_state = get_desired_state ( & actual_value) ?;
299302 let diff_properties = get_diff ( & expected_value, & actual_value) ;
303+ expected_value = redact ( & expected_value) ;
300304 Ok ( TestResult :: Resource ( ResourceTestResponse {
301305 desired_state : expected_value,
302306 actual_state : actual_value,
@@ -315,6 +319,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
315319 return Err ( DscError :: Command ( resource. resource_type . clone ( ) , exit_code, t ! ( "dscresources.commandResource.testNoDiff" ) . to_string ( ) ) ) ;
316320 } ;
317321 let diff_properties: Vec < String > = serde_json:: from_str ( diff_properties) ?;
322+ expected_value = redact ( & expected_value) ;
318323 let in_desired_state = get_desired_state ( & actual_value) ?;
319324 Ok ( TestResult :: Resource ( ResourceTestResponse {
320325 desired_state : expected_value,
@@ -339,6 +344,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
339344 }
340345 } ;
341346 let diff_properties = get_diff ( & expected_value, & actual_state) ;
347+ expected_value = redact ( & expected_value) ;
342348 Ok ( TestResult :: Resource ( ResourceTestResponse {
343349 desired_state : expected_value,
344350 actual_state,
@@ -717,9 +723,9 @@ async fn run_process_async(executable: &str, args: Option<Vec<String>>, input: O
717723#[ allow( clippy:: implicit_hasher) ]
718724#[ tokio:: main]
719725pub async fn invoke_command ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & str > , env : Option < HashMap < String , String > > , exit_codes : Option < & HashMap < i32 , String > > ) -> Result < ( i32 , String , String ) , DscError > {
720- debug ! ( "{}" , t!( "dscresources.commandResource.commandInvoke" , executable = executable, args = args : { : ?} ) ) ;
726+ trace ! ( "{}" , t!( "dscresources.commandResource.commandInvoke" , executable = executable, args = args : { : ?} ) ) ;
721727 if let Some ( cwd) = cwd {
722- debug ! ( "{}" , t!( "dscresources.commandResource.commandCwd" , cwd = cwd) ) ;
728+ trace ! ( "{}" , t!( "dscresources.commandResource.commandCwd" , cwd = cwd) ) ;
723729 }
724730
725731 match run_process_async ( executable, args, input, cwd, env, exit_codes) . await {
0 commit comments