cuenv_core/secrets/
mod.rs

1//! Secret and resolver types
2//!
3//! Based on schema/secrets.cue
4
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7use serde_json::Value;
8use std::collections::HashMap;
9
10/// Resolver for executing commands to retrieve secret values
11#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
12pub struct ExecResolver {
13    /// Command to execute
14    pub command: String,
15
16    /// Arguments to pass to the command
17    pub args: Vec<String>,
18}
19
20/// Secret definition with resolver
21/// This is the base type that can be extended in CUE
22#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
23pub struct Secret {
24    /// Resolver type (currently only "exec" is supported)
25    pub resolver: String,
26
27    /// Command to execute
28    pub command: String,
29
30    /// Arguments to pass to the command
31    #[serde(default)]
32    pub args: Vec<String>,
33
34    /// Additional fields for extensibility
35    #[serde(flatten)]
36    pub extra: HashMap<String, Value>,
37}
38
39impl Secret {
40    /// Create a new secret with a resolver
41    pub fn new(command: String, args: Vec<String>) -> Self {
42        Secret {
43            resolver: "exec".to_string(),
44            command,
45            args,
46            extra: HashMap::new(),
47        }
48    }
49
50    /// Create a secret with additional fields
51    pub fn with_extra(command: String, args: Vec<String>, extra: HashMap<String, Value>) -> Self {
52        Secret {
53            resolver: "exec".to_string(),
54            command,
55            args,
56            extra,
57        }
58    }
59}