1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use super::ItemFormatOpts;
use crate::{
    commands::{
        app::util::{AppIdent, AppIdentOpts},
        AsyncCliCommand,
    },
    config::WasmerEnv,
};

/// Rotate the secrets linked to volumes of an app.
#[derive(clap::Parser, Debug)]
pub struct CmdAppVolumesRotateSecrets {
    #[clap(flatten)]
    pub env: WasmerEnv,

    #[clap(flatten)]
    pub ident: AppIdentOpts,

    #[clap(flatten)]
    pub fmt: ItemFormatOpts,
}

#[async_trait::async_trait]
impl AsyncCliCommand for CmdAppVolumesRotateSecrets {
    type Output = ();

    async fn run_async(self) -> Result<Self::Output, anyhow::Error> {
        let client = self.env.client()?;
        let (_ident, app) = self.ident.load_app(&client).await?;

        wasmer_backend_api::query::rotate_s3_secrets(&client, app.id).await?;

        // Don't print it here and leave it implied, so users can append the output
        // of `wasmer app volumes credentials` without worrying about this message.
        //
        //println!(
        //    "Correctly rotated s3 secrets for app {} ({})",
        //    app.name,
        //    app.owner.global_name.bold()
        //);

        super::CmdAppVolumesCredentials {
            env: self.env,
            fmt: self.fmt,
            ident: AppIdentOpts {
                app: Some(AppIdent::NamespacedName(app.owner.global_name, app.name)),
            },
        }
        .run_async()
        .await?;

        Ok(())
    }
}