summaryrefslogtreecommitdiffstats
path: root/crates/common/tedge_config/src
diff options
context:
space:
mode:
authorinitard <solo@softwareag.com>2022-02-25 13:13:46 +0000
committerinitard <solo@softwareag.com>2022-03-04 10:48:34 +0000
commit1139e7bd1f5774fe426b880fb57cf7938225bacf (patch)
tree2575c603c8a8f959be975510e10b33c9f114178a /crates/common/tedge_config/src
parent15e59352f97fc79be3544155a7089f16c26a8656 (diff)
configurable run path (#858)
- added logs.path to `tedge` command - can now use `tedge config set run.path /some/run/path` - agent and mapper use the run config Signed-off-by: initard <solo@softwareag.com>
Diffstat (limited to 'crates/common/tedge_config/src')
-rw-r--r--crates/common/tedge_config/src/models/file_path.rs6
-rw-r--r--crates/common/tedge_config/src/settings.rs13
-rw-r--r--crates/common/tedge_config/src/tedge_config.rs25
-rw-r--r--crates/common/tedge_config/src/tedge_config_defaults.rs6
-rw-r--r--crates/common/tedge_config/src/tedge_config_dto.rs3
5 files changed, 53 insertions, 0 deletions
diff --git a/crates/common/tedge_config/src/models/file_path.rs b/crates/common/tedge_config/src/models/file_path.rs
index 29f8a415..62ef5723 100644
--- a/crates/common/tedge_config/src/models/file_path.rs
+++ b/crates/common/tedge_config/src/models/file_path.rs
@@ -44,3 +44,9 @@ impl std::fmt::Display for FilePath {
write!(f, "{}", self.0.display())
}
}
+
+impl Into<PathBuf> for FilePath {
+ fn into(self) -> PathBuf {
+ PathBuf::from(self.0)
+ }
+}
diff --git a/crates/common/tedge_config/src/settings.rs b/crates/common/tedge_config/src/settings.rs
index c2a12956..42a3f0f3 100644
--- a/crates/common/tedge_config/src/settings.rs
+++ b/crates/common/tedge_config/src/settings.rs
@@ -311,3 +311,16 @@ impl ConfigSetting for LogPathDefaultSetting {
type Value = FilePath;
}
+
+pub struct RunPathDefaultSetting;
+
+impl ConfigSetting for RunPathDefaultSetting {
+ const KEY: &'static str = "run.path";
+
+ const DESCRIPTION: &'static str = concat!(
+ "The default path to be used for runtime information",
+ "Example: /run"
+ );
+
+ type Value = FilePath;
+}
diff --git a/crates/common/tedge_config/src/tedge_config.rs b/crates/common/tedge_config/src/tedge_config.rs
index f79e3875..f3567d28 100644
--- a/crates/common/tedge_config/src/tedge_config.rs
+++ b/crates/common/tedge_config/src/tedge_config.rs
@@ -558,3 +558,28 @@ impl ConfigSettingAccessor<LogPathDefaultSetting> for TEdgeConfig {
Ok(())
}
}
+
+impl ConfigSettingAccessor<RunPathDefaultSetting> for TEdgeConfig {
+ fn query(&self, _setting: RunPathDefaultSetting) -> ConfigSettingResult<FilePath> {
+ Ok(self
+ .data
+ .run
+ .dir_path
+ .clone()
+ .unwrap_or_else(|| self.config_defaults.default_logs_path.clone()))
+ }
+
+ fn update(
+ &mut self,
+ _setting: RunPathDefaultSetting,
+ value: FilePath,
+ ) -> ConfigSettingResult<()> {
+ self.data.run.dir_path = Some(value);
+ Ok(())
+ }
+
+ fn unset(&mut self, _setting: RunPathDefaultSetting) -> ConfigSettingResult<()> {
+ self.data.run.dir_path = None;
+ Ok(())
+ }
+}
diff --git a/crates/common/tedge_config/src/tedge_config_defaults.rs b/crates/common/tedge_config/src/tedge_config_defaults.rs
index d950fe5e..b035445c 100644
--- a/crates/common/tedge_config/src/tedge_config_defaults.rs
+++ b/crates/common/tedge_config/src/tedge_config_defaults.rs
@@ -49,6 +49,9 @@ pub struct TEdgeConfigDefaults {
/// Default log path
pub default_logs_path: FilePath,
+ /// Default run path
+ pub default_run_path: FilePath,
+
/// Default device type
pub default_device_type: String,
@@ -61,6 +64,7 @@ impl From<&TEdgeConfigLocation> for TEdgeConfigDefaults {
let system_cert_path = Path::new(DEFAULT_ETC_PATH).join("ssl").join("certs");
let tmp_path = Path::new(DEFAULT_TMP_PATH);
let logs_path = Path::new(DEFAULT_LOG_PATH);
+ let run_path = Path::new(DEFAULT_RUN_PATH);
Self {
default_device_cert_path: config_location
.tedge_config_root_path()
@@ -78,6 +82,7 @@ impl From<&TEdgeConfigLocation> for TEdgeConfigDefaults {
default_mqtt_port: Port(DEFAULT_PORT),
default_tmp_path: tmp_path.into(),
default_logs_path: logs_path.into(),
+ default_run_path: run_path.into(),
default_device_type: DEFAULT_DEVICE_TYPE.into(),
default_mqtt_bind_address: IpAddress::default(),
}
@@ -104,6 +109,7 @@ fn test_from_tedge_config_location() {
default_mqtt_port: Port(DEFAULT_PORT),
default_tmp_path: FilePath::from("/tmp"),
default_logs_path: FilePath::from("/var/log"),
+ default_run_path: FilePath::from("/run"),
default_device_type: DEFAULT_DEVICE_TYPE.into(),
default_mqtt_bind_address: IpAddress::default(),
}
diff --git a/crates/common/tedge_config/src/tedge_config_dto.rs b/crates/common/tedge_config/src/tedge_config_dto.rs
index 1bb1fb20..28cbfcbd 100644
--- a/crates/common/tedge_config/src/tedge_config_dto.rs
+++ b/crates/common/tedge_config/src/tedge_config_dto.rs
@@ -28,6 +28,9 @@ pub(crate) struct TEdgeConfigDto {
#[serde(default)]
pub(crate) logs: PathConfigDto,
+
+ #[serde(default)]
+ pub(crate) run: PathConfigDto,
}
/// Represents the device specific configurations defined in the [device] section