Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Extension/
GetConfiguration.rs

1//! Look up a workspace configuration value for the requesting extension.
2//! Composes `section.key` when both are present, otherwise falls back to
3//! whichever side is non-empty.
4
5use tonic::{Response, Status};
6use CommonLibrary::Configuration::{
7	ConfigurationProvider::ConfigurationProvider,
8	DTO::ConfigurationOverridesDTO::ConfigurationOverridesDTO,
9};
10
11use crate::{
12	RPC::CocoonService::CocoonServiceImpl,
13	Vine::Generated::{GetConfigurationRequest, GetConfigurationResponse},
14	dev_log,
15};
16
17pub async fn Fn(
18	Service:&CocoonServiceImpl,
19
20	Request:GetConfigurationRequest,
21) -> Result<Response<GetConfigurationResponse>, Status> {
22	let Key = if Request.section.is_empty() {
23		if Request.key.is_empty() { None } else { Some(Request.key.clone()) }
24	} else if Request.key.is_empty() {
25		Some(Request.section.clone())
26	} else {
27		Some(format!("{}.{}", Request.section, Request.key))
28	};
29
30	dev_log!("cocoon", "[CocoonService] get_configuration: key={:?}", Key);
31
32	match Service
33		.environment
34		.GetConfigurationValue(Key, ConfigurationOverridesDTO::default())
35		.await
36	{
37		Ok(Value) => {
38			let Bytes = serde_json::to_vec(&Value).unwrap_or_default();
39
40			Ok(Response::new(GetConfigurationResponse { value:Bytes }))
41		},
42
43		Err(Error) => {
44			dev_log!("cocoon", "warn: [CocoonService] get_configuration failed: {}", Error);
45
46			Ok(Response::new(GetConfigurationResponse::default()))
47		},
48	}
49}