Mountain/RPC/CocoonService/Extension/
GetConfiguration.rs1#![allow(non_snake_case)]
2
3use 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 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 Ok(Response::new(GetConfigurationResponse { value:Bytes }))
41 },
42 Err(Error) => {
43 dev_log!("cocoon", "warn: [CocoonService] get_configuration failed: {}", Error);
44 Ok(Response::new(GetConfigurationResponse::default()))
45 },
46 }
47}