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//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10mod commands;
11mod helpers;
12
13use anyhow::Result;
14use clap::Subcommand;
15
16use crate::context::CommandContext;
17use crate::shared::render_result;
18
19#[derive(Debug, Subcommand)]
20pub enum SecretsCommands {
21    #[command(about = "Sync secrets from profile secrets.json to cloud")]
22    Sync,
23
24    #[command(about = "Set secrets (KEY=VALUE pairs)")]
25    Set {
26        #[arg(required = true)]
27        key_values: Vec<String>,
28    },
29
30    #[command(about = "Remove secrets")]
31    Unset {
32        #[arg(required = true)]
33        keys: Vec<String>,
34    },
35
36    #[command(about = "Remove incorrectly synced system-managed variables")]
37    Cleanup,
38}
39
40pub(super) async fn execute(cmd: SecretsCommands, ctx: &CommandContext) -> Result<()> {
41    match cmd {
42        SecretsCommands::Sync => {
43            let result = commands::sync_secrets(&ctx.cli).await?;
44            render_result(&result, &ctx.cli);
45            Ok(())
46        },
47        SecretsCommands::Set { key_values } => {
48            let result = commands::set_secrets(key_values, &ctx.cli).await?;
49            render_result(&result, &ctx.cli);
50            Ok(())
51        },
52        SecretsCommands::Unset { keys } => {
53            let result = commands::unset_secrets(keys, &ctx.cli).await?;
54            render_result(&result, &ctx.cli);
55            Ok(())
56        },
57        SecretsCommands::Cleanup => {
58            let result = commands::cleanup_secrets(&ctx.cli).await?;
59            render_result(&result, &ctx.cli);
60            Ok(())
61        },
62    }
63}