Common/Secret/GetSecret.rs
1//! # GetSecret Effect
2//!
3//! Defines the `ActionEffect` for retrieving a secret from secure storage.
4
5use std::sync::Arc;
6
7use super::SecretProvider::SecretProvider;
8use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
9
10/// Creates an effect that, when executed, will retrieve a secret from the
11/// host's secure storage (e.g., OS keychain).
12///
13/// It uses the `SecretProvider` capability from the environment to perform the
14/// actual retrieval.
15///
16/// # Parameters
17/// * `ExtensionIdentifier`: The ID of the extension that owns the secret.
18/// * `Key`: The key of the secret to retrieve.
19///
20/// # Returns
21/// An `ActionEffect` that resolves with an `Option<String>`, containing the
22/// secret's value or `None` if the secret does not exist.
23pub fn GetSecret(
24 ExtensionIdentifier:String,
25
26 Key:String,
27) -> ActionEffect<Arc<dyn SecretProvider>, CommonError, Option<String>> {
28 ActionEffect::New(Arc::new(move |Provider:Arc<dyn SecretProvider>| {
29 let ExtensionIdentifierClone = ExtensionIdentifier.clone();
30
31 let KeyClone = Key.clone();
32
33 Box::pin(async move { Provider.GetSecret(ExtensionIdentifierClone, KeyClone).await })
34 }))
35}