Skip to main content

SecretManager

Trait SecretManager 

Source
pub trait SecretManager: Send + Sync {
    // Required methods
    fn get_secret(&self, key: &str) -> Option<Value>;
    fn get_all_secrets(&self) -> Value;
}
Expand description

Trait for providing secrets to workflow expressions ($secret variable)

Implement this trait to provide secret values that can be accessed via the $secret expression variable in workflow definitions.

§Example

use swf_runtime::secret::SecretManager;
use serde_json::Value;
use std::collections::HashMap;

struct EnvSecretManager;

impl SecretManager for EnvSecretManager {
    fn get_secret(&self, key: &str) -> Option<Value> {
        std::env::var(key)
            .ok()
            .map(|v| Value::String(v))
    }

    fn get_all_secrets(&self) -> Value {
        let mut map = serde_json::Map::new();
        for (key, value) in std::env::vars() {
            map.insert(key, Value::String(value));
        }
        Value::Object(map)
    }
}

Required Methods§

Source

fn get_secret(&self, key: &str) -> Option<Value>

Gets a secret value by key path (e.g., “superman.name”)

Source

fn get_all_secrets(&self) -> Value

Gets all available secrets as a JSON value

The returned value should be a JSON object that can be navigated using dot notation in expressions (e.g., $secret.superman.name)

Implementors§