viceroy_lib/
secret_store.rs1use {bytes::Bytes, std::collections::HashMap};
2
3#[derive(Clone, Debug, Default)]
4pub struct SecretStores {
5 stores: HashMap<String, SecretStore>,
6}
7
8impl SecretStores {
9 pub fn new() -> Self {
10 Self {
11 stores: HashMap::new(),
12 }
13 }
14
15 pub fn get_store(&self, name: &str) -> Option<&SecretStore> {
16 self.stores.get(name)
17 }
18
19 pub fn add_store(&mut self, name: String, store: SecretStore) {
20 self.stores.insert(name, store);
21 }
22}
23
24#[derive(Clone, Debug, Default)]
25pub struct SecretStore {
26 secrets: HashMap<String, Secret>,
27}
28
29impl SecretStore {
30 pub fn new() -> Self {
31 Self {
32 secrets: HashMap::new(),
33 }
34 }
35
36 pub fn get_secret(&self, name: &str) -> Option<&Secret> {
37 self.secrets.get(name)
38 }
39
40 pub fn add_secret(&mut self, name: String, secret: Bytes) {
41 self.secrets.insert(name, Secret { plaintext: secret });
42 }
43}
44
45#[derive(Clone, Debug, Default)]
46pub struct Secret {
47 plaintext: Bytes,
48}
49
50impl Secret {
51 pub fn plaintext(&self) -> &[u8] {
52 &self.plaintext
53 }
54}
55
56#[derive(Clone, Debug)]
57pub enum SecretLookup {
58 Standard {
59 store_name: String,
60 secret_name: String,
61 },
62 Injected {
63 plaintext: Vec<u8>,
64 },
65}