@@ -607,6 +607,18 @@ fn insert_resource(resources: &mut BTreeMap<String, Vec<DscResource>>, resource:
607607 }
608608}
609609
610+ fn evaluate_condition ( condition : Option < & str > ) -> Result < bool , DscError > {
611+ if let Some ( cond) = condition {
612+ let mut statement = Statement :: new ( ) ?;
613+ let result = statement. parse_and_execute ( cond, & Context :: new ( ) ) ?;
614+ if let Some ( bool_result) = result. as_bool ( ) {
615+ return Ok ( bool_result) ;
616+ }
617+ return Err ( DscError :: Validation ( t ! ( "discovery.commandDiscovery.conditionNotBoolean" , condition = cond) . to_string ( ) ) ) ;
618+ }
619+ Ok ( true )
620+ }
621+
610622/// Loads a manifest from the given path and returns a vector of `ImportedManifest`.
611623///
612624/// # Arguments
@@ -690,7 +702,7 @@ pub fn load_manifest(path: &Path) -> Result<Vec<ImportedManifest>, DscError> {
690702 if let Some ( resource_manifests) = & manifest_list. resources {
691703 for res_manifest in resource_manifests {
692704 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 ( ) ) ) ;
705+ debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = res_manifest. condition. as_ref ( ) : { : ? } ) ) ;
694706 continue ;
695707 }
696708 let resource = load_resource_manifest ( path, res_manifest) ?;
@@ -700,7 +712,7 @@ pub fn load_manifest(path: &Path) -> Result<Vec<ImportedManifest>, DscError> {
700712 if let Some ( extension_manifests) = & manifest_list. extensions {
701713 for ext_manifest in extension_manifests {
702714 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 ( ) ) ) ;
715+ debug ! ( "{}" , t!( "discovery.commandDiscovery.conditionNotMet" , path = path. to_string_lossy( ) , condition = ext_manifest. condition. as_ref ( ) : { : ? } ) ) ;
704716 continue ;
705717 }
706718 let extension = load_extension_manifest ( path, ext_manifest) ?;
0 commit comments