@@ -6,7 +6,7 @@ use jsonschema::Validator;
66use rust_i18n:: t;
77use serde:: Deserialize ;
88use serde_json:: { Map , Value } ;
9- use std:: { collections:: HashMap , env, process:: Stdio } ;
9+ use std:: { collections:: HashMap , env, path :: Path , process:: Stdio } ;
1010use crate :: { configure:: { config_doc:: ExecutionKind , config_result:: { ResourceGetResult , ResourceTestResult } } , util:: canonicalize_which} ;
1111use crate :: dscerror:: DscError ;
1212use 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 } } ;
@@ -25,7 +25,7 @@ pub const EXIT_PROCESS_TERMINATED: i32 = 0x102;
2525/// # Errors
2626///
2727/// Error returned if the resource does not successfully get the current state
28- pub fn invoke_get ( resource : & ResourceManifest , cwd : & str , filter : & str , target_resource : Option < & str > ) -> Result < GetResult , DscError > {
28+ pub fn invoke_get ( resource : & ResourceManifest , cwd : & Path , filter : & str , target_resource : Option < & str > ) -> Result < GetResult , DscError > {
2929 debug ! ( "{}" , t!( "dscresources.commandResource.invokeGet" , resource = & resource. resource_type) ) ;
3030 let mut command_input = CommandInput { env : None , stdin : None } ;
3131 let Some ( get) = & resource. get else {
@@ -78,7 +78,7 @@ pub fn invoke_get(resource: &ResourceManifest, cwd: &str, filter: &str, target_r
7878///
7979/// Error returned if the resource does not successfully set the desired state
8080#[ allow( clippy:: too_many_lines) ]
81- pub fn invoke_set ( resource : & ResourceManifest , cwd : & str , desired : & str , skip_test : bool , execution_type : & ExecutionKind , target_resource : Option < & str > ) -> Result < SetResult , DscError > {
81+ pub fn invoke_set ( resource : & ResourceManifest , cwd : & Path , desired : & str , skip_test : bool , execution_type : & ExecutionKind , target_resource : Option < & str > ) -> Result < SetResult , DscError > {
8282 debug ! ( "{}" , t!( "dscresources.commandResource.invokeSet" , resource = & resource. resource_type) ) ;
8383 let operation_type: String ;
8484 let mut is_synthetic_what_if = false ;
@@ -271,7 +271,7 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
271271/// # Errors
272272///
273273/// Error is returned if the underlying command returns a non-zero exit code.
274- pub fn invoke_test ( resource : & ResourceManifest , cwd : & str , expected : & str , target_resource : Option < & str > ) -> Result < TestResult , DscError > {
274+ pub fn invoke_test ( resource : & ResourceManifest , cwd : & Path , expected : & str , target_resource : Option < & str > ) -> Result < TestResult , DscError > {
275275 debug ! ( "{}" , t!( "dscresources.commandResource.invokeTest" , resource = & resource. resource_type) ) ;
276276 let Some ( test) = & resource. test else {
277277 info ! ( "{}" , t!( "dscresources.commandResource.testSyntheticTest" , resource = & resource. resource_type) ) ;
@@ -380,7 +380,7 @@ fn get_desired_state(actual: &Value) -> Result<Option<bool>, DscError> {
380380 Ok ( in_desired_state)
381381}
382382
383- fn invoke_synthetic_test ( resource : & ResourceManifest , cwd : & str , expected : & str , target_resource : Option < & str > ) -> Result < TestResult , DscError > {
383+ fn invoke_synthetic_test ( resource : & ResourceManifest , cwd : & Path , expected : & str , target_resource : Option < & str > ) -> Result < TestResult , DscError > {
384384 let get_result = invoke_get ( resource, cwd, expected, target_resource) ?;
385385 let actual_state = match get_result {
386386 GetResult :: Group ( results) => {
@@ -415,7 +415,7 @@ fn invoke_synthetic_test(resource: &ResourceManifest, cwd: &str, expected: &str,
415415/// # Errors
416416///
417417/// Error is returned if the underlying command returns a non-zero exit code.
418- pub fn invoke_delete ( resource : & ResourceManifest , cwd : & str , filter : & str , target_resource : Option < & str > ) -> Result < ( ) , DscError > {
418+ pub fn invoke_delete ( resource : & ResourceManifest , cwd : & Path , filter : & str , target_resource : Option < & str > ) -> Result < ( ) , DscError > {
419419 let Some ( delete) = & resource. delete else {
420420 return Err ( DscError :: NotImplemented ( "delete" . to_string ( ) ) ) ;
421421 } ;
@@ -450,7 +450,7 @@ pub fn invoke_delete(resource: &ResourceManifest, cwd: &str, filter: &str, targe
450450/// # Errors
451451///
452452/// Error is returned if the underlying command returns a non-zero exit code.
453- pub fn invoke_validate ( resource : & ResourceManifest , cwd : & str , config : & str , target_resource : Option < & str > ) -> Result < ValidateResult , DscError > {
453+ pub fn invoke_validate ( resource : & ResourceManifest , cwd : & Path , config : & str , target_resource : Option < & str > ) -> Result < ValidateResult , DscError > {
454454 trace ! ( "{}" , t!( "dscresources.commandResource.invokeValidateConfig" , resource = & resource. resource_type, config = & config) ) ;
455455 // TODO: use schema to validate config if validate is not implemented
456456 let Some ( validate) = resource. validate . as_ref ( ) else {
@@ -479,7 +479,7 @@ pub fn invoke_validate(resource: &ResourceManifest, cwd: &str, config: &str, tar
479479/// # Errors
480480///
481481/// Error if schema is not available or if there is an error getting the schema
482- pub fn get_schema ( resource : & ResourceManifest , cwd : & str ) -> Result < String , DscError > {
482+ pub fn get_schema ( resource : & ResourceManifest , cwd : & Path ) -> Result < String , DscError > {
483483 let Some ( schema_kind) = resource. schema . as_ref ( ) else {
484484 return Err ( DscError :: SchemaNotAvailable ( resource. resource_type . clone ( ) ) ) ;
485485 } ;
@@ -511,7 +511,7 @@ pub fn get_schema(resource: &ResourceManifest, cwd: &str) -> Result<String, DscE
511511/// # Errors
512512///
513513/// Error returned if the resource does not successfully export the current state
514- pub fn invoke_export ( resource : & ResourceManifest , cwd : & str , input : Option < & str > , target_resource : Option < & str > ) -> Result < ExportResult , DscError > {
514+ pub fn invoke_export ( resource : & ResourceManifest , cwd : & Path , input : Option < & str > , target_resource : Option < & str > ) -> Result < ExportResult , DscError > {
515515 let Some ( export) = resource. export . as_ref ( ) else {
516516 // see if get is supported and use that instead
517517 if resource. get . is_some ( ) {
@@ -591,7 +591,7 @@ pub fn invoke_export(resource: &ResourceManifest, cwd: &str, input: Option<&str>
591591/// # Errors
592592///
593593/// Error returned if the resource does not successfully resolve the input
594- pub fn invoke_resolve ( resource : & ResourceManifest , cwd : & str , input : & str ) -> Result < ResolveResult , DscError > {
594+ pub fn invoke_resolve ( resource : & ResourceManifest , cwd : & Path , input : & str ) -> Result < ResolveResult , DscError > {
595595 let Some ( resolve) = & resource. resolve else {
596596 return Err ( DscError :: Operation ( t ! ( "dscresources.commandResource.resolveNotSupported" , resource = & resource. resource_type) . to_string ( ) ) ) ;
597597 } ;
@@ -620,7 +620,7 @@ pub fn invoke_resolve(resource: &ResourceManifest, cwd: &str, input: &str) -> Re
620620///
621621/// Error is returned if the command fails to execute or stdin/stdout/stderr cannot be opened.
622622///
623- async fn run_process_async ( 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 > {
623+ async fn run_process_async ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & Path > , env : Option < HashMap < String , String > > , exit_codes : Option < & HashMap < i32 , String > > ) -> Result < ( i32 , String , String ) , DscError > {
624624
625625 // use somewhat large initial buffer to avoid early string reallocations;
626626 // the value is based on list result of largest of built-in adapters - WMI adapter ~500KB
@@ -761,15 +761,15 @@ fn convert_hashmap_string_keys_to_i32(input: Option<&HashMap<String, String>>) -
761761/// Will panic if tokio runtime can't be created.
762762///
763763#[ allow( clippy:: implicit_hasher) ]
764- pub fn invoke_command ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & str > , env : Option < HashMap < String , String > > , exit_codes : Option < & HashMap < String , String > > ) -> Result < ( i32 , String , String ) , DscError > {
764+ pub fn invoke_command ( executable : & str , args : Option < Vec < String > > , input : Option < & str > , cwd : Option < & Path > , env : Option < HashMap < String , String > > , exit_codes : Option < & HashMap < String , String > > ) -> Result < ( i32 , String , String ) , DscError > {
765765 let exit_codes = convert_hashmap_string_keys_to_i32 ( exit_codes) ?;
766766 let executable = canonicalize_which ( executable, cwd) ?;
767767
768768 tokio:: runtime:: Builder :: new_multi_thread ( ) . enable_all ( ) . build ( ) . unwrap ( ) . block_on (
769769 async {
770770 trace ! ( "{}" , t!( "dscresources.commandResource.commandInvoke" , executable = executable, args = args : { : ?} ) ) ;
771771 if let Some ( cwd) = cwd {
772- trace ! ( "{}" , t!( "dscresources.commandResource.commandCwd" , cwd = cwd) ) ;
772+ trace ! ( "{}" , t!( "dscresources.commandResource.commandCwd" , cwd = cwd. display ( ) ) ) ;
773773 }
774774
775775 match run_process_async ( & executable, args, input, cwd, env, exit_codes. as_ref ( ) ) . await {
@@ -854,7 +854,7 @@ fn get_command_input(input_kind: Option<&InputKind>, input: &str) -> Result<Comm
854854 } )
855855}
856856
857- fn verify_json ( resource : & ResourceManifest , cwd : & str , json : & str ) -> Result < ( ) , DscError > {
857+ fn verify_json ( resource : & ResourceManifest , cwd : & Path , json : & str ) -> Result < ( ) , DscError > {
858858
859859 debug ! ( "{}" , t!( "dscresources.commandResource.verifyJson" , resource = resource. resource_type) ) ;
860860
0 commit comments