Skip to main content

Mountain/RPC/CocoonService/Secret/
GetSecret.rs

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