Skip to main content

Mountain/RPC/CocoonService/Secret/
GetSecret.rs

1#![allow(non_snake_case)]
2
3//! Read a value from the OS keychain. The gRPC proto carries only `key`;
4//! the app name is used as the keyring service scope.
5
6use tonic::{Response, Status};
7use CommonLibrary::Secret::SecretProvider::SecretProvider;
8
9use crate::{
10	RPC::CocoonService::CocoonServiceImpl,
11	Vine::Generated::{GetSecretRequest, GetSecretResponse},
12	dev_log,
13};
14
15pub async fn Fn(Service:&CocoonServiceImpl, Request:GetSecretRequest) -> Result<Response<GetSecretResponse>, Status> {
16	dev_log!("cocoon", "[CocoonService] get_secret: key={}", Request.key);
17
18	match Service.environment.GetSecret(String::new(), Request.key.clone()).await {
19		Ok(Some(Value)) => Ok(Response::new(GetSecretResponse { value:Value })),
20		Ok(None) => Ok(Response::new(GetSecretResponse { value:String::new() })),
21		Err(Error) => {
22			dev_log!(
23				"cocoon",
24				"warn: [CocoonService] get_secret failed key={}: {}",
25				Request.key,
26				Error
27			);
28			Err(Status::internal(format!("get_secret: {}", Error)))
29		},
30	}
31}