Skip to content

Commit

Permalink
add Check command to check if a component is compatible with edgee
Browse files Browse the repository at this point in the history
  • Loading branch information
CLEMENTINATOR committed Feb 3, 2025
1 parent 73c413e commit 073519d
Show file tree
Hide file tree
Showing 4 changed files with 98 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
94 changes: 94 additions & 0 deletions crates/cli/src/commands/components/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use edgee_components_runtime::config::{
ComponentsConfiguration, ConsentMappingComponents, DataCollectionComponentConfig,
DataCollectionComponents,
};
use edgee_components_runtime::context::ComponentsContext;
use std::collections::HashMap;

#[derive(Debug, clap::Parser)]
pub struct Options {
#[clap(short, long, num_args(1..))]
pub data_collection_component: Option<Vec<String>>,

#[clap(short, long, num_args(1..))]
pub consent_mapping_component: Option<Vec<String>>,
}

pub async fn run(_opts: Options) -> anyhow::Result<()> {
use crate::components::manifest::{self, Manifest};

let (dc_components, cmp_components) = match (
_opts.data_collection_component.as_ref(),
_opts.consent_mapping_component.as_ref(),
) {
(None, None) => {
let manifest_path = manifest::find_manifest_path()
.ok_or_else(|| anyhow::anyhow!("Manifest not found"))?;

let manifest = Manifest::load(&manifest_path)?;
// TODO: dont assume that it is a data collection component, add type in manifest
(
vec![manifest
.package
.build
.output_path
.into_os_string()
.into_string()
.map_err(|_| anyhow::anyhow!("Invalid path"))?],
vec![],
)
}
_ => (
_opts.data_collection_component.unwrap_or_default(),
_opts.consent_mapping_component.unwrap_or_default(),
),
};

// load a wasm host with a default configuration including the component we want to check
let config = ComponentsConfiguration {
data_collection: dc_components
.into_iter()
.map(|component_path| DataCollectionComponents {
id: "id".to_string(),
name: component_path.clone(),
component: component_path,
credentials: HashMap::new(),
config: DataCollectionComponentConfig {
anonymization: true,
default_consent: "pending".to_string(),
track_event_enabled: true,
user_event_enabled: true,
page_event_enabled: true,
},
forward_client_headers: None,
})
.collect(),
consent_mapping: cmp_components
.into_iter()
.map(|component_path| ConsentMappingComponents {
name: component_path.clone(),
component: component_path,
config: Default::default(),
})
.collect(),
cache: None,
};

// check that the world is correctly implemented by components
let context = ComponentsContext::new(&config)?;
let mut store = context.empty_store();

for name in context.components.data_collection.keys() {
let _ = context
.get_data_collection_instance(name, &mut store)
.await?;
}

for name in context.components.consent_mapping.keys() {
let _ = context
.get_consent_mapping_instance(name, &mut store)
.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 073519d

Please sign in to comment.