-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Check command to check if a component is compatible with edgee (#198
- Loading branch information
1 parent
dee49cc
commit e27b4cf
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use edgee_components_runtime::config::{ | ||
ComponentsConfiguration, ConsentMappingComponents, DataCollectionComponents, | ||
}; | ||
use edgee_components_runtime::context::ComponentsContext; | ||
|
||
#[derive(Debug, clap::Parser)] | ||
pub struct Options {} | ||
|
||
enum ComponentType { | ||
DataCollection, | ||
#[allow(dead_code)] | ||
ConsentMapping, | ||
} | ||
|
||
async fn check_component( | ||
component_type: ComponentType, | ||
component_path: &str, | ||
) -> anyhow::Result<()> { | ||
if !std::path::Path::new(component_path).exists() { | ||
return Err(anyhow::anyhow!( | ||
"Component {} does not exist. Please run `edgee component build` first", | ||
component_path | ||
)); | ||
} | ||
|
||
let config = match component_type { | ||
ComponentType::DataCollection => ComponentsConfiguration { | ||
data_collection: vec![DataCollectionComponents { | ||
id: component_path.to_string(), | ||
file: component_path.to_string(), | ||
..Default::default() | ||
}], | ||
..Default::default() | ||
}, | ||
ComponentType::ConsentMapping => ComponentsConfiguration { | ||
consent_mapping: vec![ConsentMappingComponents { | ||
name: component_path.to_string(), | ||
component: component_path.to_string(), | ||
..Default::default() | ||
}], | ||
..Default::default() | ||
}, | ||
}; | ||
|
||
let context = ComponentsContext::new(&config) | ||
.map_err(|e| anyhow::anyhow!("Invalid component {}: {}", component_path, e))?; | ||
|
||
let mut store = context.empty_store(); | ||
|
||
match component_type { | ||
ComponentType::DataCollection => { | ||
let _ = context | ||
.get_data_collection_instance(component_path, &mut store) | ||
.await?; | ||
} | ||
ComponentType::ConsentMapping => { | ||
let _ = context | ||
.get_consent_mapping_instance(component_path, &mut store) | ||
.await?; | ||
} | ||
} | ||
|
||
println!("Component {} is valid", component_path); | ||
Ok(()) | ||
} | ||
|
||
pub async fn run(_opts: Options) -> anyhow::Result<()> { | ||
use crate::components::manifest::{self, Manifest}; | ||
|
||
let manifest_path = manifest::find_manifest_path().ok_or_else(|| { | ||
anyhow::anyhow!("Edgee Manifest not found. Please run `edgee component create` and start from a template or `edgee component init` to create a new empty manifest in this folder.") | ||
})?; | ||
|
||
let manifest = Manifest::load(&manifest_path)?; | ||
let component_path = manifest | ||
.package | ||
.build | ||
.output_path | ||
.into_os_string() | ||
.into_string() | ||
.map_err(|_| anyhow::anyhow!("No output path found in manifest."))?; | ||
|
||
// TODO: dont assume that it is a data collection component, add type in manifest | ||
check_component(ComponentType::DataCollection, &component_path).await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters