44use crate :: discovery:: discovery_trait:: ResourceDiscovery ;
55use crate :: discovery:: convert_wildcard_to_regex;
66use crate :: dscresources:: dscresource:: { Capability , DscResource , ImplementedAs } ;
7- use crate :: dscresources:: resource_manifest:: { import_manifest, validate_semver, Kind , ResourceManifest } ;
7+ use crate :: dscresources:: resource_manifest:: { import_manifest, validate_semver, Kind , ResourceManifest , SchemaKind } ;
88use crate :: dscresources:: command_resource:: invoke_command;
99use crate :: dscerror:: DscError ;
1010use crate :: progress:: { ProgressBar , ProgressFormat } ;
@@ -22,6 +22,7 @@ use std::io::BufReader;
2222use std:: path:: { Path , PathBuf } ;
2323use std:: str:: FromStr ;
2424use tracing:: { debug, info, trace, warn} ;
25+ use which:: which;
2526
2627use crate :: util:: get_setting;
2728use crate :: util:: get_exe_path;
@@ -531,33 +532,41 @@ fn load_manifest(path: &Path) -> Result<DscResource, DscError> {
531532 Kind :: Resource
532533 } ;
533534
534- // all command based resources are required to support `get`
535- let mut capabilities = if manifest. get . is_some ( ) {
536- vec ! [ Capability :: Get ]
537- } else {
538- vec ! [ ]
539- } ;
535+ let mut capabilities: Vec < Capability > = vec ! [ ] ;
536+ if let Some ( get) = & manifest. get {
537+ verify_executable ( & manifest. resource_type , "get" , & get. executable ) ;
538+ capabilities. push ( Capability :: Get ) ;
539+ }
540540 if let Some ( set) = & manifest. set {
541+ verify_executable ( & manifest. resource_type , "set" , & set. executable ) ;
541542 capabilities. push ( Capability :: Set ) ;
542543 if set. handles_exist == Some ( true ) {
543544 capabilities. push ( Capability :: SetHandlesExist ) ;
544545 }
545546 }
546- if manifest. what_if . is_some ( ) {
547+ if let Some ( what_if) = & manifest. what_if {
548+ verify_executable ( & manifest. resource_type , "what_if" , & what_if. executable ) ;
547549 capabilities. push ( Capability :: WhatIf ) ;
548550 }
549- if manifest. test . is_some ( ) {
551+ if let Some ( test) = & manifest. test {
552+ verify_executable ( & manifest. resource_type , "test" , & test. executable ) ;
550553 capabilities. push ( Capability :: Test ) ;
551554 }
552- if manifest. delete . is_some ( ) {
555+ if let Some ( delete) = & manifest. delete {
556+ verify_executable ( & manifest. resource_type , "delete" , & delete. executable ) ;
553557 capabilities. push ( Capability :: Delete ) ;
554558 }
555- if manifest. export . is_some ( ) {
559+ if let Some ( export) = & manifest. export {
560+ verify_executable ( & manifest. resource_type , "export" , & export. executable ) ;
556561 capabilities. push ( Capability :: Export ) ;
557562 }
558- if manifest. resolve . is_some ( ) {
563+ if let Some ( resolve) = & manifest. resolve {
564+ verify_executable ( & manifest. resource_type , "resolve" , & resolve. executable ) ;
559565 capabilities. push ( Capability :: Resolve ) ;
560566 }
567+ if let Some ( SchemaKind :: Command ( command) ) = & manifest. schema {
568+ verify_executable ( & manifest. resource_type , "schema" , & command. executable ) ;
569+ }
561570
562571 let resource = DscResource {
563572 type_name : manifest. resource_type . clone ( ) ,
@@ -575,6 +584,12 @@ fn load_manifest(path: &Path) -> Result<DscResource, DscError> {
575584 Ok ( resource)
576585}
577586
587+ fn verify_executable ( resource : & str , operation : & str , executable : & str ) {
588+ if which ( executable) . is_err ( ) {
589+ warn ! ( "{}" , t!( "discovery.commandDiscovery.executableNotFound" , resource = resource, operation = operation, executable = executable) ) ;
590+ }
591+ }
592+
578593fn sort_adapters_based_on_lookup_table ( unsorted_adapters : & BTreeMap < String , Vec < DscResource > > , needed_resource_types : & Vec < String > ) -> LinkedHashMap < String , Vec < DscResource > >
579594{
580595 let mut result = LinkedHashMap :: < String , Vec < DscResource > > :: new ( ) ;
0 commit comments