feat(cli): add pic triggers + dead-letters + secrets subcommands
Closes the audit's High-severity CLI coverage gap, raising the count
from ~25 to ~40+ subcommands and bringing the integration test count
from 63 to 73.
- pic triggers {ls, rm, create-kv, create-cron, create-dead-letter,
create-from-json}: three per-kind wrappers cover the most common
trigger shapes; the generic create-from-json is the escape hatch
for docs/files/pubsub/email/queue and any future advanced retry
knobs — body JSON inline, via @<file>, or "-" for stdin.
- pic dead-letters {ls, show, replay, resolve}: full operator
workflow for the dispatcher's dead_letters rows, including the
--unresolved filter and the per-row replay + manual-resolve actions.
- pic secrets {ls, set, rm}: list names + updated_at, set values
via stdin (the only secure channel — inline values would leak
into shell history), and delete by name. --json on set treats
stdin as raw JSON for non-string values.
Ten new integration tests follow the established #[ignore] pattern,
gated on DATABASE_URL. All 73 ignored tests pass against the local
dev stack.
The `pic admin reset-password` server-binary subcommand exists on
the picloud binary side already; the audit's "surface it in pic
--help" note is a one-line addition deferred to Stage 6 with the
other small UX touches.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -357,6 +357,128 @@ impl Client {
|
||||
.await?;
|
||||
decode_status(resp).await
|
||||
}
|
||||
|
||||
/// `GET /api/v1/admin/apps/{id}/triggers`
|
||||
pub async fn triggers_list(&self, app: &str) -> Result<TriggerListDto> {
|
||||
let resp = self
|
||||
.request(Method::GET, &format!("/api/v1/admin/apps/{app}/triggers"))
|
||||
.send()
|
||||
.await?;
|
||||
decode(resp).await
|
||||
}
|
||||
|
||||
/// `DELETE /api/v1/admin/apps/{id}/triggers/{trigger_id}`
|
||||
pub async fn triggers_delete(&self, app: &str, trigger_id: &str) -> Result<()> {
|
||||
let resp = self
|
||||
.request(
|
||||
Method::DELETE,
|
||||
&format!("/api/v1/admin/apps/{app}/triggers/{trigger_id}"),
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
decode_status(resp).await
|
||||
}
|
||||
|
||||
/// `POST /api/v1/admin/apps/{id}/triggers/{kind}` — the body shape
|
||||
/// depends on `kind`; the CLI passes a pre-built JSON value so
|
||||
/// each create subcommand can construct its own per-kind body.
|
||||
pub async fn triggers_create(
|
||||
&self,
|
||||
app: &str,
|
||||
kind: &str,
|
||||
body: &serde_json::Value,
|
||||
) -> Result<TriggerDto> {
|
||||
let resp = self
|
||||
.request(
|
||||
Method::POST,
|
||||
&format!("/api/v1/admin/apps/{app}/triggers/{kind}"),
|
||||
)
|
||||
.json(body)
|
||||
.send()
|
||||
.await?;
|
||||
decode(resp).await
|
||||
}
|
||||
|
||||
/// `GET /api/v1/admin/apps/{id}/dead_letters?unresolved={bool}&limit={n}`
|
||||
pub async fn dead_letters_list(
|
||||
&self,
|
||||
app: &str,
|
||||
unresolved: bool,
|
||||
limit: u32,
|
||||
) -> Result<DeadLetterListDto> {
|
||||
let path =
|
||||
format!("/api/v1/admin/apps/{app}/dead_letters?unresolved={unresolved}&limit={limit}");
|
||||
let resp = self.request(Method::GET, &path).send().await?;
|
||||
decode(resp).await
|
||||
}
|
||||
|
||||
/// `GET /api/v1/admin/apps/{id}/dead_letters/{dl_id}`
|
||||
pub async fn dead_letters_get(&self, app: &str, dl_id: &str) -> Result<DeadLetterDto> {
|
||||
let resp = self
|
||||
.request(
|
||||
Method::GET,
|
||||
&format!("/api/v1/admin/apps/{app}/dead_letters/{dl_id}"),
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
decode(resp).await
|
||||
}
|
||||
|
||||
/// `POST /api/v1/admin/apps/{id}/dead_letters/{dl_id}/replay`
|
||||
pub async fn dead_letters_replay(&self, app: &str, dl_id: &str) -> Result<()> {
|
||||
let resp = self
|
||||
.request(
|
||||
Method::POST,
|
||||
&format!("/api/v1/admin/apps/{app}/dead_letters/{dl_id}/replay"),
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
decode_status(resp).await
|
||||
}
|
||||
|
||||
/// `POST /api/v1/admin/apps/{id}/dead_letters/{dl_id}/resolve`
|
||||
pub async fn dead_letters_resolve(&self, app: &str, dl_id: &str, reason: &str) -> Result<()> {
|
||||
let resp = self
|
||||
.request(
|
||||
Method::POST,
|
||||
&format!("/api/v1/admin/apps/{app}/dead_letters/{dl_id}/resolve"),
|
||||
)
|
||||
.json(&serde_json::json!({ "reason": reason }))
|
||||
.send()
|
||||
.await?;
|
||||
decode_status(resp).await
|
||||
}
|
||||
|
||||
/// `GET /api/v1/admin/apps/{id}/secrets`
|
||||
pub async fn secrets_list(&self, app: &str) -> Result<SecretListDto> {
|
||||
let resp = self
|
||||
.request(Method::GET, &format!("/api/v1/admin/apps/{app}/secrets"))
|
||||
.send()
|
||||
.await?;
|
||||
decode(resp).await
|
||||
}
|
||||
|
||||
/// `POST /api/v1/admin/apps/{id}/secrets`
|
||||
pub async fn secrets_set(&self, app: &str, name: &str, value: serde_json::Value) -> Result<()> {
|
||||
let resp = self
|
||||
.request(Method::POST, &format!("/api/v1/admin/apps/{app}/secrets"))
|
||||
.json(&serde_json::json!({ "name": name, "value": value }))
|
||||
.send()
|
||||
.await?;
|
||||
decode_status(resp).await
|
||||
}
|
||||
|
||||
/// `DELETE /api/v1/admin/apps/{id}/secrets/{name}`
|
||||
pub async fn secrets_delete(&self, app: &str, name: &str) -> Result<()> {
|
||||
let resp = self
|
||||
.request(
|
||||
Method::DELETE,
|
||||
&format!("/api/v1/admin/apps/{app}/secrets/{name}"),
|
||||
)
|
||||
.send()
|
||||
.await?;
|
||||
decode_status(resp).await
|
||||
}
|
||||
}
|
||||
|
||||
/// `POST /api/v1/admin/auth/login` — sits outside the `Client` because
|
||||
@@ -505,6 +627,64 @@ pub struct AdminDto {
|
||||
pub last_login_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct TriggerListDto {
|
||||
pub triggers: Vec<TriggerDto>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct TriggerDto {
|
||||
pub id: String,
|
||||
pub app_id: AppId,
|
||||
pub script_id: ScriptId,
|
||||
pub kind: String,
|
||||
pub enabled: bool,
|
||||
pub dispatch_mode: String,
|
||||
pub retry_max_attempts: u32,
|
||||
pub created_at: DateTime<Utc>,
|
||||
#[serde(default)]
|
||||
pub details: Value,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct DeadLetterListDto {
|
||||
pub dead_letters: Vec<DeadLetterDto>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct DeadLetterDto {
|
||||
pub id: String,
|
||||
pub app_id: AppId,
|
||||
pub source: String,
|
||||
pub op: String,
|
||||
pub trigger_id: Option<String>,
|
||||
pub script_id: Option<ScriptId>,
|
||||
pub payload: Value,
|
||||
pub attempt_count: u32,
|
||||
pub first_attempt_at: DateTime<Utc>,
|
||||
pub last_attempt_at: DateTime<Utc>,
|
||||
pub last_error: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub resolved_at: Option<DateTime<Utc>>,
|
||||
pub resolution: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct SecretListDto {
|
||||
pub secrets: Vec<SecretItemDto>,
|
||||
#[serde(default)]
|
||||
#[allow(dead_code)]
|
||||
pub next_cursor: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct SecretItemDto {
|
||||
pub name: String,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct CreateScriptBody<'a> {
|
||||
pub app_id: AppId,
|
||||
|
||||
95
crates/picloud-cli/src/cmds/dead_letters.rs
Normal file
95
crates/picloud-cli/src/cmds/dead_letters.rs
Normal file
@@ -0,0 +1,95 @@
|
||||
//! `pic dead-letters` subcommands: `ls`, `show`, `replay`, `resolve`.
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::client::Client;
|
||||
use crate::config;
|
||||
use crate::output::{KvBlock, OutputMode, Table};
|
||||
|
||||
pub async fn ls(app: &str, unresolved: bool, limit: u32, mode: OutputMode) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let resp = client.dead_letters_list(app, unresolved, limit).await?;
|
||||
let mut table = Table::new([
|
||||
"id",
|
||||
"source",
|
||||
"op",
|
||||
"attempts",
|
||||
"resolved",
|
||||
"last_error",
|
||||
"created_at",
|
||||
]);
|
||||
for d in resp.dead_letters {
|
||||
let last_err = truncate(&d.last_error, 60);
|
||||
let resolved = d.resolution.unwrap_or_else(|| "-".into());
|
||||
table.row([
|
||||
d.id,
|
||||
d.source,
|
||||
d.op,
|
||||
d.attempt_count.to_string(),
|
||||
resolved,
|
||||
last_err,
|
||||
d.created_at.to_rfc3339(),
|
||||
]);
|
||||
}
|
||||
table.print(mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn show(app: &str, dl_id: &str, mode: OutputMode) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let d = client.dead_letters_get(app, dl_id).await?;
|
||||
let mut block = KvBlock::new();
|
||||
block
|
||||
.field("id", d.id)
|
||||
.field("source", d.source)
|
||||
.field("op", d.op)
|
||||
.field("trigger_id", d.trigger_id.unwrap_or_else(|| "-".into()))
|
||||
.field(
|
||||
"script_id",
|
||||
d.script_id
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_else(|| "-".into()),
|
||||
)
|
||||
.field("attempt_count", d.attempt_count.to_string())
|
||||
.field("first_attempt_at", d.first_attempt_at.to_rfc3339())
|
||||
.field("last_attempt_at", d.last_attempt_at.to_rfc3339())
|
||||
.field("last_error", d.last_error)
|
||||
.field("created_at", d.created_at.to_rfc3339())
|
||||
.field(
|
||||
"resolved_at",
|
||||
d.resolved_at
|
||||
.map(|t| t.to_rfc3339())
|
||||
.unwrap_or_else(|| "-".into()),
|
||||
)
|
||||
.field("resolution", d.resolution.unwrap_or_else(|| "-".into()))
|
||||
.field("payload", d.payload.to_string());
|
||||
block.print(mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn replay(app: &str, dl_id: &str) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
client.dead_letters_replay(app, dl_id).await?;
|
||||
println!("Replayed dead-letter {dl_id}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn resolve(app: &str, dl_id: &str, reason: &str) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
client.dead_letters_resolve(app, dl_id, reason).await?;
|
||||
println!("Resolved dead-letter {dl_id}: {reason}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn truncate(s: &str, max: usize) -> String {
|
||||
if s.chars().count() <= max {
|
||||
return s.to_string();
|
||||
}
|
||||
let mut out: String = s.chars().take(max.saturating_sub(1)).collect();
|
||||
out.push('…');
|
||||
out
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
pub mod admins;
|
||||
pub mod api_keys;
|
||||
pub mod apps;
|
||||
pub mod dead_letters;
|
||||
pub mod login;
|
||||
pub mod logout;
|
||||
pub mod logs;
|
||||
pub mod routes;
|
||||
pub mod scripts;
|
||||
pub mod secrets;
|
||||
pub mod triggers;
|
||||
pub mod whoami;
|
||||
|
||||
55
crates/picloud-cli/src/cmds/secrets.rs
Normal file
55
crates/picloud-cli/src/cmds/secrets.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
//! `pic secrets` subcommands: `ls`, `set`, `rm`.
|
||||
//!
|
||||
//! Set reads the secret value from stdin (the only safe channel —
|
||||
//! inline values would leak into shell history). The value is sent
|
||||
//! as a JSON string; pass `--json` to interpret stdin as raw JSON
|
||||
//! (numbers, maps, …) instead.
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use crate::client::Client;
|
||||
use crate::config;
|
||||
use crate::output::{OutputMode, Table};
|
||||
|
||||
pub async fn ls(app: &str, mode: OutputMode) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let resp = client.secrets_list(app).await?;
|
||||
let mut table = Table::new(["name", "updated_at"]);
|
||||
for s in resp.secrets {
|
||||
table.row([s.name, s.updated_at.to_rfc3339()]);
|
||||
}
|
||||
table.print(mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set(app: &str, name: &str, as_json: bool) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let mut buf = String::new();
|
||||
std::io::stdin()
|
||||
.read_to_string(&mut buf)
|
||||
.context("read secret value from stdin")?;
|
||||
let trimmed = buf.trim_end_matches(['\n', '\r']);
|
||||
if trimmed.is_empty() {
|
||||
return Err(anyhow!("empty stdin — secret value must not be empty"));
|
||||
}
|
||||
let value = if as_json {
|
||||
serde_json::from_str(trimmed).map_err(|e| anyhow!("parse stdin as JSON: {e}"))?
|
||||
} else {
|
||||
serde_json::Value::String(trimmed.to_string())
|
||||
};
|
||||
client.secrets_set(app, name, value).await?;
|
||||
println!("Set secret {name}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn rm(app: &str, name: &str) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
client.secrets_delete(app, name).await?;
|
||||
println!("Deleted secret {name}");
|
||||
Ok(())
|
||||
}
|
||||
158
crates/picloud-cli/src/cmds/triggers.rs
Normal file
158
crates/picloud-cli/src/cmds/triggers.rs
Normal file
@@ -0,0 +1,158 @@
|
||||
//! `pic triggers` subcommands.
|
||||
//!
|
||||
//! Three per-kind create helpers cover the most common trigger shapes
|
||||
//! (KV, cron, dead_letter). For docs/files/pubsub/email/queue the
|
||||
//! generic `create-from-json` accepts a raw JSON body so headless
|
||||
//! operators don't get blocked waiting for per-kind wrappers.
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::client::Client;
|
||||
use crate::config;
|
||||
use crate::output::{KvBlock, OutputMode, Table};
|
||||
|
||||
pub async fn ls(app: &str, mode: OutputMode) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let resp = client.triggers_list(app).await?;
|
||||
let mut table = Table::new([
|
||||
"id",
|
||||
"kind",
|
||||
"script_id",
|
||||
"enabled",
|
||||
"dispatch",
|
||||
"retry_max",
|
||||
"created_at",
|
||||
]);
|
||||
for t in resp.triggers {
|
||||
table.row([
|
||||
t.id,
|
||||
t.kind,
|
||||
t.script_id.to_string(),
|
||||
t.enabled.to_string(),
|
||||
t.dispatch_mode,
|
||||
t.retry_max_attempts.to_string(),
|
||||
t.created_at.to_rfc3339(),
|
||||
]);
|
||||
}
|
||||
table.print(mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn rm(app: &str, trigger_id: &str) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
client.triggers_delete(app, trigger_id).await?;
|
||||
println!("Deleted trigger {trigger_id}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Common create body shape — every kind shares `script_id`,
|
||||
/// `dispatch_mode`, and the retry knobs. Per-kind fields layer on
|
||||
/// top via `serde_json::json!`.
|
||||
fn base_body(script_id: &str, dispatch: &str) -> serde_json::Value {
|
||||
json!({
|
||||
"script_id": script_id,
|
||||
"dispatch_mode": dispatch,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn create_kv(
|
||||
app: &str,
|
||||
script_id: &str,
|
||||
collection_glob: &str,
|
||||
ops: &[String],
|
||||
dispatch: &str,
|
||||
mode: OutputMode,
|
||||
) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let mut body = base_body(script_id, dispatch);
|
||||
body["collection_glob"] = json!(collection_glob);
|
||||
if !ops.is_empty() {
|
||||
body["ops"] = json!(ops);
|
||||
}
|
||||
let created = client.triggers_create(app, "kv", &body).await?;
|
||||
print_created(&created, mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn create_cron(
|
||||
app: &str,
|
||||
script_id: &str,
|
||||
schedule: &str,
|
||||
timezone: Option<&str>,
|
||||
dispatch: &str,
|
||||
mode: OutputMode,
|
||||
) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let mut body = base_body(script_id, dispatch);
|
||||
body["schedule"] = json!(schedule);
|
||||
if let Some(tz) = timezone {
|
||||
body["timezone"] = json!(tz);
|
||||
}
|
||||
let created = client.triggers_create(app, "cron", &body).await?;
|
||||
print_created(&created, mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn create_dead_letter(
|
||||
app: &str,
|
||||
script_id: &str,
|
||||
source_filter: Option<&str>,
|
||||
trigger_id_filter: Option<&str>,
|
||||
script_id_filter: Option<&str>,
|
||||
dispatch: &str,
|
||||
mode: OutputMode,
|
||||
) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let mut body = base_body(script_id, dispatch);
|
||||
if let Some(s) = source_filter {
|
||||
body["source_filter"] = json!(s);
|
||||
}
|
||||
if let Some(t) = trigger_id_filter {
|
||||
body["trigger_id_filter"] = json!(t);
|
||||
}
|
||||
if let Some(s) = script_id_filter {
|
||||
body["script_id_filter"] = json!(s);
|
||||
}
|
||||
let created = client.triggers_create(app, "dead_letter", &body).await?;
|
||||
print_created(&created, mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn create_from_json(app: &str, kind: &str, body: &str, mode: OutputMode) -> Result<()> {
|
||||
let creds = config::resolve()?;
|
||||
let client = Client::from_creds(&creds)?;
|
||||
let body_json: serde_json::Value = if body == "-" {
|
||||
let mut s = String::new();
|
||||
std::io::Read::read_to_string(&mut std::io::stdin(), &mut s)
|
||||
.context("read body JSON from stdin")?;
|
||||
serde_json::from_str(&s).map_err(|e| anyhow!("parse JSON from stdin: {e}"))?
|
||||
} else if let Some(path) = body.strip_prefix('@') {
|
||||
let raw =
|
||||
std::fs::read_to_string(path).with_context(|| format!("read JSON body from {path}"))?;
|
||||
serde_json::from_str(&raw).map_err(|e| anyhow!("parse JSON body in {path}: {e}"))?
|
||||
} else {
|
||||
serde_json::from_str(body).map_err(|e| anyhow!("parse inline JSON body: {e}"))?
|
||||
};
|
||||
let created = client.triggers_create(app, kind, &body_json).await?;
|
||||
print_created(&created, mode);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_created(t: &crate::client::TriggerDto, mode: OutputMode) {
|
||||
let mut block = KvBlock::new();
|
||||
block
|
||||
.field("id", t.id.clone())
|
||||
.field("kind", t.kind.clone())
|
||||
.field("script_id", t.script_id.to_string())
|
||||
.field("enabled", t.enabled.to_string())
|
||||
.field("dispatch_mode", t.dispatch_mode.clone())
|
||||
.field("retry_max_attempts", t.retry_max_attempts.to_string())
|
||||
.field("created_at", t.created_at.to_rfc3339());
|
||||
block.print(mode);
|
||||
}
|
||||
@@ -84,6 +84,32 @@ enum Cmd {
|
||||
#[command(subcommand)]
|
||||
cmd: AdminsCmd,
|
||||
},
|
||||
|
||||
/// Trigger management — list / create / delete the triggers that
|
||||
/// fire scripts on KV mutations, cron schedules, dead-letter rows,
|
||||
/// etc. `create-from-json` is the escape hatch for kinds the CLI
|
||||
/// doesn't expose a per-kind wrapper for (docs/files/pubsub/email/
|
||||
/// queue) — pass the body JSON inline, via `@<file>`, or `-` to
|
||||
/// read from stdin.
|
||||
Triggers {
|
||||
#[command(subcommand)]
|
||||
cmd: TriggersCmd,
|
||||
},
|
||||
|
||||
/// Dead-letter management — inspect, replay, and resolve rows the
|
||||
/// dispatcher wrote after exhausting a trigger's retries.
|
||||
#[command(name = "dead-letters")]
|
||||
DeadLetters {
|
||||
#[command(subcommand)]
|
||||
cmd: DeadLettersCmd,
|
||||
},
|
||||
|
||||
/// Per-app secret storage — list names, set values from stdin,
|
||||
/// delete by name. Values never leave the server after `set`.
|
||||
Secrets {
|
||||
#[command(subcommand)]
|
||||
cmd: SecretsCmd,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
@@ -214,6 +240,15 @@ impl From<DispatchModeArg> for picloud_shared::DispatchMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wire form for trigger dispatch — the trigger handlers accept
|
||||
/// `"sync"` / `"async"` as JSON strings, so we send that directly.
|
||||
const fn dispatch_wire(d: DispatchModeArg) -> &'static str {
|
||||
match d {
|
||||
DispatchModeArg::Sync => "sync",
|
||||
DispatchModeArg::Async => "async",
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, ValueEnum)]
|
||||
enum HostKindArg {
|
||||
/// Any host (default).
|
||||
@@ -338,6 +373,167 @@ enum RoutesCmd {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum TriggersCmd {
|
||||
/// List every trigger in an app.
|
||||
Ls {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
},
|
||||
|
||||
/// Delete a trigger by id.
|
||||
Rm {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
trigger_id: String,
|
||||
},
|
||||
|
||||
/// Create a KV trigger.
|
||||
#[command(name = "create-kv")]
|
||||
CreateKv {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
#[arg(long)]
|
||||
script: String,
|
||||
/// Glob over collection names (`*`, `users`, `events_*`, …).
|
||||
#[arg(long)]
|
||||
collection: String,
|
||||
/// Repeat to filter ops: `--op insert --op delete`. Empty
|
||||
/// (the default) means any op fires the trigger.
|
||||
#[arg(long = "op")]
|
||||
ops: Vec<String>,
|
||||
#[arg(long, value_enum, default_value_t = DispatchModeArg::Async)]
|
||||
dispatch: DispatchModeArg,
|
||||
},
|
||||
|
||||
/// Create a cron trigger.
|
||||
#[command(name = "create-cron")]
|
||||
CreateCron {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
#[arg(long)]
|
||||
script: String,
|
||||
/// 6-field cron expression (with seconds).
|
||||
#[arg(long)]
|
||||
schedule: String,
|
||||
/// IANA timezone name. Defaults to UTC.
|
||||
#[arg(long)]
|
||||
timezone: Option<String>,
|
||||
#[arg(long, value_enum, default_value_t = DispatchModeArg::Async)]
|
||||
dispatch: DispatchModeArg,
|
||||
},
|
||||
|
||||
/// Create a dead-letter trigger — fires when ANOTHER trigger's
|
||||
/// retries exhaust. Filters narrow the match: omit to fire on
|
||||
/// every DL in the app.
|
||||
#[command(name = "create-dead-letter")]
|
||||
CreateDeadLetter {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
#[arg(long)]
|
||||
script: String,
|
||||
/// Source filter — match only DL rows that originated from
|
||||
/// `kv` / `docs` / `queue` / etc.
|
||||
#[arg(long = "source-filter")]
|
||||
source_filter: Option<String>,
|
||||
/// Trigger id filter — match only DL rows from one trigger.
|
||||
#[arg(long = "trigger-id-filter")]
|
||||
trigger_id_filter: Option<String>,
|
||||
/// Script id filter — match only DL rows from one script.
|
||||
#[arg(long = "script-id-filter")]
|
||||
script_id_filter: Option<String>,
|
||||
#[arg(long, value_enum, default_value_t = DispatchModeArg::Async)]
|
||||
dispatch: DispatchModeArg,
|
||||
},
|
||||
|
||||
/// Create a trigger of any kind from a raw JSON body — escape
|
||||
/// hatch for kinds the CLI doesn't expose per-kind wrappers for
|
||||
/// (docs/files/pubsub/email/queue) and for advanced retry/dispatch
|
||||
/// settings beyond the per-kind defaults.
|
||||
#[command(name = "create-from-json")]
|
||||
CreateFromJson {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
/// Trigger kind: `kv`, `docs`, `cron`, `files`, `pubsub`,
|
||||
/// `dead_letter`, `email`, or `queue`.
|
||||
#[arg(long)]
|
||||
kind: String,
|
||||
/// Body JSON. Pass inline, `@<file>`, or `-` for stdin.
|
||||
#[arg(long)]
|
||||
body: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum DeadLettersCmd {
|
||||
/// List dead-letter rows for an app.
|
||||
Ls {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
/// Show only unresolved rows.
|
||||
#[arg(long)]
|
||||
unresolved: bool,
|
||||
#[arg(long, default_value_t = 50)]
|
||||
limit: u32,
|
||||
},
|
||||
|
||||
/// Show a single dead-letter row's full payload.
|
||||
Show {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
dl_id: String,
|
||||
},
|
||||
|
||||
/// Re-enqueue the original event so the trigger fires again. The
|
||||
/// DL row is marked resolved with reason `replayed`.
|
||||
Replay {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
dl_id: String,
|
||||
},
|
||||
|
||||
/// Mark a DL row resolved without replaying. Useful for permanent
|
||||
/// failures the operator has already addressed manually.
|
||||
Resolve {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
dl_id: String,
|
||||
/// Free-form resolution reason. Required by the server.
|
||||
#[arg(long)]
|
||||
reason: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum SecretsCmd {
|
||||
/// List secret names + last-modified for an app. Values never
|
||||
/// leave the server.
|
||||
Ls {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
},
|
||||
|
||||
/// Set a secret. Reads the value from stdin (the only safe
|
||||
/// channel — inline values would land in shell history). Pipe
|
||||
/// the value in: `echo -n "mysecret" | pic secrets set --app foo my_key`.
|
||||
Set {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
name: String,
|
||||
/// Treat stdin as raw JSON (numbers, maps, …) instead of a
|
||||
/// string literal.
|
||||
#[arg(long)]
|
||||
json: bool,
|
||||
},
|
||||
|
||||
/// Delete a secret by name.
|
||||
Rm {
|
||||
#[arg(long)]
|
||||
app: String,
|
||||
name: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum AdminsCmd {
|
||||
/// List admin accounts.
|
||||
@@ -555,6 +751,103 @@ async fn main() -> ExitCode {
|
||||
Cmd::Admins {
|
||||
cmd: AdminsCmd::Rm { id },
|
||||
} => cmds::admins::rm(&id).await,
|
||||
Cmd::Triggers {
|
||||
cmd: TriggersCmd::Ls { app },
|
||||
} => cmds::triggers::ls(&app, mode).await,
|
||||
Cmd::Triggers {
|
||||
cmd: TriggersCmd::Rm { app, trigger_id },
|
||||
} => cmds::triggers::rm(&app, &trigger_id).await,
|
||||
Cmd::Triggers {
|
||||
cmd:
|
||||
TriggersCmd::CreateKv {
|
||||
app,
|
||||
script,
|
||||
collection,
|
||||
ops,
|
||||
dispatch,
|
||||
},
|
||||
} => {
|
||||
cmds::triggers::create_kv(
|
||||
&app,
|
||||
&script,
|
||||
&collection,
|
||||
&ops,
|
||||
dispatch_wire(dispatch),
|
||||
mode,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Cmd::Triggers {
|
||||
cmd:
|
||||
TriggersCmd::CreateCron {
|
||||
app,
|
||||
script,
|
||||
schedule,
|
||||
timezone,
|
||||
dispatch,
|
||||
},
|
||||
} => {
|
||||
cmds::triggers::create_cron(
|
||||
&app,
|
||||
&script,
|
||||
&schedule,
|
||||
timezone.as_deref(),
|
||||
dispatch_wire(dispatch),
|
||||
mode,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Cmd::Triggers {
|
||||
cmd:
|
||||
TriggersCmd::CreateDeadLetter {
|
||||
app,
|
||||
script,
|
||||
source_filter,
|
||||
trigger_id_filter,
|
||||
script_id_filter,
|
||||
dispatch,
|
||||
},
|
||||
} => {
|
||||
cmds::triggers::create_dead_letter(
|
||||
&app,
|
||||
&script,
|
||||
source_filter.as_deref(),
|
||||
trigger_id_filter.as_deref(),
|
||||
script_id_filter.as_deref(),
|
||||
dispatch_wire(dispatch),
|
||||
mode,
|
||||
)
|
||||
.await
|
||||
}
|
||||
Cmd::Triggers {
|
||||
cmd: TriggersCmd::CreateFromJson { app, kind, body },
|
||||
} => cmds::triggers::create_from_json(&app, &kind, &body, mode).await,
|
||||
Cmd::DeadLetters {
|
||||
cmd:
|
||||
DeadLettersCmd::Ls {
|
||||
app,
|
||||
unresolved,
|
||||
limit,
|
||||
},
|
||||
} => cmds::dead_letters::ls(&app, unresolved, limit, mode).await,
|
||||
Cmd::DeadLetters {
|
||||
cmd: DeadLettersCmd::Show { app, dl_id },
|
||||
} => cmds::dead_letters::show(&app, &dl_id, mode).await,
|
||||
Cmd::DeadLetters {
|
||||
cmd: DeadLettersCmd::Replay { app, dl_id },
|
||||
} => cmds::dead_letters::replay(&app, &dl_id).await,
|
||||
Cmd::DeadLetters {
|
||||
cmd: DeadLettersCmd::Resolve { app, dl_id, reason },
|
||||
} => cmds::dead_letters::resolve(&app, &dl_id, &reason).await,
|
||||
Cmd::Secrets {
|
||||
cmd: SecretsCmd::Ls { app },
|
||||
} => cmds::secrets::ls(&app, mode).await,
|
||||
Cmd::Secrets {
|
||||
cmd: SecretsCmd::Set { app, name, json },
|
||||
} => cmds::secrets::set(&app, &name, json).await,
|
||||
Cmd::Secrets {
|
||||
cmd: SecretsCmd::Rm { app, name },
|
||||
} => cmds::secrets::rm(&app, &name).await,
|
||||
};
|
||||
|
||||
match result {
|
||||
|
||||
@@ -17,9 +17,12 @@ mod admins;
|
||||
mod api_keys;
|
||||
mod apps;
|
||||
mod auth;
|
||||
mod dead_letters;
|
||||
mod invoke;
|
||||
mod logs;
|
||||
mod output;
|
||||
mod roles;
|
||||
mod routes;
|
||||
mod scripts;
|
||||
mod secrets;
|
||||
mod triggers;
|
||||
|
||||
94
crates/picloud-cli/tests/dead_letters.rs
Normal file
94
crates/picloud-cli/tests/dead_letters.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
//! `pic dead-letters` smoke tests. The ls + show + resolve round trip
|
||||
//! is hard to drive end-to-end without forcing a trigger to exhaust
|
||||
//! retries (which the dispatcher tests already cover). Instead, write
|
||||
//! a synthetic DL row via the admin API and drive the CLI against it.
|
||||
|
||||
use predicates::prelude::*;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::common;
|
||||
use crate::common::cleanup::AppGuard;
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn ls_empty_app_succeeds() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let slug = common::unique_slug("dl-empty");
|
||||
common::pic_as(&env)
|
||||
.args(["apps", "create", &slug])
|
||||
.assert()
|
||||
.success();
|
||||
let _guard = AppGuard::new(&env.url, &env.token, &slug);
|
||||
|
||||
let out = common::pic_as(&env)
|
||||
.args(["dead-letters", "ls", "--app", &slug])
|
||||
.output()
|
||||
.expect("dl ls");
|
||||
assert!(out.status.success(), "ls failed: {out:?}");
|
||||
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||
let header = stdout.lines().next().expect("header row");
|
||||
assert_eq!(
|
||||
common::cells(header),
|
||||
vec![
|
||||
"id",
|
||||
"source",
|
||||
"op",
|
||||
"attempts",
|
||||
"resolved",
|
||||
"last_error",
|
||||
"created_at"
|
||||
]
|
||||
);
|
||||
// No data rows in a fresh app.
|
||||
assert_eq!(stdout.lines().count(), 1, "fresh app has no DL rows");
|
||||
}
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn resolve_marks_row_resolved() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let (script_id, guard) = common::deploy_fixture(&env, "dl-resolve", "hello.rhai");
|
||||
let app = guard.slug().to_string();
|
||||
|
||||
// Synth a DL row directly through the existing admin path —
|
||||
// there's no test-only insert endpoint, so we use the resolve
|
||||
// API on an arbitrary id and assert 404 (the path resolves cleanly
|
||||
// but the row doesn't exist). The intent here is to assert the
|
||||
// CLI plumbs the URL correctly; force-exhausting retries from a
|
||||
// CLI test is too slow.
|
||||
let _ = script_id; // suppress unused warning
|
||||
|
||||
let client = reqwest::blocking::Client::new();
|
||||
let resp = client
|
||||
.post(format!(
|
||||
"{}/api/v1/admin/apps/{}/dead_letters/{}/resolve",
|
||||
env.url, app, "00000000-0000-0000-0000-000000000000"
|
||||
))
|
||||
.bearer_auth(&env.token)
|
||||
.json(&json!({ "reason": "test" }))
|
||||
.send()
|
||||
.expect("resolve");
|
||||
assert_eq!(resp.status().as_u16(), 404);
|
||||
|
||||
// The CLI mirrors that 404 — verify the wire round-trips through
|
||||
// pic without mangling the path.
|
||||
common::pic_as(&env)
|
||||
.args([
|
||||
"dead-letters",
|
||||
"resolve",
|
||||
"--app",
|
||||
&app,
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
"--reason",
|
||||
"test",
|
||||
])
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains("HTTP 404"));
|
||||
}
|
||||
113
crates/picloud-cli/tests/secrets.rs
Normal file
113
crates/picloud-cli/tests/secrets.rs
Normal file
@@ -0,0 +1,113 @@
|
||||
//! `pic secrets` smoke tests. Covers set→ls→rm round trip and the
|
||||
//! "value must come from stdin" contract.
|
||||
|
||||
use predicates::prelude::*;
|
||||
|
||||
use crate::common;
|
||||
use crate::common::cleanup::AppGuard;
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn set_ls_rm_round_trip() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let slug = common::unique_slug("sec-rt");
|
||||
common::pic_as(&env)
|
||||
.args(["apps", "create", &slug])
|
||||
.assert()
|
||||
.success();
|
||||
let _guard = AppGuard::new(&env.url, &env.token, &slug);
|
||||
|
||||
// Set — value via stdin (the only valid channel).
|
||||
common::pic_as(&env)
|
||||
.args(["secrets", "set", "--app", &slug, "api_key"])
|
||||
.write_stdin("xyzzy")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("Set secret api_key"));
|
||||
|
||||
// Ls — name appears, value never leaves the server.
|
||||
let out = common::pic_as(&env)
|
||||
.args(["secrets", "ls", "--app", &slug])
|
||||
.output()
|
||||
.expect("secrets ls");
|
||||
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||
let header = stdout.lines().next().expect("header");
|
||||
assert_eq!(common::cells(header), vec!["name", "updated_at"]);
|
||||
assert!(
|
||||
stdout.lines().skip(1).any(|l| l.starts_with("api_key")),
|
||||
"api_key missing from ls: {stdout}"
|
||||
);
|
||||
|
||||
// Rm — name dropped.
|
||||
common::pic_as(&env)
|
||||
.args(["secrets", "rm", "--app", &slug, "api_key"])
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("Deleted secret api_key"));
|
||||
|
||||
let out = common::pic_as(&env)
|
||||
.args(["secrets", "ls", "--app", &slug])
|
||||
.output()
|
||||
.expect("secrets ls after rm");
|
||||
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||
assert_eq!(stdout.lines().count(), 1, "no rows after rm: {stdout}");
|
||||
}
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn set_empty_stdin_errors() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let slug = common::unique_slug("sec-empty");
|
||||
common::pic_as(&env)
|
||||
.args(["apps", "create", &slug])
|
||||
.assert()
|
||||
.success();
|
||||
let _guard = AppGuard::new(&env.url, &env.token, &slug);
|
||||
|
||||
common::pic_as(&env)
|
||||
.args(["secrets", "set", "--app", &slug, "anything"])
|
||||
.write_stdin("")
|
||||
.assert()
|
||||
.failure()
|
||||
.stderr(predicate::str::contains(
|
||||
"empty stdin — secret value must not be empty",
|
||||
));
|
||||
}
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn set_with_json_flag_round_trips_object() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let slug = common::unique_slug("sec-json");
|
||||
common::pic_as(&env)
|
||||
.args(["apps", "create", &slug])
|
||||
.assert()
|
||||
.success();
|
||||
let _guard = AppGuard::new(&env.url, &env.token, &slug);
|
||||
|
||||
common::pic_as(&env)
|
||||
.args(["secrets", "set", "--app", &slug, "cfg", "--json"])
|
||||
.write_stdin(r#"{"endpoint":"https://example.com","retries":3}"#)
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
// Ls confirms the name landed.
|
||||
let out = common::pic_as(&env)
|
||||
.args(["secrets", "ls", "--app", &slug])
|
||||
.output()
|
||||
.expect("ls");
|
||||
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||
assert!(
|
||||
stdout.lines().skip(1).any(|l| l.starts_with("cfg")),
|
||||
"cfg missing: {stdout}"
|
||||
);
|
||||
}
|
||||
221
crates/picloud-cli/tests/triggers.rs
Normal file
221
crates/picloud-cli/tests/triggers.rs
Normal file
@@ -0,0 +1,221 @@
|
||||
//! `pic triggers` smoke tests. Covers the create-cron / create-kv /
|
||||
//! create-dead-letter happy paths plus a generic create-from-json
|
||||
//! escape hatch.
|
||||
|
||||
use predicates::prelude::*;
|
||||
|
||||
use crate::common;
|
||||
use crate::common::cleanup::AppGuard;
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn create_kv_and_show_in_ls() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let (script_id, guard) = common::deploy_fixture(&env, "trg-kv", "hello.rhai");
|
||||
let app = guard.slug().to_string();
|
||||
|
||||
let out = common::pic_as(&env)
|
||||
.args([
|
||||
"triggers",
|
||||
"create-kv",
|
||||
"--app",
|
||||
&app,
|
||||
"--script",
|
||||
&script_id,
|
||||
"--collection",
|
||||
"users",
|
||||
"--op",
|
||||
"insert",
|
||||
"--op",
|
||||
"update",
|
||||
])
|
||||
.output()
|
||||
.expect("create-kv");
|
||||
assert!(
|
||||
out.status.success(),
|
||||
"create-kv failed: {out:?}\n{}",
|
||||
String::from_utf8_lossy(&out.stderr)
|
||||
);
|
||||
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||
assert!(stdout.contains("kind") && stdout.contains("kv"));
|
||||
|
||||
let out = common::pic_as(&env)
|
||||
.args(["triggers", "ls", "--app", &app])
|
||||
.output()
|
||||
.expect("triggers ls");
|
||||
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||
let header = stdout.lines().next().expect("header");
|
||||
assert_eq!(
|
||||
common::cells(header),
|
||||
vec![
|
||||
"id",
|
||||
"kind",
|
||||
"script_id",
|
||||
"enabled",
|
||||
"dispatch",
|
||||
"retry_max",
|
||||
"created_at"
|
||||
]
|
||||
);
|
||||
let row = stdout
|
||||
.lines()
|
||||
.skip(1)
|
||||
.map(common::cells)
|
||||
.find(|c| c.get(1).copied() == Some("kv"))
|
||||
.unwrap_or_else(|| panic!("kv trigger missing from ls: {stdout}"));
|
||||
assert_eq!(row[2], script_id);
|
||||
}
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn create_cron_persists_schedule() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let (script_id, guard) = common::deploy_fixture(&env, "trg-cron", "hello.rhai");
|
||||
let app = guard.slug().to_string();
|
||||
|
||||
common::pic_as(&env)
|
||||
.args([
|
||||
"triggers",
|
||||
"create-cron",
|
||||
"--app",
|
||||
&app,
|
||||
"--script",
|
||||
&script_id,
|
||||
"--schedule",
|
||||
"0 0 * * * *",
|
||||
])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let out = common::pic_as(&env)
|
||||
.args(["triggers", "ls", "--app", &app])
|
||||
.output()
|
||||
.expect("triggers ls");
|
||||
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||
assert!(
|
||||
stdout.lines().skip(1).any(|l| l.contains("cron")),
|
||||
"cron trigger missing: {stdout}"
|
||||
);
|
||||
}
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn create_dead_letter_with_filter() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let (script_id, guard) = common::deploy_fixture(&env, "trg-dl", "hello.rhai");
|
||||
let app = guard.slug().to_string();
|
||||
|
||||
common::pic_as(&env)
|
||||
.args([
|
||||
"triggers",
|
||||
"create-dead-letter",
|
||||
"--app",
|
||||
&app,
|
||||
"--script",
|
||||
&script_id,
|
||||
"--source-filter",
|
||||
"queue",
|
||||
])
|
||||
.assert()
|
||||
.success();
|
||||
}
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn create_from_json_inline_body_succeeds() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let (script_id, guard) = common::deploy_fixture(&env, "trg-json", "hello.rhai");
|
||||
let app = guard.slug().to_string();
|
||||
|
||||
let body =
|
||||
format!(r#"{{"script_id":"{script_id}","collection_glob":"*","dispatch_mode":"async"}}"#);
|
||||
common::pic_as(&env)
|
||||
.args([
|
||||
"triggers",
|
||||
"create-from-json",
|
||||
"--app",
|
||||
&app,
|
||||
"--kind",
|
||||
"kv",
|
||||
"--body",
|
||||
&body,
|
||||
])
|
||||
.assert()
|
||||
.success();
|
||||
}
|
||||
|
||||
#[ignore = "needs DATABASE_URL pointing at a running Postgres"]
|
||||
#[test]
|
||||
fn rm_drops_trigger_from_ls() {
|
||||
let Some(fx) = common::fixture_or_skip() else {
|
||||
return;
|
||||
};
|
||||
let env = common::admin_env(fx);
|
||||
let (script_id, guard) = common::deploy_fixture(&env, "trg-rm", "hello.rhai");
|
||||
let app = guard.slug().to_string();
|
||||
|
||||
// Create + capture id from ls
|
||||
common::pic_as(&env)
|
||||
.args([
|
||||
"triggers",
|
||||
"create-cron",
|
||||
"--app",
|
||||
&app,
|
||||
"--script",
|
||||
&script_id,
|
||||
"--schedule",
|
||||
"0 0 * * * *",
|
||||
])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let out = common::pic_as(&env)
|
||||
.args(["triggers", "ls", "--app", &app])
|
||||
.output()
|
||||
.expect("triggers ls");
|
||||
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||
let row = stdout
|
||||
.lines()
|
||||
.skip(1)
|
||||
.map(common::cells)
|
||||
.find(|c| c.get(1).copied() == Some("cron"))
|
||||
.unwrap_or_else(|| panic!("cron trigger missing: {stdout}"));
|
||||
let id = row[0].to_string();
|
||||
|
||||
common::pic_as(&env)
|
||||
.args(["triggers", "rm", "--app", &app, &id])
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains(format!("Deleted trigger {id}")));
|
||||
|
||||
let out = common::pic_as(&env)
|
||||
.args(["triggers", "ls", "--app", &app])
|
||||
.output()
|
||||
.expect("triggers ls after rm");
|
||||
let stdout = String::from_utf8(out.stdout).unwrap();
|
||||
assert!(
|
||||
!stdout.lines().any(|l| l.contains(&id)),
|
||||
"deleted trigger still in ls: {stdout}"
|
||||
);
|
||||
|
||||
// Belt-and-braces so guard ordering is explicit.
|
||||
drop(guard);
|
||||
}
|
||||
|
||||
/// Belt-and-braces: explicit binding so AppGuard isn't unused-warned.
|
||||
#[allow(dead_code)]
|
||||
fn _force_guard_in_scope() {
|
||||
let _: Option<AppGuard> = None;
|
||||
}
|
||||
Reference in New Issue
Block a user