Skip to main content

envvault/cli/commands/
list.rs

1//! `envvault list` — display all secrets in a table.
2
3use crate::cli::output;
4use crate::cli::{load_keyfile, prompt_password_for_vault, vault_path, Cli};
5use crate::errors::Result;
6use crate::vault::VaultStore;
7
8/// Execute the `list` command.
9pub fn execute(cli: &Cli) -> Result<()> {
10    let path = vault_path(cli)?;
11    let keyfile = load_keyfile(cli)?;
12
13    let vault_id = path.to_string_lossy();
14    let password = prompt_password_for_vault(Some(&vault_id))?;
15    let store = match VaultStore::open(&path, password.as_bytes(), keyfile.as_deref()) {
16        Ok(store) => store,
17        Err(e) => {
18            #[cfg(feature = "audit-log")]
19            crate::audit::log_auth_failure(cli, &e.to_string());
20            return Err(e);
21        }
22    };
23
24    let secrets = store.list_secrets();
25
26    output::info(&format!(
27        "{} environment — {} secret(s)",
28        cli.env,
29        secrets.len()
30    ));
31
32    output::print_secrets_table(&secrets);
33
34    #[cfg(feature = "audit-log")]
35    crate::audit::log_read_audit(
36        cli,
37        "list",
38        None,
39        Some(&format!("{} secrets", secrets.len())),
40    );
41
42    Ok(())
43}