vantage_cmd/lib.rs
1//! `vantage-cmd` — a Vantage persistence backend that gets its data by
2//! **running a local command** (the `aws` CLI, `kubectl`, `gh`, …).
3//!
4//! The design pins down a strict security boundary and hands everything
5//! else to a [Rhai](https://rhai.rs) script:
6//!
7//! - The **command is locked** on the [`Cmd`] datasource — a script can
8//! never change which binary runs.
9//! - **Environment variables are locked** — the child process gets a
10//! *cleared* environment plus only the vars declared on the datasource
11//! / table (and `PATH`/`HOME` so the binary is locatable, toggleable
12//! via [`Cmd::with_pass_path`]).
13//! - The **arguments and the output parsing are scripted in Rhai**. When
14//! a table is read, the script runs with the table's `conditions`,
15//! `columns`, `limit`, `offset` and `id_column` in scope; it builds an
16//! argv, calls the registered `run(args)` callback (which executes the
17//! locked command), then parses the captured output into rows.
18//!
19//! ```no_run
20//! # use vantage_cmd::Cmd;
21//! # use vantage_table::table::Table;
22//! # use vantage_types::EmptyEntity;
23//! # async fn run() -> vantage_core::Result<()> {
24//! const LOG_GROUPS: &str = r#"
25//! let args = ["logs", "describe-log-groups", "--output", "json"];
26//! for c in conditions {
27//! if c.field == "logGroupNamePrefix" {
28//! args += ["--log-group-name-prefix", c.value];
29//! }
30//! }
31//! let out = run(args);
32//! if out.exit_code != 0 { throw out.stderr; }
33//! parse_json(out.stdout).logGroups
34//! "#;
35//!
36//! let cmd = Cmd::new("aws")
37//! .with_env("AWS_REGION", "us-east-1")
38//! .with_script("log.groups", LOG_GROUPS);
39//!
40//! let groups = Table::<Cmd, EmptyEntity>::new("log.groups", cmd)
41//! .with_id_column("logGroupName")
42//! .with_column_of::<i64>("creationTime");
43//! # let _ = groups;
44//! # Ok(()) }
45//! ```
46
47mod cmd;
48mod condition;
49mod exec;
50mod expr_data_source;
51mod operation;
52mod rhai_engine;
53mod table_source;
54mod types;
55
56pub mod models;
57pub mod vista;
58
59pub use cmd::{Cmd, CmdSpec};
60pub use condition::{CmdCondition, eq};
61pub use exec::CmdOutput;
62pub use operation::CmdOperation;
63pub use types::AnyCmdType;