11// Copyright (c) Microsoft Corporation.
22// Licensed under the MIT License.
33
4- use crate :: { discovery:: discovery_trait:: { DiscoveryFilter , DiscoveryKind , ResourceDiscovery } } ;
4+ use crate :: { discovery:: discovery_trait:: { DiscoveryFilter , DiscoveryKind , ResourceDiscovery } , parser :: Statement } ;
55use crate :: { locked_is_empty, locked_extend, locked_clone, locked_get} ;
6+ use crate :: configure:: context:: Context ;
67use crate :: dscresources:: dscresource:: { Capability , DscResource , ImplementedAs } ;
78use crate :: dscresources:: resource_manifest:: { import_manifest, validate_semver, Kind , ResourceManifest , SchemaKind } ;
89use crate :: dscresources:: command_resource:: invoke_command;
@@ -639,6 +640,10 @@ pub fn load_manifest(path: &Path) -> Result<Vec<ImportedManifest>, DscError> {
639640 }
640641 }
641642 } ;
643+ if !evaluate_condition ( manifest. condition . as_deref ( ) ) ? {
644+ debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = manifest. condition. unwrap_or_default( ) ) ) ;
645+ return Ok ( vec ! [ ] ) ;
646+ }
642647 let resource = load_resource_manifest ( path, & manifest) ?;
643648 return Ok ( vec ! [ ImportedManifest :: Resource ( resource) ] ) ;
644649 }
@@ -658,10 +663,15 @@ pub fn load_manifest(path: &Path) -> Result<Vec<ImportedManifest>, DscError> {
658663 }
659664 }
660665 } ;
666+ if !evaluate_condition ( manifest. condition . as_deref ( ) ) ? {
667+ debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = manifest. condition. unwrap_or_default( ) ) ) ;
668+ return Ok ( vec ! [ ] ) ;
669+ }
661670 let extension = load_extension_manifest ( path, & manifest) ?;
662671 return Ok ( vec ! [ ImportedManifest :: Extension ( extension) ] ) ;
663672 }
664673 if DSC_MANIFEST_LIST_EXTENSIONS . iter ( ) . any ( |ext| file_name_lowercase. ends_with ( ext) ) {
674+ let mut resources: Vec < ImportedManifest > = vec ! [ ] ;
665675 let manifest_list = if extension_is_json {
666676 match serde_json:: from_str :: < ManifestList > ( & contents) {
667677 Ok ( manifest) => manifest,
@@ -677,15 +687,22 @@ pub fn load_manifest(path: &Path) -> Result<Vec<ImportedManifest>, DscError> {
677687 }
678688 }
679689 } ;
680- let mut resources = vec ! [ ] ;
681690 if let Some ( resource_manifests) = & manifest_list. resources {
682691 for res_manifest in resource_manifests {
692+ if !evaluate_condition ( res_manifest. condition . as_deref ( ) ) ? {
693+ debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = res_manifest. condition. unwrap_or_default( ) ) ) ;
694+ continue ;
695+ }
683696 let resource = load_resource_manifest ( path, res_manifest) ?;
684697 resources. push ( ImportedManifest :: Resource ( resource) ) ;
685698 }
686699 }
687700 if let Some ( extension_manifests) = & manifest_list. extensions {
688701 for ext_manifest in extension_manifests {
702+ if !evaluate_condition ( ext_manifest. condition . as_deref ( ) ) ? {
703+ debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = ext_manifest. condition. unwrap_or_default( ) ) ) ;
704+ continue ;
705+ }
689706 let extension = load_extension_manifest ( path, ext_manifest) ?;
690707 resources. push ( ImportedManifest :: Extension ( extension) ) ;
691708 }
0 commit comments