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
21		Ok(None) => Ok(Response::new(GetSecretResponse { value:String::new() })),
22
23		Err(Error) => {
24			dev_log!(
25				"cocoon",
26				"warn: [CocoonService] get_secret failed key={}: {}",
27				Request.key,
28				Error
29			);
30
31			Err(Status::internal(format!("get_secret: {}", Error)))
32		},
33	}
34}