Skip to content

Commit

Permalink
fixup! Add tedge config plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruadhri17 committed Sep 18, 2023
1 parent 5e9bcc4 commit 23f5b38
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions plugins/tedge_configuration_plugin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use tedge_actors::Runtime;
use tedge_config::system_services::get_log_level;
use tedge_config::system_services::set_log_level;
Expand All @@ -10,6 +10,7 @@ use tedge_config::TEdgeConfigRepository;
use tedge_config::DEFAULT_TEDGE_CONFIG_PATH;
use tedge_config_manager::ConfigManagerBuilder;
use tedge_config_manager::ConfigManagerConfig;
use tedge_config_manager::ConfigManagerOptions;
use tedge_downloader_ext::DownloaderActor;
use tedge_file_system_ext::FsWatchActorBuilder;
use tedge_health_ext::HealthMonitorBuilder;
Expand Down Expand Up @@ -48,11 +49,11 @@ pub struct ConfigPluginOpt {
#[clap(long = "config-dir", default_value = DEFAULT_TEDGE_CONFIG_PATH)]
pub config_dir: PathBuf,

#[clap(long, default_value = "te")]
root: String,
#[clap(long)]
mqtt_topic_root: Option<Arc<str>>,

#[clap(long, default_value = "device/main//")]
device: String,
#[clap(long)]
mqtt_device_topic_id: Option<Arc<str>>,
}

#[tokio::main]
Expand All @@ -74,28 +75,24 @@ async fn main() -> Result<(), anyhow::Error> {

let tedge_config = TEdgeConfigRepository::new(tedge_config_location).load()?;

run(
config_opt.config_dir,
tedge_config,
config_opt.root,
config_opt.device,
)
.await
run(tedge_config, config_opt).await
}

async fn run(
config_dir: impl AsRef<Path>,
tedge_config: TEdgeConfig,
topic_root: String,
topic_identifier: String,
) -> Result<(), anyhow::Error> {
async fn run(tedge_config: TEdgeConfig, cliopts: ConfigPluginOpt) -> Result<(), anyhow::Error> {
let runtime_events_logger = None;
let mut runtime = Runtime::try_new(runtime_events_logger).await?;

let mqtt_topic_root = cliopts
.mqtt_topic_root
.unwrap_or(tedge_config.mqtt.topic_root.clone().into());

let mqtt_device_topic_id = cliopts
.mqtt_device_topic_id
.unwrap_or(tedge_config.mqtt.device_topic_id.clone().into());

let mqtt_config = tedge_config.mqtt_config()?;
let mut mqtt_actor = MqttActorBuilder::new(mqtt_config.clone().with_session_name(format!(
"{}#{}/{}",
TEDGE_CONFIGURATION_PLUGIN, topic_root, topic_identifier
"{TEDGE_CONFIGURATION_PLUGIN}#{mqtt_topic_root}/{mqtt_device_topic_id}",
)));

let mut fs_watch_actor = FsWatchActorBuilder::new();
Expand All @@ -107,12 +104,12 @@ async fn run(
let mut downloader_actor = DownloaderActor::new().builder();

// Instantiate config manager actor
let manager_config = ConfigManagerConfig::from_tedge_config(
config_dir,
&tedge_config,
topic_root,
topic_identifier,
)?;
let manager_config = ConfigManagerConfig::from_options(ConfigManagerOptions {
config_dir: cliopts.config_dir,
mqtt_device_topic_id,
mqtt_topic_root,
})?;

let config_actor = ConfigManagerBuilder::try_new(
manager_config,
&mut mqtt_actor,
Expand Down

0 comments on commit 23f5b38

Please sign in to comment.