submilli_engine/runtime/
secrets.rs1use serde::{Deserialize, Serialize};
4use std::future::Future;
5use std::pin::Pin;
6
7#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(transparent)]
10pub struct SecretKeyId(pub String);
11
12#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
15pub struct EncryptedSecret {
16 pub key_id: SecretKeyId,
17 #[serde(with = "super::effects::binary")]
18 pub ciphertext: Vec<u8>,
19}
20
21pub trait SecretProvider: Send + Sync {
28 fn get<'a>(
29 &'a self,
30 name: &'a str,
31 ) -> Pin<Box<dyn Future<Output = Result<Option<String>, String>> + Send + 'a>>;
32
33 fn get_encrypted<'a>(
37 &'a self,
38 _name: &'a str,
39 ) -> Pin<Box<dyn Future<Output = Result<Option<EncryptedSecret>, String>> + Send + 'a>> {
40 Box::pin(async { Err("secret provider does not support encrypted retrieval".into()) })
41 }
42
43 fn decrypt(&self, _name: &str, _secret: &EncryptedSecret) -> Result<String, String> {
47 Err("secret provider does not support decryption".into())
48 }
49}
50
51#[derive(Default)]
52pub struct NoopSecretProvider;
53
54impl SecretProvider for NoopSecretProvider {
55 fn get_encrypted<'a>(
56 &'a self,
57 _name: &'a str,
58 ) -> Pin<Box<dyn Future<Output = Result<Option<EncryptedSecret>, String>> + Send + 'a>> {
59 Box::pin(async { Ok(None) })
60 }
61
62 fn get<'a>(
63 &'a self,
64 _name: &'a str,
65 ) -> Pin<Box<dyn Future<Output = Result<Option<String>, String>> + Send + 'a>> {
66 Box::pin(async { Ok(None) })
67 }
68}