Common/Secret/StoreSecret.rs
1//! # StoreSecret Effect
2//!
3//! Defines the `ActionEffect` for storing a secret in 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 store a secret in the host's
11/// secure storage (e.g., OS keychain).
12///
13/// It uses the `SecretProvider` capability from the environment to perform the
14/// actual storage operation.
15///
16/// # Parameters
17/// * `ExtensionIdentifier`: The ID of the extension that owns the secret.
18/// * `Key`: The key to store the secret under.
19/// * `Value`: The secret string to be stored.
20///
21/// # Returns
22/// An `ActionEffect` that resolves to `()` on success.
23pub fn StoreSecret(
24 ExtensionIdentifier:String,
25
26 Key:String,
27
28 Value:String,
29) -> ActionEffect<Arc<dyn SecretProvider>, CommonError, ()> {
30 ActionEffect::New(Arc::new(move |Provider:Arc<dyn SecretProvider>| {
31 let ExtensionIdentifierClone = ExtensionIdentifier.clone();
32
33 let KeyClone = Key.clone();
34
35 let ValueClone = Value.clone();
36
37 Box::pin(async move { Provider.StoreSecret(ExtensionIdentifierClone, KeyClone, ValueClone).await })
38 }))
39}