ordinary 0.11.1

Ordinary CLI
Documentation
use crate::HostCallFlags;
use crate::cmds::accounts::get_current_account;
use clap::Subcommand;
use tracing::instrument;

#[derive(Subcommand, Debug)]
pub enum Secrets {
    /// store an application secret
    ///
    /// Note: currently requires a restart via `ordinary app restart`
    /// after being stored.
    Store {
        #[command(flatten)]
        host: HostCallFlags,

        /// secret name
        name: String,
        // todo: also be able to load this from a file
        /// secret value
        secret: String,
    },
}

impl Secrets {
    #[instrument(skip_all, name = "secrets")]
    pub async fn handle(&self, project: &str) -> anyhow::Result<()> {
        match self {
            Self::Store { name, secret, host } => {
                let account = get_current_account(host.insecure)?;
                let client = host.client(&account)?;

                client
                    .secrets_store(project, name, secret.as_bytes())
                    .await?;
            }
        }

        Ok(())
    }
}