@@ -608,6 +608,18 @@ fn insert_resource(resources: &mut BTreeMap<String, Vec<DscResource>>, resource:
608608 }
609609}
610610
611+ fn evaluate_condition ( condition : Option < & str > ) -> Result < bool , DscError > {
612+ if let Some ( cond) = condition {
613+ let mut statement = Statement :: new ( ) ?;
614+ let result = statement. parse_and_execute ( cond, & Context :: new ( ) ) ?;
615+ if let Some ( bool_result) = result. as_bool ( ) {
616+ return Ok ( bool_result) ;
617+ }
618+ return Err ( DscError :: Validation ( t ! ( "discovery.commandDiscovery.conditionNotBoolean" , condition = cond) . to_string ( ) ) ) ;
619+ }
620+ Ok ( true )
621+ }
622+
611623/// Loads a manifest from the given path and returns a vector of `ImportedManifest`.
612624///
613625/// # Arguments
@@ -691,7 +703,7 @@ pub fn load_manifest(path: &Path) -> Result<Vec<ImportedManifest>, DscError> {
691703 if let Some ( resource_manifests) = & manifest_list. resources {
692704 for res_manifest in resource_manifests {
693705 if !evaluate_condition ( res_manifest. condition . as_deref ( ) ) ? {
694- debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = res_manifest. condition. unwrap_or_default ( ) ) ) ;
706+ debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = res_manifest. condition. as_ref ( ) : { : ? } ) ) ;
695707 continue ;
696708 }
697709 let resource = load_resource_manifest ( path, res_manifest) ?;
@@ -701,7 +713,7 @@ pub fn load_manifest(path: &Path) -> Result<Vec<ImportedManifest>, DscError> {
701713 if let Some ( extension_manifests) = & manifest_list. extensions {
702714 for ext_manifest in extension_manifests {
703715 if !evaluate_condition ( ext_manifest. condition . as_deref ( ) ) ? {
704- debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = ext_manifest. condition. unwrap_or_default ( ) ) ) ;
716+ debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = ext_manifest. condition. as_ref ( ) : { : ? } ) ) ;
705717 continue ;
706718 }
707719 let extension = load_extension_manifest ( path, ext_manifest) ?;
0 commit comments