Mountain/Environment/ConfigurationProvider/
InspectValue.rs1use CommonLibrary::{
4 Configuration::DTO::{
5 ConfigurationOverridesDTO::ConfigurationOverridesDTO,
6 InspectResultDataDTO::InspectResultDataDTO,
7 },
8 Error::CommonError::CommonError,
9};
10use log::info;
11use serde_json::Value;
12use tauri::Manager;
13
14use crate::Environment::Utility;
15
16pub(super) async fn inspect_configuration_value(
18 environment:&crate::Environment::MountainEnvironment::MountainEnvironment,
19 key:String,
20 _overrides:ConfigurationOverridesDTO,
21) -> Result<Option<InspectResultDataDTO>, CommonError> {
22 info!("[ConfigurationProvider] Inspecting key: {}", key);
23
24 let user_settings_path = environment
25 .ApplicationHandle
26 .path()
27 .app_config_dir()
28 .map(|p| p.join("settings.json"))
29 .ok();
30
31 let workspace_settings_path = environment
32 .ApplicationState
33 .Workspace
34 .WorkspaceConfigurationPath
35 .lock()
36 .map_err(Utility::MapApplicationStateLockErrorToCommonError)?
37 .clone();
38
39 let default_config = super::Loading::collect_default_configurations(&environment.ApplicationState)?;
41
42 let user_config = super::Loading::read_and_parse_configuration_file(environment, &user_settings_path).await?;
43
44 let workspace_config =
45 super::Loading::read_and_parse_configuration_file(environment, &workspace_settings_path).await?;
46
47 let get_value_from_dot_path =
48 |node:&Value, path:&str| -> Option<Value> { path.split('.').try_fold(node, |n, k| n.get(k)).cloned() };
49
50 let mut result_dto = InspectResultDataDTO::default();
51
52 result_dto.DefaultValue = get_value_from_dot_path(&default_config, &key);
53
54 result_dto.UserValue = get_value_from_dot_path(&user_config, &key);
55
56 result_dto.WorkspaceValue = get_value_from_dot_path(&workspace_config, &key);
57
58 result_dto.EffectiveValue = result_dto
60 .WorkspaceValue
61 .clone()
62 .or_else(|| result_dto.UserValue.clone())
63 .or_else(|| result_dto.DefaultValue.clone());
64
65 if result_dto.EffectiveValue.is_some() {
66 Ok(Some(result_dto))
67 } else {
68 Ok(None)
69 }
70}