Skip to main content

faucet_cli/commands/
schema.rs

1//! `faucet schema` — print the JSON Schema for a connector's config.
2
3use crate::cli::{SchemaArgs, SchemaTarget};
4use crate::error::CliResult;
5use crate::registry::{sink_schema, source_schema};
6use crate::transforms::transform_schema;
7
8/// Execute the `schema` subcommand.
9pub async fn run(args: SchemaArgs) -> CliResult<()> {
10    let schema = match args.target {
11        SchemaTarget::Source { name } => source_schema(&name)?,
12        SchemaTarget::Sink { name } => sink_schema(&name)?,
13        SchemaTarget::Transform { name } => transform_schema(&name)?,
14        SchemaTarget::Dlq => {
15            let dlq_schema = faucet_core::schema_for!(crate::config::DlqSpec);
16            serde_json::to_value(dlq_schema)
17                .unwrap_or_else(|_| serde_json::json!({"type": "object"}))
18        }
19        #[cfg(feature = "quality")]
20        SchemaTarget::Quality => {
21            let quality_schema = faucet_core::schema_for!(faucet_core::QualitySpec);
22            serde_json::to_value(quality_schema)
23                .unwrap_or_else(|_| serde_json::json!({"type": "object"}))
24        }
25        #[cfg(feature = "schedule")]
26        SchemaTarget::Schedule => {
27            let s = faucet_core::schema_for!(crate::schedule::spec::ScheduleSpec);
28            serde_json::to_value(s).unwrap_or_else(|_| serde_json::json!({"type": "object"}))
29        }
30        SchemaTarget::Secrets => serde_json::json!({
31            "title": "Secrets-manager interpolation grammar",
32            "schemes": {
33                "vault":    { "syntax": "${vault:<path>[#field]}", "auth": ["VAULT_ADDR", "VAULT_TOKEN", "VAULT_NAMESPACE (optional)"] },
34                "aws-sm":   { "syntax": "${aws-sm:<name-or-ARN>[#field]}", "auth": ["aws-config default credential chain"] },
35                "gcp-sm":   { "syntax": "${gcp-sm:projects/<p>/secrets/<s>/versions/<v>}", "auth": ["Application Default Credentials"] },
36                "azure-kv": { "syntax": "${azure-kv:<vault>/<secret>[/<version>]}", "auth": ["AZURE_* env / managed identity / az login"] }
37            },
38            "notes": [
39                "#field parses the secret as JSON and extracts one key (vault, aws-sm).",
40                "Resolved at config load; fetched concurrently and de-duplicated; never persisted.",
41                "Build with --features secrets (or per-backend secrets-vault / secrets-aws-sm / ...)."
42            ]
43        }),
44    };
45    let body = serde_json::to_string_pretty(&schema).unwrap_or_else(|_| schema.to_string());
46    println!("{body}");
47    Ok(())
48}