diff options
Diffstat (limited to 'crates/core/tedge_mapper')
-rw-r--r-- | crates/core/tedge_mapper/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/core/tedge_mapper/src/c8y/converter.rs | 8 | ||||
-rw-r--r-- | crates/core/tedge_mapper/src/c8y/dynamic_discovery.rs | 12 | ||||
-rw-r--r-- | crates/core/tedge_mapper/src/c8y/error.rs | 1 | ||||
-rw-r--r-- | crates/core/tedge_mapper/src/c8y/mapper.rs | 2 | ||||
-rw-r--r-- | crates/core/tedge_mapper/src/core/error.rs | 3 | ||||
-rw-r--r-- | crates/core/tedge_mapper/src/core/mapper.rs | 29 | ||||
-rw-r--r-- | crates/core/tedge_mapper/src/main.rs | 7 |
8 files changed, 31 insertions, 34 deletions
diff --git a/crates/core/tedge_mapper/Cargo.toml b/crates/core/tedge_mapper/Cargo.toml index d7464294..bb68c8db 100644 --- a/crates/core/tedge_mapper/Cargo.toml +++ b/crates/core/tedge_mapper/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tedge_mapper" -version = "0.7.1" +version = "0.7.2" authors = ["thin-edge.io team <info@thin-edge.io>"] edition = "2021" rust-version = "1.58.1" @@ -47,7 +47,6 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" clap = { version = "3.0", features = ["cargo", "derive"] } tedge_config = { path = "../../common/tedge_config" } -tedge_users = { path = "../../common/tedge_users" } tedge_utils = { path = "../../common/tedge_utils", features = ["logging"] } thin_edge_json = { path = "../thin_edge_json" } thiserror = "1.0" diff --git a/crates/core/tedge_mapper/src/c8y/converter.rs b/crates/core/tedge_mapper/src/c8y/converter.rs index 9ec58cb0..fd9223b5 100644 --- a/crates/core/tedge_mapper/src/c8y/converter.rs +++ b/crates/core/tedge_mapper/src/c8y/converter.rs @@ -357,13 +357,13 @@ where message: &DiscoverOp, ) -> Result<Option<Message>, ConversionError> { match message.event_type { - EventType::ADD => { + EventType::Add => { let ops_dir = message.ops_dir.clone(); let op_name = message.operation_name.clone(); let op = get_operation(ops_dir.join(op_name))?; self.operations.add_operation(op); } - EventType::REMOVE => { + EventType::Remove => { self.operations.remove_operation(&message.operation_name); } } @@ -379,7 +379,7 @@ async fn parse_c8y_topics( ) -> Result<Vec<Message>, ConversionError> { match process_smartrest( message.payload_str()?, - &operations, + operations, http_proxy, operation_logs, ) @@ -721,7 +721,7 @@ async fn process_smartrest( match message_id { "528" => forward_software_request(payload, http_proxy).await, "510" => forward_restart_request(payload), - template => forward_operation_request(payload, template, &operations, operation_logs).await, + template => forward_operation_request(payload, template, operations, operation_logs).await, } } diff --git a/crates/core/tedge_mapper/src/c8y/dynamic_discovery.rs b/crates/core/tedge_mapper/src/c8y/dynamic_discovery.rs index fca9057d..4eff35c4 100644 --- a/crates/core/tedge_mapper/src/c8y/dynamic_discovery.rs +++ b/crates/core/tedge_mapper/src/c8y/dynamic_discovery.rs @@ -5,8 +5,8 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] pub enum EventType { - ADD, - REMOVE, + Add, + Remove, } #[derive(Serialize, Deserialize, Debug)] @@ -54,23 +54,21 @@ pub fn process_inotify_events( if let Some(ops_name) = event.clone().name { let operation_name = ops_name .to_str() - .ok_or(DynamicDiscoverOpsError::NotAnOperationName( - ops_name.clone(), - )); + .ok_or_else(|| DynamicDiscoverOpsError::NotAnOperationName(ops_name.clone())); match operation_name { Ok(ops_name) => match event.mask { EventMask::DELETE => { return Ok(Some(DiscoverOp { ops_dir, - event_type: EventType::REMOVE, + event_type: EventType::Remove, operation_name: ops_name.to_string(), })) } EventMask::CLOSE_WRITE => { return Ok(Some(DiscoverOp { ops_dir, - event_type: EventType::ADD, + event_type: EventType::Add, operation_name: ops_name.to_string(), })) } diff --git a/crates/core/tedge_mapper/src/c8y/error.rs b/crates/core/tedge_mapper/src/c8y/error.rs index e388084d..60b9bea1 100644 --- a/crates/core/tedge_mapper/src/c8y/error.rs +++ b/crates/core/tedge_mapper/src/c8y/error.rs @@ -4,6 +4,7 @@ use c8y_smartrest::error::{ use plugin_sm::operation_logs::OperationLogsError; #[derive(thiserror::Error, Debug)] +#[allow(clippy::large_enum_variant)] #[allow(clippy::enum_variant_names)] pub enum CumulocityMapperError { #[error(transparent)] diff --git a/crates/core/tedge_mapper/src/c8y/mapper.rs b/crates/core/tedge_mapper/src/c8y/mapper.rs index 8ea3b4fc..81068adb 100644 --- a/crates/core/tedge_mapper/src/c8y/mapper.rs +++ b/crates/core/tedge_mapper/src/c8y/mapper.rs @@ -110,12 +110,14 @@ fn create_directories(config_dir: &str) -> Result<(), anyhow::Error> { "tedge", "tedge", 0o644, + None, )?; create_file_with_user_group( &format!("{config_dir}/operations/c8y/c8y_Restart"), "tedge", "tedge", 0o644, + None, )?; Ok(()) } diff --git a/crates/core/tedge_mapper/src/core/error.rs b/crates/core/tedge_mapper/src/core/error.rs index 4280c738..b703161a 100644 --- a/crates/core/tedge_mapper/src/core/error.rs +++ b/crates/core/tedge_mapper/src/core/error.rs @@ -5,6 +5,9 @@ use mqtt_channel::MqttError; use tedge_config::TEdgeConfigError; use thin_edge_json::serialize::ThinEdgeJsonSerializationError; +// allowing enum_variant_names due to a False positive where it is +// detected that "all variants have the same prefix: `From`" +#[allow(clippy::enum_variant_names)] #[derive(Debug, thiserror::Error)] pub enum MapperError { #[error(transparent)] diff --git a/crates/core/tedge_mapper/src/core/mapper.rs b/crates/core/tedge_mapper/src/core/mapper.rs index d4f0da23..a16a042d 100644 --- a/crates/core/tedge_mapper/src/core/mapper.rs +++ b/crates/core/tedge_mapper/src/core/mapper.rs @@ -171,25 +171,20 @@ async fn process_inotify_and_mqtt_messages( } } } - event = inotify_events.next() => { - match event { - Some(ev) => { - match ev { - Ok(ev_string) => { - - match process_inotify_events(dir.clone(), ev_string) { - Ok(Some(discovered_ops)) => { - let _ = mapper.output.send(mapper.converter.process_operation_update_message(discovered_ops)).await; - } - Ok(None) => {} - Err(e) => {eprintln!("Processing inotify event failed due to {}", e);} - } - - - } Err(e) => {eprintln!("Failed to extract event {}", e);} + Some(event_or_error) = inotify_events.next() => { + match event_or_error { + Ok(event) => { + match process_inotify_events(dir.clone(), event) { + Ok(Some(discovered_ops)) => { + let _ = mapper.output.send(mapper.converter.process_operation_update_message(discovered_ops)).await; + } + Ok(None) => {} + Err(e) => {eprintln!("Processing inotify event failed due to {}", e);} } } - None => {} + Err(error) => { + eprintln!("Failed to extract event {}", error); + } } } } diff --git a/crates/core/tedge_mapper/src/main.rs b/crates/core/tedge_mapper/src/main.rs index 4b4a9f47..eabc82a7 100644 --- a/crates/core/tedge_mapper/src/main.rs +++ b/crates/core/tedge_mapper/src/main.rs @@ -84,10 +84,9 @@ async fn main() -> anyhow::Result<()> { tedge_config::TEdgeConfigLocation::from_custom_root(&mapper_opt.config_dir); let config = tedge_config::TEdgeConfigRepository::new(tedge_config_location.clone()).load()?; // Run only one instance of a mapper - let _flock = check_another_instance_is_not_running( - &mapper_opt.name.to_string(), - &config.query(RunPathSetting)?.into(), - )?; + + let run_dir: PathBuf = config.query(RunPathSetting)?.into(); + let _flock = check_another_instance_is_not_running(&mapper_opt.name.to_string(), &run_dir)?; if mapper_opt.init { component.init(&mapper_opt.config_dir).await |