Common/Secret/SecretProvider.rs
1//! # SecretProvider Trait
2//!
3//! Defines the abstract service trait for secure storage capabilities,
4
5//! abstracting interactions with an OS-level keychain or credential store.
6
7use async_trait::async_trait;
8
9use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
10
11/// An abstract service contract for an environment component that handles the
12/// secure storage and retrieval of sensitive information like API tokens.
13///
14/// This trait is implemented by `MountainEnvironment` and typically uses a
15/// library like `keyring` to interact with the native operating system's
16/// credential manager. Secrets are namespaced by an `ExtensionIdentifier` to
17/// ensure that one extension cannot access the secrets of another.
18#[async_trait]
19pub trait SecretProvider: Environment + Send + Sync {
20 /// Retrieves a secret for a given extension and key.
21 ///
22 /// # Parameters
23 /// * `ExtensionIdentifier`: The ID of the extension that owns the secret.
24 /// * `Key`: The key identifying the secret.
25 ///
26 /// # Returns
27 /// A `Result` containing an `Option<String>`. It resolves to
28 /// `Ok(Some(Value))` if the secret is found, `Ok(None)` if not found, or
29 /// an `Err` on failure.
30 async fn GetSecret(&self, ExtensionIdentifier:String, Key:String) -> Result<Option<String>, CommonError>;
31
32 /// Stores a secret for a given extension and key.
33 ///
34 /// # Parameters
35 /// * `ExtensionIdentifier`: The ID of the extension that owns the secret.
36 /// * `Key`: The key to store the secret under.
37 /// * `Value`: The secret value to be stored.
38 async fn StoreSecret(&self, ExtensionIdentifier:String, Key:String, Value:String) -> Result<(), CommonError>;
39
40 /// Deletes a secret for a given extension and key.
41 ///
42 /// # Parameters
43 /// * `ExtensionIdentifier`: The ID of the extension that owns the secret.
44 /// * `Key`: The key of the secret to delete.
45 async fn DeleteSecret(&self, ExtensionIdentifier:String, Key:String) -> Result<(), CommonError>;
46}