4
4
use crate :: discovery:: discovery_trait:: ResourceDiscovery ;
5
5
use crate :: discovery:: convert_wildcard_to_regex;
6
6
use 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 } ;
8
8
use crate :: dscresources:: command_resource:: invoke_command;
9
9
use crate :: dscerror:: DscError ;
10
10
use crate :: progress:: { ProgressBar , ProgressFormat } ;
@@ -22,6 +22,7 @@ use std::io::BufReader;
22
22
use std:: path:: { Path , PathBuf } ;
23
23
use std:: str:: FromStr ;
24
24
use tracing:: { debug, info, trace, warn} ;
25
+ use which:: which;
25
26
26
27
use crate :: util:: get_setting;
27
28
use crate :: util:: get_exe_path;
@@ -531,33 +532,41 @@ fn load_manifest(path: &Path) -> Result<DscResource, DscError> {
531
532
Kind :: Resource
532
533
} ;
533
534
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
+ }
540
540
if let Some ( set) = & manifest. set {
541
+ verify_executable ( & manifest. resource_type , "set" , & set. executable ) ;
541
542
capabilities. push ( Capability :: Set ) ;
542
543
if set. handles_exist == Some ( true ) {
543
544
capabilities. push ( Capability :: SetHandlesExist ) ;
544
545
}
545
546
}
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 ) ;
547
549
capabilities. push ( Capability :: WhatIf ) ;
548
550
}
549
- if manifest. test . is_some ( ) {
551
+ if let Some ( test) = & manifest. test {
552
+ verify_executable ( & manifest. resource_type , "test" , & test. executable ) ;
550
553
capabilities. push ( Capability :: Test ) ;
551
554
}
552
- if manifest. delete . is_some ( ) {
555
+ if let Some ( delete) = & manifest. delete {
556
+ verify_executable ( & manifest. resource_type , "delete" , & delete. executable ) ;
553
557
capabilities. push ( Capability :: Delete ) ;
554
558
}
555
- if manifest. export . is_some ( ) {
559
+ if let Some ( export) = & manifest. export {
560
+ verify_executable ( & manifest. resource_type , "export" , & export. executable ) ;
556
561
capabilities. push ( Capability :: Export ) ;
557
562
}
558
- if manifest. resolve . is_some ( ) {
563
+ if let Some ( resolve) = & manifest. resolve {
564
+ verify_executable ( & manifest. resource_type , "resolve" , & resolve. executable ) ;
559
565
capabilities. push ( Capability :: Resolve ) ;
560
566
}
567
+ if let Some ( SchemaKind :: Command ( command) ) = & manifest. schema {
568
+ verify_executable ( & manifest. resource_type , "schema" , & command. executable ) ;
569
+ }
561
570
562
571
let resource = DscResource {
563
572
type_name : manifest. resource_type . clone ( ) ,
@@ -575,6 +584,12 @@ fn load_manifest(path: &Path) -> Result<DscResource, DscError> {
575
584
Ok ( resource)
576
585
}
577
586
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
+
578
593
fn sort_adapters_based_on_lookup_table ( unsorted_adapters : & BTreeMap < String , Vec < DscResource > > , needed_resource_types : & Vec < String > ) -> LinkedHashMap < String , Vec < DscResource > >
579
594
{
580
595
let mut result = LinkedHashMap :: < String , Vec < DscResource > > :: new ( ) ;
0 commit comments