Skip to main content

Mountain/RPC/CocoonService/Extension/
GetConfiguration.rs

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