Skip to main content

Mountain/RPC/CocoonService/Secret/
GetSecret.rs

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