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
55
56
57
58
59
60
61
62
63
//! `vantage-cmd` — a Vantage persistence backend that gets its data by
//! **running a local command** (the `aws` CLI, `kubectl`, `gh`, …).
//!
//! The design pins down a strict security boundary and hands everything
//! else to a [Rhai](https://rhai.rs) script:
//!
//! - The **command is locked** on the [`Cmd`] datasource — a script can
//! never change which binary runs.
//! - **Environment variables are locked** — the child process gets a
//! *cleared* environment plus only the vars declared on the datasource
//! / table (and `PATH`/`HOME` so the binary is locatable, toggleable
//! via [`Cmd::with_pass_path`]).
//! - The **arguments and the output parsing are scripted in Rhai**. When
//! a table is read, the script runs with the table's `conditions`,
//! `columns`, `limit`, `offset` and `id_column` in scope; it builds an
//! argv, calls the registered `run(args)` callback (which executes the
//! locked command), then parses the captured output into rows.
//!
//! ```no_run
//! # use vantage_cmd::Cmd;
//! # use vantage_table::table::Table;
//! # use vantage_types::EmptyEntity;
//! # async fn run() -> vantage_core::Result<()> {
//! const LOG_GROUPS: &str = r#"
//! let args = ["logs", "describe-log-groups", "--output", "json"];
//! for c in conditions {
//! if c.field == "logGroupNamePrefix" {
//! args += ["--log-group-name-prefix", c.value];
//! }
//! }
//! let out = run(args);
//! if out.exit_code != 0 { throw out.stderr; }
//! parse_json(out.stdout).logGroups
//! "#;
//!
//! let cmd = Cmd::new("aws")
//! .with_env("AWS_REGION", "us-east-1")
//! .with_script("log.groups", LOG_GROUPS);
//!
//! let groups = Table::<Cmd, EmptyEntity>::new("log.groups", cmd)
//! .with_id_column("logGroupName")
//! .with_column_of::<i64>("creationTime");
//! # let _ = groups;
//! # Ok(()) }
//! ```
pub use ;
pub use ;
pub use CmdOutput;
pub use CmdOperation;
pub use AnyCmdType;