Skip to content

Commit

Permalink
fixup! Add tedge config manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruadhri17 committed Sep 19, 2023
1 parent bd1b9cd commit 919be7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
25 changes: 13 additions & 12 deletions crates/extensions/tedge_config_manager/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fan_in_message_type!(ConfigOutput[MqttMessage, ConfigDownloadRequest]: Debug);

pub struct ConfigManagerActor {
config: ConfigManagerConfig,
plugin_config: PluginConfig,
pending_downloads: HashMap<String, ConfigUpdateCmdPayload>,
mqtt_publisher: LoggingSender<MqttMessage>,
messages: SimpleMessageBox<ConfigInput, NoMessage>,
Expand Down Expand Up @@ -82,13 +83,15 @@ impl Actor for ConfigManagerActor {
impl ConfigManagerActor {
pub fn new(
config: ConfigManagerConfig,
plugin_config: PluginConfig,
mqtt_publisher: LoggingSender<MqttMessage>,
messages: SimpleMessageBox<ConfigInput, NoMessage>,
http_proxy: ClientMessageBox<HttpRequest, HttpResult>,
download_sender: DynSender<ConfigDownloadRequest>,
) -> Self {
ConfigManagerActor {
config,
plugin_config,
pending_downloads: HashMap::new(),
mqtt_publisher,
messages,
Expand Down Expand Up @@ -191,8 +194,9 @@ impl ConfigManagerActor {
&mut self,
request: &ConfigSnapshotCmdPayload,
) -> Result<String, ConfigManagementError> {
let plugin_config = PluginConfig::new(&self.config.plugin_config_path);
let file_entry = plugin_config.get_file_entry_from_type(&request.config_type)?;
let file_entry = self
.plugin_config
.get_file_entry_from_type(&request.config_type)?;

let config_content = std::fs::read_to_string(&file_entry.path)?;

Expand Down Expand Up @@ -256,8 +260,9 @@ impl ConfigManagerActor {
topic: &Topic,
request: &ConfigUpdateCmdPayload,
) -> Result<(), ConfigManagementError> {
let plugin_config = PluginConfig::new(&self.config.plugin_config_path);
let file_entry = plugin_config.get_file_entry_from_type(&request.config_type)?;
let file_entry = self
.plugin_config
.get_file_entry_from_type(&request.config_type)?;

let download_request =
DownloadRequest::new(&request.tedge_url, Path::new(&file_entry.path))
Expand Down Expand Up @@ -330,17 +335,13 @@ impl ConfigManagerActor {
}

async fn reload_supported_config_types(&mut self) -> Result<(), ChannelError> {
let plugin_config: PluginConfig =
PluginConfig::new(self.config.plugin_config_path.as_path());
self.publish_supported_config_types(&plugin_config).await
self.plugin_config = PluginConfig::new(self.config.plugin_config_path.as_path());
self.publish_supported_config_types().await
}

/// updates the config types
async fn publish_supported_config_types(
&mut self,
plugin_config: &PluginConfig,
) -> Result<(), ChannelError> {
let mut config_types = plugin_config.get_all_file_types();
async fn publish_supported_config_types(&mut self) -> Result<(), ChannelError> {
let mut config_types = self.plugin_config.get_all_file_types();
config_types.sort();
let payload = json!({ "types": config_types }).to_string();
for topic in self.config.config_reload_topics.patterns.iter() {
Expand Down
5 changes: 5 additions & 0 deletions crates/extensions/tedge_config_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use tedge_utils::file::FileError;
/// This is an actor builder.
pub struct ConfigManagerBuilder {
config: ConfigManagerConfig,
plugin_config: PluginConfig,
box_builder: SimpleMessageBoxBuilder<ConfigInput, NoMessage>,
mqtt_publisher: DynSender<MqttMessage>,
http_proxy: ClientMessageBox<HttpRequest, HttpResult>,
Expand All @@ -57,6 +58,8 @@ impl ConfigManagerBuilder {
) -> Result<Self, FileError> {
Self::init(&config)?;

let plugin_config = PluginConfig::new(config.plugin_config_path.as_path());

let box_builder = SimpleMessageBoxBuilder::new("Config Manager", 16);

let mqtt_publisher = mqtt.connect_consumer(
Expand All @@ -76,6 +79,7 @@ impl ConfigManagerBuilder {

Ok(ConfigManagerBuilder {
config,
plugin_config,
box_builder,
mqtt_publisher,
http_proxy,
Expand Down Expand Up @@ -129,6 +133,7 @@ impl Builder<ConfigManagerActor> for ConfigManagerBuilder {

Ok(ConfigManagerActor::new(
self.config,
self.plugin_config,
mqtt_publisher,
message_box,
self.http_proxy,
Expand Down

0 comments on commit 919be7e

Please sign in to comment.