Skip to main content

Mountain/IPC/WindServiceAdapters/
WindConfigurationService.rs

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