-
Notifications
You must be signed in to change notification settings - Fork 8
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
- Loading branch information
1 parent
73c413e
commit cdee835
Showing
4 changed files
with
98 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,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 { | ||
let _ = context | ||
.get_data_collection_instance(name, &mut store) | ||
.await?; | ||
} | ||
|
||
for (name, _) in &context.components.consent_mapping { | ||
let _ = context | ||
.get_consent_mapping_instance(name, &mut store) | ||
.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