wasmer_cli/commands/app/secrets/
list.rs

1use super::utils::{BackendSecretWrapper, get_secrets};
2use crate::{
3    commands::{AsyncCliCommand, app::util::AppIdentFlag},
4    config::WasmerEnv,
5    opts::ListFormatOpts,
6};
7use is_terminal::IsTerminal;
8use std::path::PathBuf;
9
10/// Retrieve the value of an existing app secret.
11#[derive(clap::Parser, Debug)]
12pub struct CmdAppSecretsList {
13    /* --- Common flags --- */
14    #[clap(flatten)]
15    pub env: WasmerEnv,
16
17    /// Don't print any message.
18    #[clap(long)]
19    pub quiet: bool,
20
21    /// Do not prompt for user input.
22    #[clap(long, default_value_t = !std::io::stdin().is_terminal())]
23    pub non_interactive: bool,
24
25    #[clap(flatten)]
26    pub fmt: ListFormatOpts,
27
28    /* --- Flags --- */
29    /// The identifier of the app to list secrets of.
30    #[clap(flatten)]
31    pub app_id: AppIdentFlag,
32
33    /// The path to the directory where the config file for the application will be written to.
34    #[clap(long = "app-dir", conflicts_with = "app")]
35    pub app_dir_path: Option<PathBuf>,
36}
37
38#[async_trait::async_trait]
39impl AsyncCliCommand for CmdAppSecretsList {
40    type Output = ();
41
42    async fn run_async(self) -> Result<Self::Output, anyhow::Error> {
43        let client = self.env.client()?;
44        let app_id = super::utils::get_app_id(
45            &client,
46            self.app_id.app.as_ref(),
47            self.app_dir_path.as_ref(),
48            self.quiet,
49            self.non_interactive,
50        )
51        .await?;
52
53        let secrets: Vec<BackendSecretWrapper> = get_secrets(&client, &app_id)
54            .await?
55            .into_iter()
56            .map(|s| s.into())
57            .collect();
58
59        println!("{}", self.fmt.format.render(secrets.as_slice()));
60
61        Ok(())
62    }
63}