@@ -9,7 +9,7 @@ use serde_json::{Map, Value};
9
9
use std:: { collections:: HashMap , env, process:: Stdio } ;
10
10
use crate :: configure:: { config_doc:: ExecutionKind , config_result:: { ResourceGetResult , ResourceTestResult } } ;
11
11
use 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 } } ;
13
13
use tracing:: { error, warn, info, debug, trace} ;
14
14
use tokio:: { io:: { AsyncBufReadExt , AsyncWriteExt , BufReader } , process:: Command } ;
15
15
@@ -120,8 +120,9 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
120
120
} ;
121
121
122
122
if in_desired_state && execution_type == & ExecutionKind :: Actual {
123
+ let before_state = redact ( & serde_json:: from_str ( desired) ?) ;
123
124
return Ok ( SetResult :: Resource ( ResourceSetResponse {
124
- before_state : serde_json :: from_str ( desired ) ? ,
125
+ before_state,
125
126
after_state : actual_state,
126
127
changed_properties : None ,
127
128
} ) ) ;
@@ -152,7 +153,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
152
153
else {
153
154
return Err ( DscError :: Command ( resource. resource_type . clone ( ) , exit_code, stderr) ) ;
154
155
} ;
155
- let pre_state = if pre_state_value. is_object ( ) {
156
+ let mut pre_state = if pre_state_value. is_object ( ) {
156
157
let mut pre_state_map: Map < String , Value > = serde_json:: from_value ( pre_state_value) ?;
157
158
158
159
// 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
200
201
201
202
// for changed_properties, we compare post state to pre state
202
203
let diff_properties = get_diff ( & actual_value, & pre_state) ;
204
+ pre_state = redact ( & pre_state) ;
203
205
Ok ( SetResult :: Resource ( ResourceSetResponse {
204
206
before_state : pre_state,
205
207
after_state : actual_value,
@@ -241,6 +243,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
241
243
}
242
244
} ;
243
245
let diff_properties = get_diff ( & actual_state, & pre_state) ;
246
+ pre_state = redact ( & pre_state) ;
244
247
Ok ( SetResult :: Resource ( ResourceSetResponse {
245
248
before_state : pre_state,
246
249
after_state : actual_state,
@@ -286,7 +289,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
286
289
return Ok ( TestResult :: Group ( group_test_response) ) ;
287
290
}
288
291
289
- let expected_value: Value = serde_json:: from_str ( expected) ?;
292
+ let mut expected_value: Value = serde_json:: from_str ( expected) ?;
290
293
match test. returns {
291
294
Some ( ReturnKind :: State ) => {
292
295
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
297
300
} ;
298
301
let in_desired_state = get_desired_state ( & actual_value) ?;
299
302
let diff_properties = get_diff ( & expected_value, & actual_value) ;
303
+ expected_value = redact ( & expected_value) ;
300
304
Ok ( TestResult :: Resource ( ResourceTestResponse {
301
305
desired_state : expected_value,
302
306
actual_state : actual_value,
@@ -315,6 +319,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
315
319
return Err ( DscError :: Command ( resource. resource_type . clone ( ) , exit_code, t ! ( "dscresources.commandResource.testNoDiff" ) . to_string ( ) ) ) ;
316
320
} ;
317
321
let diff_properties: Vec < String > = serde_json:: from_str ( diff_properties) ?;
322
+ expected_value = redact ( & expected_value) ;
318
323
let in_desired_state = get_desired_state ( & actual_value) ?;
319
324
Ok ( TestResult :: Resource ( ResourceTestResponse {
320
325
desired_state : expected_value,
@@ -339,6 +344,7 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
339
344
}
340
345
} ;
341
346
let diff_properties = get_diff ( & expected_value, & actual_state) ;
347
+ expected_value = redact ( & expected_value) ;
342
348
Ok ( TestResult :: Resource ( ResourceTestResponse {
343
349
desired_state : expected_value,
344
350
actual_state,
@@ -717,9 +723,9 @@ async fn run_process_async(executable: &str, args: Option<Vec<String>>, input: O
717
723
#[ allow( clippy:: implicit_hasher) ]
718
724
#[ tokio:: main]
719
725
pub 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 : { : ?} ) ) ;
721
727
if let Some ( cwd) = cwd {
722
- debug ! ( "{}" , t!( "dscresources.commandResource.commandCwd" , cwd = cwd) ) ;
728
+ trace ! ( "{}" , t!( "dscresources.commandResource.commandCwd" , cwd = cwd) ) ;
723
729
}
724
730
725
731
match run_process_async ( executable, args, input, cwd, env, exit_codes) . await {
0 commit comments