Skip to main content

systemprompt_cli/commands/cloud/secrets/
mod.rs

1//! `cloud secrets` subcommand: manage tenant environment secrets in the cloud.
2//!
3//! Exposes [`SecretsCommands`] (sync, set, unset, cleanup) and dispatches each
4//! to the corresponding action in the `commands` submodule, rejecting
5//! system-managed keys before they reach the cloud API.
6
7mod commands;
8mod helpers;
9
10use anyhow::Result;
11use clap::Subcommand;
12
13use crate::context::CommandContext;
14use crate::shared::render_result;
15
16#[derive(Debug, Subcommand)]
17pub enum SecretsCommands {
18    #[command(about = "Sync secrets from profile secrets.json to cloud")]
19    Sync,
20
21    #[command(about = "Set secrets (KEY=VALUE pairs)")]
22    Set {
23        #[arg(required = true)]
24        key_values: Vec<String>,
25    },
26
27    #[command(about = "Remove secrets")]
28    Unset {
29        #[arg(required = true)]
30        keys: Vec<String>,
31    },
32
33    #[command(about = "Remove incorrectly synced system-managed variables")]
34    Cleanup,
35}
36
37pub(super) async fn execute(cmd: SecretsCommands, ctx: &CommandContext) -> Result<()> {
38    match cmd {
39        SecretsCommands::Sync => {
40            let result = commands::sync_secrets(&ctx.cli).await?;
41            render_result(&result, &ctx.cli);
42            Ok(())
43        },
44        SecretsCommands::Set { key_values } => {
45            let result = commands::set_secrets(key_values, &ctx.cli).await?;
46            render_result(&result, &ctx.cli);
47            Ok(())
48        },
49        SecretsCommands::Unset { keys } => {
50            let result = commands::unset_secrets(keys, &ctx.cli).await?;
51            render_result(&result, &ctx.cli);
52            Ok(())
53        },
54        SecretsCommands::Cleanup => {
55            let result = commands::cleanup_secrets(&ctx.cli).await?;
56            render_result(&result, &ctx.cli);
57            Ok(())
58        },
59    }
60}