ordinary 0.6.0-pre.9

Ordinary CLI
Documentation
use crate::cmds::accounts::get_current_account;
use clap::Subcommand;
use ordinary_api::client::OrdinaryApiClient;

#[derive(Subcommand, Debug)]
pub enum Secrets {
    /// store an application secret
    ///
    /// Note: currently requires a restart via `ordinary app restart`
    /// after being stored.
    Store {
        /// secret name
        name: String,
        // todo: also be able to load this from a file
        /// secret value
        secret: String,
    },
}

impl Secrets {
    pub async fn handle(
        &self,
        api_domain: Option<&str>,
        accept_invalid_certs: bool,
        project: &str,
        insecure: bool,
    ) -> anyhow::Result<()> {
        let account = get_current_account(insecure)?;
        let client = OrdinaryApiClient::new(
            &account.host,
            &account.name,
            api_domain,
            accept_invalid_certs,
            crate::USER_AGENT,
        )?;

        match self {
            Self::Store { name, secret } => {
                client.store(project, name, secret.as_bytes()).await?;
            }
        }

        Ok(())
    }
}