Skip to content

Commit 4bd4c97

Browse files
committed
fix merge
1 parent ddf7e6a commit 4bd4c97

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/dsc-lib/src/discovery/command_discovery.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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)?;

lib/dsc-lib/src/extensions/discover.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl DscExtension {
9191
let manifest_path = Path::new(&discover_result.manifest_path);
9292
// Currently we don't support extensions discovering other extensions
9393
for imported_manifest in load_manifest(manifest_path)? {
94-
if let Some(ImportedManifest::Resource(resource)) = imported_manifest {
94+
if let ImportedManifest::Resource(resource) = imported_manifest {
9595
resources.push(resource);
9696
}
9797
}

0 commit comments

Comments
 (0)