Skip to content

Commit

Permalink
Merge pull request thin-edge#2238 from Ruadhri17/config-plugin-ref
Browse files Browse the repository at this point in the history
Create generic tedge configuration plugin
  • Loading branch information
Ruadhri17 authored Sep 25, 2023
2 parents be351da + f75f5c2 commit 3ba5851
Show file tree
Hide file tree
Showing 12 changed files with 1,601 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"plugins/c8y_log_plugin",
"plugins/c8y_remote_access_plugin",
"plugins/tedge_apt_plugin",
"plugins/tedge_configuration_plugin",
"plugins/tedge_dummy_plugin",
"plugins/tedge_log_plugin",
]
Expand Down Expand Up @@ -129,6 +130,7 @@ tedge_api = { path = "crates/core/tedge_api" }
tedge_config = { path = "crates/common/tedge_config" }
tedge_config_macros = { path = "crates/common/tedge_config_macros" }
tedge_config_macros-impl = { path = "crates/common/tedge_config_macros/impl" }
tedge_config_manager = { path = "crates/extensions/tedge_config_manager" }
tedge_downloader_ext = { path = "crates/extensions/tedge_downloader_ext" }
tedge_file_system_ext = { path = "crates/extensions/tedge_file_system_ext" }
tedge_health_ext = { path = "crates/extensions/tedge_health_ext" }
Expand Down
67 changes: 67 additions & 0 deletions crates/core/tedge_api/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,73 @@ impl LogUploadCmdPayload {
}
}

#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ConfigSnapshotCmdPayload {
pub status: CommandStatus,
pub tedge_url: String,
#[serde(rename = "type")]
pub config_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
}

impl<'a> Jsonify<'a> for ConfigSnapshotCmdPayload {}

impl ConfigSnapshotCmdPayload {
pub fn executing(&mut self) {
self.status = CommandStatus::Executing;
self.reason = None;
}

pub fn successful(&mut self, path: impl Into<String>) {
self.status = CommandStatus::Successful;
self.reason = None;
self.path = Some(path.into())
}

pub fn failed(&mut self, reason: impl Into<String>) {
self.status = CommandStatus::Failed;
self.reason = Some(reason.into());
}
}

#[derive(Debug, Deserialize, Serialize, Eq, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ConfigUpdateCmdPayload {
pub status: CommandStatus,
pub tedge_url: String,
pub remote_url: String,
#[serde(rename = "type")]
pub config_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
}

impl<'a> Jsonify<'a> for ConfigUpdateCmdPayload {}

impl ConfigUpdateCmdPayload {
pub fn executing(&mut self) {
self.status = CommandStatus::Executing;
self.reason = None;
}

pub fn successful(&mut self, path: impl Into<String>) {
self.status = CommandStatus::Successful;
self.reason = None;
self.path = Some(path.into())
}

pub fn failed(&mut self, reason: impl Into<String>) {
self.status = CommandStatus::Failed;
self.reason = Some(reason.into());
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 6 additions & 0 deletions crates/core/tedge_api/src/mqtt_topics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ pub enum OperationType {
SoftwareList,
SoftwareUpdate,
LogUpload,
ConfigSnapshot,
ConfigUpdate,
Custom(String),
}

Expand All @@ -436,6 +438,8 @@ impl FromStr for OperationType {
"software_list" => Ok(OperationType::SoftwareList),
"software_update" => Ok(OperationType::SoftwareUpdate),
"log_upload" => Ok(OperationType::LogUpload),
"config_snapshot" => Ok(OperationType::ConfigSnapshot),
"config_update" => Ok(OperationType::ConfigUpdate),
operation => Ok(OperationType::Custom(operation.to_string())),
}
}
Expand All @@ -448,6 +452,8 @@ impl Display for OperationType {
OperationType::SoftwareList => write!(f, "software_list"),
OperationType::SoftwareUpdate => write!(f, "software_update"),
OperationType::LogUpload => write!(f, "log_upload"),
OperationType::ConfigSnapshot => write!(f, "config_snapshot"),
OperationType::ConfigUpdate => write!(f, "config_update"),
OperationType::Custom(operation) => write!(f, "{operation}"),
}
}
Expand Down
34 changes: 34 additions & 0 deletions crates/extensions/tedge_config_manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "tedge_config_manager"
description = "thin-edge extension adding support for configuration management"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
license = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }

[dependencies]
async-trait = { workspace = true }
http = { workspace = true }
log = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tedge_actors = { workspace = true }
tedge_api = { workspace = true }
tedge_config = { workspace = true }
tedge_downloader_ext = { workspace = true }
tedge_file_system_ext = { workspace = true }
tedge_http_ext = { workspace = true }
tedge_mqtt_ext = { workspace = true }
tedge_utils = { workspace = true }
thiserror = { workspace = true }
toml = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
tedge_actors = { workspace = true, features = ["test-helpers"] }
tedge_http_ext = { workspace = true, features = ["test_helpers"] }
tedge_test_utils = { workspace = true }
tokio = { workspace = true, features = ["macros"] }
Loading

0 comments on commit 3ba5851

Please sign in to comment.