Skip to main content

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};
10use ::Vine::Generated::{GetConfigurationRequest, GetConfigurationResponse};
11
12use crate::{RPC::CocoonService::CocoonServiceImpl, dev_log};
13
14pub async fn Fn(
15	Service:&CocoonServiceImpl,
16
17	Request:GetConfigurationRequest,
18) -> Result<Response<GetConfigurationResponse>, Status> {
19	let Key = if Request.section.is_empty() {
20		if Request.key.is_empty() { None } else { Some(Request.key.clone()) }
21	} else if Request.key.is_empty() {
22		Some(Request.section.clone())
23	} else {
24		Some(format!("{}.{}", Request.section, Request.key))
25	};
26
27	dev_log!("cocoon", "[CocoonService] get_configuration: key={:?}", Key);
28
29	match Service
30		.environment
31		.GetConfigurationValue(Key, ConfigurationOverridesDTO::default())
32		.await
33	{
34		Ok(Value) => {
35			let Bytes = serde_json::to_vec(&Value).unwrap_or_default();
36
37			Ok(Response::new(GetConfigurationResponse { value:Bytes }))
38		},
39
40		Err(Error) => {
41			dev_log!("cocoon", "warn: [CocoonService] get_configuration failed: {}", Error);
42
43			Ok(Response::new(GetConfigurationResponse::default()))
44		},
45	}
46}