feat(cli): pic config --effective (masked secret resolution)
The §11 Phase-1 `config --effective` surface. Single-app today, "config" = the app's secrets, so it cross-references the manifest's declared secret names against what's set on the server and renders each masked: `<set>` (managed / on-server-not-in-manifest) or `<unset>` (declared but not pushed). Values are never fetched or shown (§4.6). Shaped to grow an `--explain` mode and inherited `vars` when groups/vars arrive (Phase 3). Tested: a journey verifying declared-but-unset → `<unset>`, post-`secret set` → `<set>`/managed, and the value never appears in output. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
50
crates/picloud-cli/src/cmds/config.rs
Normal file
50
crates/picloud-cli/src/cmds/config.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
//! `pic config --effective` — read-only view of an app's resolved
|
||||
//! configuration, with secret values masked (§4.6).
|
||||
//!
|
||||
//! Single-app today: "config" means the app's secrets, cross-referenced
|
||||
//! against the manifest so an operator can see at a glance which declared
|
||||
//! secrets are still unset and which live secrets aren't declared. Values are
|
||||
//! never fetched or shown — only `<set>` / `<unset>`. The command is shaped to
|
||||
//! grow an `--explain` mode and inherited `vars` once groups/vars land (the
|
||||
//! Phase-3 multi-level resolution).
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use crate::client::Client;
|
||||
use crate::config;
|
||||
use crate::manifest::Manifest;
|
||||
use crate::output::{OutputMode, Table};
|
||||
|
||||
pub async fn run(manifest_path: &Path, effective: bool, mode: OutputMode) -> Result<()> {
|
||||
if !effective {
|
||||
bail!("`pic config` currently supports only `--effective`");
|
||||
}
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let manifest = Manifest::load(manifest_path)?;
|
||||
|
||||
let declared: BTreeSet<String> = manifest.secrets.names.iter().cloned().collect();
|
||||
let on_server: BTreeSet<String> = client
|
||||
.secrets_list(&manifest.app.slug)
|
||||
.await?
|
||||
.secrets
|
||||
.into_iter()
|
||||
.map(|s| s.name)
|
||||
.collect();
|
||||
|
||||
let mut table = Table::new(["secret", "value", "status"]);
|
||||
for name in declared.union(&on_server) {
|
||||
let (value, status) = match (declared.contains(name), on_server.contains(name)) {
|
||||
(true, true) => ("<set>", "managed"),
|
||||
(true, false) => ("<unset>", "declared, not pushed — `pic secret set`"),
|
||||
(false, true) => ("<set>", "on server, not in manifest"),
|
||||
(false, false) => unreachable!("name came from one of the two sets"),
|
||||
};
|
||||
table.row([name.clone(), value.to_string(), status.to_string()]);
|
||||
}
|
||||
table.print(mode);
|
||||
Ok(())
|
||||
}
|
||||
@@ -3,6 +3,7 @@ pub mod api_keys;
|
||||
pub mod apply;
|
||||
pub mod apps;
|
||||
pub mod apps_domains;
|
||||
pub mod config;
|
||||
pub mod dead_letters;
|
||||
pub mod files;
|
||||
pub mod init;
|
||||
|
||||
@@ -177,6 +177,10 @@ enum Cmd {
|
||||
/// app), `scripts/hello.rhai`, and a `.gitignore`. Offline; deploy with
|
||||
/// `pic plan` then `pic apply`.
|
||||
Init(InitArgs),
|
||||
|
||||
/// Show an app's resolved configuration. `--effective` lists secrets with
|
||||
/// values masked (`<set>`/`<unset>`), cross-referenced against the manifest.
|
||||
Config(ConfigArgs),
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
@@ -230,6 +234,16 @@ struct InitArgs {
|
||||
force: bool,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct ConfigArgs {
|
||||
/// Path to the manifest.
|
||||
#[arg(long, default_value = "picloud.toml")]
|
||||
file: PathBuf,
|
||||
/// Show the effective (resolved) config with secrets masked.
|
||||
#[arg(long)]
|
||||
effective: bool,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum KvCmd {
|
||||
/// List keys in a collection.
|
||||
@@ -1122,6 +1136,7 @@ async fn main() -> ExitCode {
|
||||
}
|
||||
Cmd::Plan(args) => cmds::plan::run(&args.file, mode).await,
|
||||
Cmd::Pull(args) => cmds::pull::run(&args.app, &args.dir, mode).await,
|
||||
Cmd::Config(args) => cmds::config::run(&args.file, args.effective, mode).await,
|
||||
Cmd::Init(args) => cmds::init::run(
|
||||
&args.dir,
|
||||
args.slug.as_deref(),
|
||||
|
||||
Reference in New Issue
Block a user