Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/GenericRequest/
Secrets.rs

1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! Generic-request secret-storage handlers for `process_mountain_request`.
4//! Handles `getSecret`, `storeSecret`, `deleteSecret` using Cocoon's
5//! `MountainGRPCClient` name conventions.
6
7use CommonLibrary::Secret::SecretProvider::SecretProvider;
8use serde_json::{Value, json};
9use tonic::Response;
10
11use crate::{Environment::MountainEnvironment::MountainEnvironment, Vine::Generated::GenericResponse};
12use super::FileSystem::{ErrResponse, OkResponse};
13
14pub async fn HandleGetSecret(RequestId:u64, Params:Value, Env:&MountainEnvironment) -> Response<GenericResponse> {
15	let ExtensionId = Params.get("extensionId").and_then(|V| V.as_str()).unwrap_or("").to_string();
16	let Key = Params.get("key").and_then(|V| V.as_str()).unwrap_or("").to_string();
17	match Env.GetSecret(ExtensionId, Key).await {
18		Ok(Some(V)) => OkResponse(RequestId, &json!({ "value": V })),
19		Ok(None) => OkResponse(RequestId, &Value::Null),
20		Err(Error) => ErrResponse(RequestId, -32000, Error.to_string()),
21	}
22}
23
24pub async fn HandleStoreSecret(RequestId:u64, Params:Value, Env:&MountainEnvironment) -> Response<GenericResponse> {
25	let ExtensionId = Params.get("extensionId").and_then(|V| V.as_str()).unwrap_or("").to_string();
26	let Key = Params.get("key").and_then(|V| V.as_str()).unwrap_or("").to_string();
27	let V = Params.get("value").and_then(|V| V.as_str()).unwrap_or("").to_string();
28	match Env.StoreSecret(ExtensionId, Key, V).await {
29		Ok(()) => OkResponse(RequestId, &json!({ "success": true })),
30		Err(Error) => ErrResponse(RequestId, -32000, Error.to_string()),
31	}
32}
33
34pub async fn HandleDeleteSecret(RequestId:u64, Params:Value, Env:&MountainEnvironment) -> Response<GenericResponse> {
35	let ExtensionId = Params.get("extensionId").and_then(|V| V.as_str()).unwrap_or("").to_string();
36	let Key = Params.get("key").and_then(|V| V.as_str()).unwrap_or("").to_string();
37	match Env.DeleteSecret(ExtensionId, Key).await {
38		Ok(()) => OkResponse(RequestId, &json!({ "success": true })),
39		Err(Error) => ErrResponse(RequestId, -32000, Error.to_string()),
40	}
41}