Skip to content

Commit

Permalink
add Check command to check if a component is compatible with edgee (#198
Browse files Browse the repository at this point in the history
)
  • Loading branch information
CLEMENTINATOR authored Feb 5, 2025
1 parent dee49cc commit e27b4cf
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }

edgee-api-client.workspace = true
edgee-server.workspace = true
edgee-components-runtime.workspace = true

[features]
bundled = [
Expand Down
87 changes: 87 additions & 0 deletions crates/cli/src/commands/components/check.rs
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(())
}
2 changes: 2 additions & 0 deletions crates/cli/src/commands/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ setup_commands! {
Push(push),
/// List currently pulled components
List(list),
/// Check if a component implements the required interfaces
Check(check)
}

pub type Options = Command;
Expand Down

0 comments on commit e27b4cf

Please sign in to comment.