summaryrefslogtreecommitdiffstats
path: root/tedge_config
diff options
context:
space:
mode:
authorAlbin Suresh <albin.suresh@softwareag.com>2021-08-19 18:48:10 +0530
committerGitHub <noreply@github.com>2021-08-19 18:48:10 +0530
commitd782a7354c7ed7bc6ddb703d95b83c212a6d85d3 (patch)
treeaa9d0c9274c6f6e8e244423faf7b4b9b4f078835 /tedge_config
parentb0f61f611b02a701293c19b86c4158d781ffdf16 (diff)
[CIT-502] Default software plugin support (#386)
* [CIT-502] Default software plugin support
Diffstat (limited to 'tedge_config')
-rw-r--r--tedge_config/src/settings.rs14
-rw-r--r--tedge_config/src/tedge_config.rs26
-rw-r--r--tedge_config/src/tedge_config_dto.rs9
-rw-r--r--tedge_config/src/tedge_config_repository.rs5
4 files changed, 54 insertions, 0 deletions
diff --git a/tedge_config/src/settings.rs b/tedge_config/src/settings.rs
index cff9541e..438cead8 100644
--- a/tedge_config/src/settings.rs
+++ b/tedge_config/src/settings.rs
@@ -158,3 +158,17 @@ impl ConfigSetting for MqttPortSetting {
type Value = Port;
}
+
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+pub struct SoftwarePluginDefaultSetting;
+
+impl ConfigSetting for SoftwarePluginDefaultSetting {
+ const KEY: &'static str = "software.plugin.default";
+
+ const DESCRIPTION: &'static str = concat!(
+ "The default software plugin to be used for software management on the device",
+ "Example: apt"
+ );
+
+ type Value = String;
+}
diff --git a/tedge_config/src/tedge_config.rs b/tedge_config/src/tedge_config.rs
index ef1766dd..cbfacaa6 100644
--- a/tedge_config/src/tedge_config.rs
+++ b/tedge_config/src/tedge_config.rs
@@ -244,6 +244,32 @@ impl ConfigSettingAccessor<MqttPortSetting> for TEdgeConfig {
}
}
+impl ConfigSettingAccessor<SoftwarePluginDefaultSetting> for TEdgeConfig {
+ fn query(&self, _setting: SoftwarePluginDefaultSetting) -> ConfigSettingResult<String> {
+ self.data
+ .software
+ .default_plugin_type
+ .clone()
+ .ok_or(ConfigSettingError::ConfigNotSet {
+ key: SoftwarePluginDefaultSetting::KEY,
+ })
+ }
+
+ fn update(
+ &mut self,
+ _setting: SoftwarePluginDefaultSetting,
+ value: String,
+ ) -> ConfigSettingResult<()> {
+ self.data.software.default_plugin_type = Some(value);
+ Ok(())
+ }
+
+ fn unset(&mut self, _setting: SoftwarePluginDefaultSetting) -> ConfigSettingResult<()> {
+ self.data.software.default_plugin_type = None;
+ Ok(())
+ }
+}
+
/// Generic extension trait implementation for all `ConfigSetting`s of `TEdgeConfig`
/// that provide `TryFrom`/`TryInto` implementations for `String`.
impl<T, E, F> ConfigSettingAccessorStringExt<T> for TEdgeConfig
diff --git a/tedge_config/src/tedge_config_dto.rs b/tedge_config/src/tedge_config_dto.rs
index 2e9579ec..faabd8d4 100644
--- a/tedge_config/src/tedge_config_dto.rs
+++ b/tedge_config/src/tedge_config_dto.rs
@@ -19,6 +19,9 @@ pub(crate) struct TEdgeConfigDto {
#[serde(default)]
pub(crate) mqtt: MqttConfigDto,
+
+ #[serde(default)]
+ pub(crate) software: SoftwareConfigDto,
}
/// Represents the device specific configurations defined in the [device] section
@@ -73,3 +76,9 @@ pub(crate) struct AzureConfigDto {
pub(crate) struct MqttConfigDto {
pub(crate) port: Option<u16>,
}
+
+#[derive(Debug, Default, Deserialize, Serialize)]
+#[serde(deny_unknown_fields)]
+pub(crate) struct SoftwareConfigDto {
+ pub(crate) default_plugin_type: Option<String>,
+}
diff --git a/tedge_config/src/tedge_config_repository.rs b/tedge_config/src/tedge_config_repository.rs
index 790efb29..433d3013 100644
--- a/tedge_config/src/tedge_config_repository.rs
+++ b/tedge_config/src/tedge_config_repository.rs
@@ -5,6 +5,7 @@ use tedge_utils::fs::atomically_write_file_sync;
/// TEdgeConfigRepository is resposible for loading and storing TEdgeConfig entities.
///
+#[derive(Debug)]
pub struct TEdgeConfigRepository {
config_location: TEdgeConfigLocation,
config_defaults: TEdgeConfigDefaults,
@@ -59,6 +60,10 @@ impl TEdgeConfigRepository {
}
}
+ pub fn get_config_location(&self) -> &TEdgeConfigLocation {
+ &self.config_location
+ }
+
/// Parse the configuration file at the provided `path` and create a `TEdgeConfig` out of it
///
/// #Arguments