Skip to main content

Mountain/IPC/WindServiceAdapters/
WindConfigurationService.rs

1
2//! Wind-shaped configuration service - read / write of
3//! configuration values via the injected
4//! `ConfigurationProvider` trait. Defaults to user-target
5//! writes; `ConfigurationOverridesDTO::default()` resolves to
6//! the active scope.
7
8use std::sync::Arc;
9
10use CommonLibrary::Configuration::{
11	ConfigurationProvider::ConfigurationProvider,
12	DTO::{ConfigurationOverridesDTO::ConfigurationOverridesDTO, ConfigurationTarget::ConfigurationTarget},
13};
14
15pub struct Struct {
16	pub(super) provider:Arc<dyn ConfigurationProvider>,
17}
18
19impl Struct {
20	pub fn new(provider:Arc<dyn ConfigurationProvider>) -> Self { Self { provider } }
21
22	pub async fn get_value(&self, key:String) -> Result<serde_json::Value, String> {
23		self.provider
24			.GetConfigurationValue(Some(key.to_string()), ConfigurationOverridesDTO::default())
25			.await
26			.map_err(|e| e.to_string())
27	}
28
29	pub async fn update_value(&self, key:String, value:serde_json::Value) -> Result<(), String> {
30		self.provider
31			.UpdateConfigurationValue(
32				key,
33				value,
34				ConfigurationTarget::User,
35				ConfigurationOverridesDTO::default(),
36				None,
37			)
38			.await
39			.map_err(|e| e.to_string())
40	}
41}