Skip to main content

Mountain/RPC/CocoonService/Extension/
GetConfiguration.rs

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