intentdataflow 0.3.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- intentdataflow-0.3.10.dist-info/METADATA +191 -0
- intentdataflow-0.3.10.dist-info/RECORD +83 -0
- intentdataflow-0.3.10.dist-info/WHEEL +5 -0
- intentdataflow-0.3.10.dist-info/entry_points.txt +2 -0
- intentdataflow-0.3.10.dist-info/licenses/LICENSE +202 -0
- intentdataflow-0.3.10.dist-info/licenses/NOTICE +4 -0
- intentdataflow-0.3.10.dist-info/top_level.txt +1 -0
- intentflow/__init__.py +2 -0
- intentflow/auth.py +30 -0
- intentflow/business_rules.py +77 -0
- intentflow/catalogs.py +100 -0
- intentflow/change_review.py +331 -0
- intentflow/checks/__init__.py +92 -0
- intentflow/checks/airflow3.py +174 -0
- intentflow/checks/business.py +27 -0
- intentflow/checks/catalog.py +43 -0
- intentflow/checks/cluster.py +81 -0
- intentflow/checks/contracts.py +79 -0
- intentflow/checks/cost.py +35 -0
- intentflow/checks/dbt_quality.py +90 -0
- intentflow/checks/dbt_run.py +83 -0
- intentflow/checks/deep.py +180 -0
- intentflow/checks/dq.py +53 -0
- intentflow/checks/elementary.py +50 -0
- intentflow/checks/external.py +91 -0
- intentflow/checks/lakehouse.py +46 -0
- intentflow/checks/lint.py +81 -0
- intentflow/checks/orchestration.py +148 -0
- intentflow/checks/probes.py +66 -0
- intentflow/checks/runtime_history.py +94 -0
- intentflow/checks/schema_drift.py +92 -0
- intentflow/checks/sql_quality.py +274 -0
- intentflow/checks/streaming.py +62 -0
- intentflow/cli.py +914 -0
- intentflow/contracts.py +107 -0
- intentflow/datadiff.py +172 -0
- intentflow/dbt_loader.py +194 -0
- intentflow/dbt_results.py +55 -0
- intentflow/dq_results.py +108 -0
- intentflow/extensions.py +51 -0
- intentflow/external.py +381 -0
- intentflow/http_utils.py +89 -0
- intentflow/i18n.py +76 -0
- intentflow/incidents.py +83 -0
- intentflow/integrations.py +139 -0
- intentflow/lakehouse.py +62 -0
- intentflow/lineage.py +336 -0
- intentflow/lineage_api.py +244 -0
- intentflow/lineage_oracle.py +374 -0
- intentflow/locale/pt.json +1300 -0
- intentflow/model.py +43 -0
- intentflow/monitoring.py +197 -0
- intentflow/notify.py +154 -0
- intentflow/ol_emit.py +93 -0
- intentflow/openlineage.py +168 -0
- intentflow/orchestrators/__init__.py +53 -0
- intentflow/orchestrators/airflow.py +69 -0
- intentflow/orchestrators/aws.py +93 -0
- intentflow/orchestrators/dagster.py +48 -0
- intentflow/orchestrators/dbtcloud.py +68 -0
- intentflow/orchestrators/extra.py +135 -0
- intentflow/orchestrators/ingestion.py +112 -0
- intentflow/orchestrators/kestra.py +27 -0
- intentflow/orchestrators/more.py +135 -0
- intentflow/orchestrators/prefect.py +53 -0
- intentflow/orchestrators/spark.py +118 -0
- intentflow/otel.py +53 -0
- intentflow/overview.py +123 -0
- intentflow/preflight.py +363 -0
- intentflow/promexport.py +39 -0
- intentflow/pyflow.py +554 -0
- intentflow/risks.py +178 -0
- intentflow/runner.py +264 -0
- intentflow/secrets_box.py +84 -0
- intentflow/sqlmesh_loader.py +134 -0
- intentflow/store.py +1006 -0
- intentflow/streaming.py +115 -0
- intentflow/totp.py +38 -0
- intentflow/warehouses/__init__.py +190 -0
- intentflow/warehouses/cloud.py +160 -0
- intentflow/warehouses/more.py +342 -0
- intentflow/web.html +878 -0
- intentflow/web.py +726 -0
intentflow/cli.py
ADDED
|
@@ -0,0 +1,914 @@
|
|
|
1
|
+
"""IntentFlow CLI: checks, lineage, data diff, run collection, notifications and the UI."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
import time
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from . import dbt_loader, extensions, lineage as lin, overview as ov
|
|
12
|
+
from .i18n import tr
|
|
13
|
+
from .model import SEVERITIES
|
|
14
|
+
from .store import Store
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _store(a) -> Store:
|
|
18
|
+
return Store(a.store)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def err(msg: str) -> None:
|
|
22
|
+
print(tr("error: {msg}", msg=msg), file=sys.stderr)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def cmd_check(a) -> int:
|
|
26
|
+
from . import runner
|
|
27
|
+
st = _store(a)
|
|
28
|
+
over = {"target": a.target, "root": a.root, "base": a.base, "base_root": a.base_root, "airflow_dags": a.airflow_dags,
|
|
29
|
+
"kestra_flows": a.kestra_flows, "duckdb": a.duckdb, "postgres_env": a.postgres_env}
|
|
30
|
+
if a.save:
|
|
31
|
+
for k, v in over.items():
|
|
32
|
+
if v is not None:
|
|
33
|
+
st.set_setting(runner.SOURCE_KEYS[k], v)
|
|
34
|
+
stages = set(a.stage.split(",")) if getattr(a, "stage", None) else None
|
|
35
|
+
try:
|
|
36
|
+
r = runner.run_check(st, over, a.only.split(",") if a.only else None, stages)
|
|
37
|
+
except ValueError as e:
|
|
38
|
+
err(str(e))
|
|
39
|
+
return 2
|
|
40
|
+
findings, lineage, res = r["findings"], r["lineage"], r["store"]
|
|
41
|
+
fmt = "json" if a.json else a.format
|
|
42
|
+
if fmt == "json":
|
|
43
|
+
print(json.dumps({"findings": [f.to_dict() for f in findings], "lineage": lineage, "store": res}, indent=2, default=str))
|
|
44
|
+
elif fmt == "github":
|
|
45
|
+
lvl = {"critical": "error", "high": "error", "medium": "warning", "low": "notice", "info": "notice"}
|
|
46
|
+
for f in findings:
|
|
47
|
+
file = f.evidence.get("file")
|
|
48
|
+
loc = f"file={file}," if file else ""
|
|
49
|
+
print(f"::{lvl[f.severity]} {loc}title={f.check}::{f.title}".replace("\n", " "))
|
|
50
|
+
elif fmt == "markdown":
|
|
51
|
+
from . import incidents as inc_mod, notify
|
|
52
|
+
rows = [{**f.to_dict(), "check_id": f.check} for f in findings]
|
|
53
|
+
print(notify.render_markdown(inc_mod.group(rows, r["project"])))
|
|
54
|
+
print("\n<sub>" + tr("lineage resolved: {ratio}", ratio=f"{lineage['resolved_ratio']:.0%}") + "</sub>")
|
|
55
|
+
else:
|
|
56
|
+
order = {s: i for i, s in enumerate(SEVERITIES)}
|
|
57
|
+
for f in sorted(findings, key=lambda f: (order[f.severity], f.check)):
|
|
58
|
+
print(f"[{f.severity:8}] {f.check:7} {f.title}")
|
|
59
|
+
print("\n" + tr("{n} finding(s) | lineage resolved: {ratio} | new: {new}, resolved: {resolved}", n=len(findings),
|
|
60
|
+
ratio=f"{lineage['resolved_ratio']:.0%}", new=res["new"], resolved=res["resolved"]))
|
|
61
|
+
if a.fail_on:
|
|
62
|
+
gate = SEVERITIES[: SEVERITIES.index(a.fail_on) + 1]
|
|
63
|
+
if any(f.severity in gate for f in findings):
|
|
64
|
+
return 1
|
|
65
|
+
return 0
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def cmd_preflight(a) -> int:
|
|
69
|
+
from . import preflight
|
|
70
|
+
try:
|
|
71
|
+
with _store(a) as store:
|
|
72
|
+
result = preflight.run(store, {k: getattr(a, k) for k in ("target", "base", "root", "base_root", "duckdb", "postgres_env")},
|
|
73
|
+
required=[x.strip() for group in a.require_check for x in group.split(",") if x.strip()],
|
|
74
|
+
max_age_hours=a.max_age_hours, warnings_as_errors=a.warnings_as_errors, fail_on=a.fail_on, revision=a.revision, require_freshness=a.require_source_freshness, accepted_changes=a.accept_change, review_model_logic=a.review_model_logic, baseline_revision=a.base_revision)
|
|
75
|
+
except ValueError as e:
|
|
76
|
+
err(str(e))
|
|
77
|
+
return 2
|
|
78
|
+
if a.format == "json":
|
|
79
|
+
print(json.dumps(result, indent=2, default=str))
|
|
80
|
+
else:
|
|
81
|
+
print(tr("preflight: {status}", status=tr("passed") if result["ok"] else tr("blocked")))
|
|
82
|
+
for gap in result["errors"]:
|
|
83
|
+
line = f"{gap['code']}: {gap['message']}"
|
|
84
|
+
print(f"::error::{line}" if a.format == "github" else line)
|
|
85
|
+
for change in result.get("change_review", {}).get("changes", []):
|
|
86
|
+
if change["requires_review"]:
|
|
87
|
+
print(f"{change['id']} {change['name']}: {change['message']}")
|
|
88
|
+
for f in result["findings"]:
|
|
89
|
+
line = f"[{f['severity']}] {f['check']} {f['title']}"
|
|
90
|
+
print(f"::{'error' if f['id'] in result.get('blocking_findings', []) else 'warning'}::{line}".replace("\n", " ") if a.format == "github" else line)
|
|
91
|
+
print(tr("completed checks: {n}; evidence gaps: {gaps}", n=len(result["completed_checks"]), gaps=len(result["errors"])))
|
|
92
|
+
return 0 if result["ok"] else 1
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def cmd_changes(a) -> int:
|
|
96
|
+
from . import change_review, runner
|
|
97
|
+
try:
|
|
98
|
+
with _store(a) as store:
|
|
99
|
+
o = runner.resolve_options(store, {"target": a.target, "base": a.base})
|
|
100
|
+
if not o["target"] or not o["base"]:
|
|
101
|
+
raise ValueError(tr("change comparison requires candidate and baseline targets"))
|
|
102
|
+
report = change_review.acknowledge(change_review.load(o["target"], o["base"], review_model_logic=a.review_model_logic, baseline_revision=a.base_revision))
|
|
103
|
+
except ValueError as e:
|
|
104
|
+
err(str(e))
|
|
105
|
+
return 2
|
|
106
|
+
if a.format == "json":
|
|
107
|
+
print(json.dumps(report, indent=2))
|
|
108
|
+
else:
|
|
109
|
+
for gap in report["gaps"]:
|
|
110
|
+
print(f"[{gap['side']}] {gap['resource']}: {gap['message']}")
|
|
111
|
+
for change in report["changes"]:
|
|
112
|
+
label = tr("review required") if change["requires_review"] else tr("informational")
|
|
113
|
+
print(f"{change['id']} [{label}] {change['name']}: {change['message']}")
|
|
114
|
+
if change["impact"]:
|
|
115
|
+
print(" " + tr("Known impact: {models}", models=", ".join(n["name"] for n in change["impact"])))
|
|
116
|
+
print(report["note"])
|
|
117
|
+
return 1 if a.fail_on_review and (report["unreviewed"] or report["gaps"]) else 0
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def cmd_rules(a) -> int:
|
|
121
|
+
from . import business_rules, dbt_results, runner
|
|
122
|
+
try:
|
|
123
|
+
with _store(a) as store:
|
|
124
|
+
o = runner.resolve_options(store, {"target": a.target, "root": a.root})
|
|
125
|
+
if not o["target"]:
|
|
126
|
+
raise ValueError(tr("dbt target directory not configured (`intentflow config set dbt.target <dir>` or in the UI)"))
|
|
127
|
+
project = dbt_loader.load(o["target"], o["root"] or Path(o["target"]).parent)
|
|
128
|
+
result = business_rules.build(project, dbt_results.load(o["target"]), store, tag=None if a.all else business_rules.TAG)
|
|
129
|
+
except (ValueError, OSError) as e:
|
|
130
|
+
err(str(e))
|
|
131
|
+
return 2
|
|
132
|
+
if a.format == "json":
|
|
133
|
+
print(json.dumps(result, indent=2, default=str))
|
|
134
|
+
else:
|
|
135
|
+
for rule in result["rules"]:
|
|
136
|
+
print(f"[{rule['status']}] {rule['name']} | {rule['owner'] or '-'} | {', '.join(rule['models'])}")
|
|
137
|
+
print(result["note"])
|
|
138
|
+
return 0
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _parse_value(v: str):
|
|
142
|
+
try:
|
|
143
|
+
return json.loads(v)
|
|
144
|
+
except ValueError:
|
|
145
|
+
return v
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def cmd_config(a) -> int:
|
|
149
|
+
st = _store(a)
|
|
150
|
+
if a.action == "set":
|
|
151
|
+
st.set_setting(a.key, _parse_value(a.value))
|
|
152
|
+
st.audit(os.environ.get("USER", "cli"), "config_set", {"key": a.key})
|
|
153
|
+
elif a.action == "unset":
|
|
154
|
+
st.unset_setting(a.key)
|
|
155
|
+
elif a.action == "get":
|
|
156
|
+
print(json.dumps(st.get_setting(a.key)))
|
|
157
|
+
else:
|
|
158
|
+
for k, v in st.settings().items():
|
|
159
|
+
if not k.startswith("state."):
|
|
160
|
+
print(f"{k} = {json.dumps(v, ensure_ascii=False)}")
|
|
161
|
+
return 0
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def cmd_policy(a) -> int:
|
|
165
|
+
st = _store(a)
|
|
166
|
+
if a.action == "pii-allow":
|
|
167
|
+
cur = list(st.get_setting("policy.pii_allowed_models", []))
|
|
168
|
+
if a.remove and a.name in cur:
|
|
169
|
+
cur.remove(a.name)
|
|
170
|
+
elif not a.remove and a.name not in cur:
|
|
171
|
+
cur.append(a.name)
|
|
172
|
+
st.set_setting("policy.pii_allowed_models", cur)
|
|
173
|
+
elif a.action == "sla":
|
|
174
|
+
st.set_setting(f"policy.sla.{a.name}", {"minutes": float(a.value)}) # name = system:pipeline
|
|
175
|
+
elif a.action == "max-rows":
|
|
176
|
+
st.set_setting("policy.max_estimated_rows", int(a.name))
|
|
177
|
+
elif a.action == "disable-check":
|
|
178
|
+
cur = set(st.get_setting("policy.disabled_checks", []))
|
|
179
|
+
(cur.discard if a.remove else cur.add)(a.name)
|
|
180
|
+
st.set_setting("policy.disabled_checks", sorted(cur))
|
|
181
|
+
elif a.action == "max-age":
|
|
182
|
+
st.set_setting(f"policy.max_age_hours.{a.name}", float(a.value))
|
|
183
|
+
elif a.action == "airflow-target": # target Airflow version: 3 turns on the migration check (AF3xx) in regular runs
|
|
184
|
+
st.set_setting("policy.airflow_target_major", int(a.name))
|
|
185
|
+
for k, v in st.policies().items():
|
|
186
|
+
print(f"{k} = {json.dumps(v, ensure_ascii=False)}")
|
|
187
|
+
return 0
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def cmd_runs(a) -> int:
|
|
191
|
+
from . import runner
|
|
192
|
+
r = runner.collect_runs(_store(a), a.airflow, a.airflow_api, a.kestra, a.prefect, a.dagster, a.airbyte, a.fivetran, a.spark, a.databricks, a.argo, a.mage)
|
|
193
|
+
for e in r["errors"]:
|
|
194
|
+
print(tr("warning: {msg}", msg=e), file=sys.stderr)
|
|
195
|
+
print(tr("{n} run(s) collected", n=r["runs"]))
|
|
196
|
+
return 0 if not r["errors"] or r["runs"] else 1
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def cmd_monitor(a) -> int:
|
|
200
|
+
from . import runner
|
|
201
|
+
n = runner.collect_samples(_store(a), host=a.host or not (a.host or a.docker), docker=a.docker or not (a.host or a.docker))
|
|
202
|
+
print(tr("{n} sample(s)", n=n))
|
|
203
|
+
return 0
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _target(a, st: Store) -> str | None:
|
|
207
|
+
target = a.target or st.get_setting("dbt.target")
|
|
208
|
+
if not target:
|
|
209
|
+
err(tr("pass --target or run `intentflow config set dbt.target <dir>`"))
|
|
210
|
+
return target
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def cmd_lineage(a) -> int:
|
|
214
|
+
st = _store(a)
|
|
215
|
+
target = _target(a, st)
|
|
216
|
+
if not target:
|
|
217
|
+
return 2
|
|
218
|
+
p = dbt_loader.load(target, a.root or Path(target).parent)
|
|
219
|
+
r = lin.build(p, cache=st) # only models whose SQL/schema changed since the last run are recomputed
|
|
220
|
+
st.flush()
|
|
221
|
+
from . import external
|
|
222
|
+
decl = a.declared or str(Path(a.root or Path(target).parent) / external.DECLARED_FILE)
|
|
223
|
+
if a.alias or a.unmatched or a.coverage:
|
|
224
|
+
if a.alias:
|
|
225
|
+
ds, _, model = a.alias.partition("=")
|
|
226
|
+
if not ds or not model:
|
|
227
|
+
err(tr("use --alias DATASET=MODEL"))
|
|
228
|
+
return 2
|
|
229
|
+
if external.match_dataset(p, model) is None:
|
|
230
|
+
err(tr("'{model}' does not match a single project model", model=model))
|
|
231
|
+
return 2
|
|
232
|
+
external.add_alias(decl, ds, model)
|
|
233
|
+
print(tr("alias saved in {file}: {dataset} → {model}", file=decl, dataset=ds, model=model))
|
|
234
|
+
reads = external.load(st, decl, p)
|
|
235
|
+
if a.unmatched:
|
|
236
|
+
for ds, v in sorted(external.unmatched(p, reads).items()):
|
|
237
|
+
sug = external.suggest(p, ds)
|
|
238
|
+
print(tr("{reason}: {dataset} (jobs: {jobs})", reason=tr(external.REASONS[v["reason"]]), dataset=ds, jobs=", ".join(v["jobs"]))
|
|
239
|
+
+ (" " + tr("suggestion: {names}", names=", ".join(sug)) if sug else ""))
|
|
240
|
+
if a.coverage:
|
|
241
|
+
for c in external.coverage(reads):
|
|
242
|
+
print(tr("conservative propagation: {job} (no feeds: {datasets})", job=c["job"], datasets=", ".join(c["reads_without_feeds"])))
|
|
243
|
+
if a.base:
|
|
244
|
+
from . import lineage_api
|
|
245
|
+
d = lineage_api.diff(lineage_api.load(a.base, a.base_root, cache=st), (p, r))
|
|
246
|
+
if a.json:
|
|
247
|
+
print(json.dumps(d, indent=1))
|
|
248
|
+
return 0
|
|
249
|
+
for x in d["models_added"]:
|
|
250
|
+
print(f"+ model {x}")
|
|
251
|
+
for x in d["models_removed"]:
|
|
252
|
+
print(f"- model {x}")
|
|
253
|
+
for e in d["added"]:
|
|
254
|
+
print(f"+ {e['src']} --{e['kind']}--> {e['dst']}")
|
|
255
|
+
for e in d["removed"]:
|
|
256
|
+
print(f"- {e['src']} --{e['kind']}--> {e['dst']}")
|
|
257
|
+
for e in d["changed"]:
|
|
258
|
+
print(f"~ {e['src']} --{e['from']}→{e['to']}--> {e['dst']}")
|
|
259
|
+
return 0
|
|
260
|
+
if a.json:
|
|
261
|
+
print(json.dumps([{"src": f"{p.nodes[e.src].name}.{e.src_col}", "dst": f"{p.nodes[e.dst].name}.{e.dst_col}", "kind": e.kind,
|
|
262
|
+
"masked": e.masked} for e in r.edges if e.src in p.nodes and e.dst in p.nodes], indent=1))
|
|
263
|
+
return 0
|
|
264
|
+
if a.column:
|
|
265
|
+
m, _, c = a.column.rpartition(".")
|
|
266
|
+
uid = next((u for u, n in p.nodes.items() if n.name == m), None)
|
|
267
|
+
if not m or uid is None:
|
|
268
|
+
err(tr("model '{model}' not found", model=m or a.column))
|
|
269
|
+
return 2
|
|
270
|
+
for e in r.upstream_of(uid, c):
|
|
271
|
+
print(f"{p.nodes[e.src].name}.{e.src_col} --{e.kind}{' (' + tr('masked') + ')' if e.masked else ''}--> {m}.{c}")
|
|
272
|
+
for e in r.downstream_of(uid, c):
|
|
273
|
+
print(f"{m}.{c} --{e.kind}--> {p.nodes[e.dst].name}.{e.dst_col}")
|
|
274
|
+
if a.impact: # transitive closure, including indirect dependency (join/filter)
|
|
275
|
+
from . import lineage_api
|
|
276
|
+
for x in lineage_api.impact(p, r, m, c, external=external.load(st, decl, p))["affected"]:
|
|
277
|
+
print(tr("impact d={d}: ", d=x["distance"]) + ("job " if x.get("kind") == "job" else "") + x["name"]
|
|
278
|
+
+ (" (" + tr("via job {job}", job=x["via_job"]) + ")" if x.get("via_job") else "")
|
|
279
|
+
+ (f" ({', '.join(x['columns'])})" if x["columns"] else "")
|
|
280
|
+
+ (" " + tr("via {what}", what=", ".join(x["indirect_via"])) if x.get("indirect_via") else ""))
|
|
281
|
+
elif not (a.alias or a.unmatched or a.coverage):
|
|
282
|
+
print(json.dumps(r.precision_report))
|
|
283
|
+
for n, c, why in r.unresolved:
|
|
284
|
+
print(" " + tr("unresolved: {column}: {why}", column=f"{p.nodes[n].name}.{c}", why=tr(why)))
|
|
285
|
+
return 0
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def cmd_notify(a) -> int:
|
|
289
|
+
from . import incidents as inc_mod, notify
|
|
290
|
+
st = _store(a)
|
|
291
|
+
sinks, routes = st.get_setting("notify.sinks", []), st.get_setting("notify.routes", [])
|
|
292
|
+
if a.action == "add-sink":
|
|
293
|
+
if a.type not in notify.sink_types():
|
|
294
|
+
err(tr("unknown sink type: {type}", type=a.type))
|
|
295
|
+
return 2
|
|
296
|
+
sink = {"name": a.name, "type": a.type}
|
|
297
|
+
for k in ("url_env", "to", "repo", "pr", "api", "token_env", "min_severity"):
|
|
298
|
+
v = getattr(a, k, None)
|
|
299
|
+
if v:
|
|
300
|
+
sink[k] = v
|
|
301
|
+
st.set_setting("notify.sinks", [s for s in sinks if s["name"] != a.name] + [sink])
|
|
302
|
+
elif a.action == "route":
|
|
303
|
+
r = {"sink": a.name}
|
|
304
|
+
for k in ("owner", "check_prefix", "min_severity"):
|
|
305
|
+
v = getattr(a, k, None)
|
|
306
|
+
if v:
|
|
307
|
+
r[k] = v
|
|
308
|
+
st.set_setting("notify.routes", routes + [r])
|
|
309
|
+
elif a.action == "send":
|
|
310
|
+
target = st.get_setting("dbt.target")
|
|
311
|
+
proj = dbt_loader.load(target, Path(target).parent) if target else None
|
|
312
|
+
incs = inc_mod.group(st.findings("open"), proj)
|
|
313
|
+
for entry in notify.send(st, incs, dry_run=a.dry_run):
|
|
314
|
+
print(f"{entry['incident']} -> {entry['sink']}: {entry['status']}")
|
|
315
|
+
return 0
|
|
316
|
+
print(json.dumps({"sinks": st.get_setting("notify.sinks", []), "routes": st.get_setting("notify.routes", [])}, ensure_ascii=False, indent=2))
|
|
317
|
+
return 0
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def cmd_openlineage(a) -> int:
|
|
321
|
+
from . import openlineage
|
|
322
|
+
if a.action == "serve":
|
|
323
|
+
openlineage.serve(a.store, a.port, a.host, tls_cert=a.tls_cert, tls_key=a.tls_key, behind_proxy=a.behind_proxy)
|
|
324
|
+
return 0
|
|
325
|
+
if a.action == "emit":
|
|
326
|
+
from . import ol_emit
|
|
327
|
+
target = a.target or _store(a).get_setting("dbt.target")
|
|
328
|
+
if not target or not a.url:
|
|
329
|
+
err(tr("pass the catalog --url and --target (or configure dbt.target)"))
|
|
330
|
+
return 1
|
|
331
|
+
proj = dbt_loader.load(target, Path(target).parent)
|
|
332
|
+
evs = ol_emit.build_events(proj, lin.build(proj, cache=_store(a)))
|
|
333
|
+
if a.dry_run:
|
|
334
|
+
print(json.dumps(evs, ensure_ascii=False, indent=1))
|
|
335
|
+
return 0
|
|
336
|
+
tok = os.environ.get("OPENLINEAGE_API_KEY")
|
|
337
|
+
r = ol_emit.emit(a.url, evs, {"Authorization": f"Bearer {tok}"} if tok else None)
|
|
338
|
+
print(tr("{sent}/{total} event(s) sent", sent=r["sent"], total=len(evs)))
|
|
339
|
+
for e in r["errors"]:
|
|
340
|
+
err(e)
|
|
341
|
+
return 0 if not r["errors"] else 1
|
|
342
|
+
r = openlineage.ingest_file(_store(a), a.file)
|
|
343
|
+
print(tr("{runs} run(s), {edges} column edge(s)", runs=r["runs"], edges=r["column_edges"]))
|
|
344
|
+
return 0
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def cmd_watch(a) -> int:
|
|
348
|
+
from . import runner
|
|
349
|
+
interval = a.interval or float(_store(a).get_setting("watch.interval_s", 300))
|
|
350
|
+
print(tr("scheduler running (every {s}s). Ctrl-C to stop.", s=f"{interval:g}"))
|
|
351
|
+
try:
|
|
352
|
+
runner.watch(_store(a), interval, a.iterations)
|
|
353
|
+
except KeyboardInterrupt:
|
|
354
|
+
pass
|
|
355
|
+
return 0
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def cmd_backup(a) -> int:
|
|
359
|
+
n = _store(a).backup(a.dest)
|
|
360
|
+
remote = "://" in a.dest
|
|
361
|
+
print(tr("backup written to {dest} ({n} {unit})", dest=a.dest.split("@")[-1] if remote else a.dest, n=n, unit=tr("rows") if remote else "bytes"))
|
|
362
|
+
return 0
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def cmd_migrate_store(a) -> int:
|
|
366
|
+
from .store import copy_store
|
|
367
|
+
src, dst = Store(a.src), Store(a.dst)
|
|
368
|
+
if a.dst_has_data_ok is False and any(dst.con.execute(f"select 1 from {t} limit 1").fetchone() for t in ("findings", "users", "settings")):
|
|
369
|
+
err(tr("the destination already has data; use --overwrite to replace it"))
|
|
370
|
+
return 1
|
|
371
|
+
n = copy_store(src, dst)
|
|
372
|
+
print(tr("{n} rows copied from {src} to {dst}", n=n, src=src.backend, dst=dst.backend))
|
|
373
|
+
return 0
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def cmd_dbt_cloud(a) -> int:
|
|
377
|
+
from .orchestrators.dbtcloud import DbtCloudClient
|
|
378
|
+
st = _store(a)
|
|
379
|
+
acc = a.account or st.get_setting("dbt_cloud.account_id")
|
|
380
|
+
if not acc:
|
|
381
|
+
err(tr("pass --account or configure dbt_cloud.account_id"))
|
|
382
|
+
return 1
|
|
383
|
+
c = DbtCloudClient(a.host or st.get_setting("dbt_cloud.host"), acc)
|
|
384
|
+
if a.action == "runs":
|
|
385
|
+
for r in c.runs(a.limit):
|
|
386
|
+
print(f"{r.state:8} {r.pipeline:30} #{r.run_id} {'' if r.duration is None else f'{r.duration:.0f}s'}")
|
|
387
|
+
return 0
|
|
388
|
+
job = a.job or st.get_setting("dbt_cloud.job_id")
|
|
389
|
+
if not job:
|
|
390
|
+
err(tr("pass --job or configure dbt_cloud.job_id"))
|
|
391
|
+
return 1
|
|
392
|
+
r = c.pull_artifacts(job, a.dest, a.run)
|
|
393
|
+
print(tr("{n} artifact(s) in {dir}", n=len(r["files"]), dir=r["dir"]) + (" (" + tr("missing: {names}", names=", ".join(r["missing"])) + ")" if r["missing"] else ""))
|
|
394
|
+
print(tr("use: intentflow config set dbt.target {dir}", dir=r["dir"]))
|
|
395
|
+
return 0
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def cmd_lineage_verify(a) -> int:
|
|
399
|
+
from . import lineage_oracle
|
|
400
|
+
target = a.target or _store(a).get_setting("dbt.target")
|
|
401
|
+
db = a.duckdb or _store(a).get_setting("warehouse.duckdb")
|
|
402
|
+
if not (target and db):
|
|
403
|
+
err(tr("pass --target and --duckdb (or configure dbt.target and warehouse.duckdb)"))
|
|
404
|
+
return 1
|
|
405
|
+
proj = dbt_loader.load(target, Path(target).parent)
|
|
406
|
+
res = lin.build(proj)
|
|
407
|
+
rep = lineage_oracle.run(proj, res, db, a.package, a.max_columns, a.model, only_used=a.only_used, only_sources=a.source, sample_rows=a.sample_rows,
|
|
408
|
+
progress=lambda i, n, c: print(f" [{i}/{n}] {c}", file=sys.stderr) if a.verbose else None)
|
|
409
|
+
if a.out:
|
|
410
|
+
Path(a.out).write_text(json.dumps(rep, ensure_ascii=False, indent=1))
|
|
411
|
+
d, m = rep["direct"], rep["model_level"]
|
|
412
|
+
pct = lambda v: "n/a" if v is None else f"{v:.1%}"
|
|
413
|
+
print(tr("{models} model(s), {cols} source column(s) perturbed in {s}s", models=rep["models"], cols=rep["source_columns_tested"], s=rep["seconds"]))
|
|
414
|
+
print(" " + tr("Direct lineage (column by column):"))
|
|
415
|
+
print(" " + tr("hits {tp} · suspected false positives {fp} · precision ≥ {p}", tp=d["tp"], fp=d["fp_suspect"], p=pct(d["precision_lower_bound"])))
|
|
416
|
+
print(" " + tr("changed only through indirect dependency (join/filter/...): {n} · truly lost: {lost}", n=d["changed_but_only_indirect"], lost=d["lost"]))
|
|
417
|
+
print(" " + tr("With indirect dependency (per model):"))
|
|
418
|
+
print(" " + tr("hits {tp} · suspected false positives {fp} · lost {fn} · precision ≥ {p} · recall {r}",
|
|
419
|
+
tp=m["tp"], fp=m["fp_suspect"], fn=m["fn"], p=pct(m["precision_lower_bound"]), r=pct(m["recall"])))
|
|
420
|
+
for k, tag in (("false_negatives", "LOST"), ("suspect_false_positives", "FP?")):
|
|
421
|
+
for x in rep[k][:a.show]:
|
|
422
|
+
print(f" {tag} {x}")
|
|
423
|
+
return 0
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def cmd_secrets(a) -> int:
|
|
427
|
+
from .store import migrate_secrets, rotate_secrets
|
|
428
|
+
st = _store(a)
|
|
429
|
+
if a.action == "status":
|
|
430
|
+
print(json.dumps(st.box.status()))
|
|
431
|
+
return 0 if st.box.enabled else 1
|
|
432
|
+
try:
|
|
433
|
+
print(json.dumps((rotate_secrets if a.action == "rotate" else migrate_secrets)(st)))
|
|
434
|
+
except RuntimeError as e:
|
|
435
|
+
err(str(e))
|
|
436
|
+
return 1
|
|
437
|
+
return 0
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def cmd_otel_push(a) -> int:
|
|
441
|
+
from . import otel
|
|
442
|
+
try:
|
|
443
|
+
st = otel.push(_store(a), a.endpoint)
|
|
444
|
+
except Exception as e:
|
|
445
|
+
err(str(e))
|
|
446
|
+
return 1
|
|
447
|
+
print(tr("metrics sent (HTTP {status})", status=st))
|
|
448
|
+
return 0
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def cmd_sqlmesh_export(a) -> int:
|
|
452
|
+
from . import sqlmesh_loader
|
|
453
|
+
data = sqlmesh_loader.export(a.project, a.gateway)
|
|
454
|
+
out = Path(a.output or Path(a.project) / sqlmesh_loader.SNAPSHOT)
|
|
455
|
+
out.write_text(json.dumps(data, ensure_ascii=False, indent=1))
|
|
456
|
+
print(tr("{n} model(s) exported to {file}", n=len(data["models"]), file=out))
|
|
457
|
+
return 0
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def cmd_airflow3(a) -> int:
|
|
461
|
+
from .checks.airflow3 import migrate_dir
|
|
462
|
+
res = migrate_dir(a.dags, write=a.write)
|
|
463
|
+
if a.json:
|
|
464
|
+
print(json.dumps(res, ensure_ascii=False, indent=1))
|
|
465
|
+
return 1 if any(r["issues"] for r in res) and not a.write else 0
|
|
466
|
+
total = sum(len(r["issues"]) for r in res)
|
|
467
|
+
for r in res:
|
|
468
|
+
print(f"\n{r['file']}")
|
|
469
|
+
for p in r["issues"]:
|
|
470
|
+
print(f" L{p['line']:<4} {p['rule']} [{p['severity']}] {p['message']}\n → {p['recommendation']}{' (auto)' if p['fixable'] else ''}")
|
|
471
|
+
if r["written"]:
|
|
472
|
+
print(" " + tr("rewritten: {n} import(s); original in .af2.bak; {left} manual item(s) left", n=r["rewritable"], left=len(r["remaining"])))
|
|
473
|
+
fix = sum(r["rewritable"] for r in res)
|
|
474
|
+
print("\n" + tr("{files} file(s) with changes, {total} item(s) to handle, {fix} mechanical rewrite(s) {state}.", files=len(res), total=total, fix=fix,
|
|
475
|
+
state=tr("applied") if a.write else tr("possible (use --write)")))
|
|
476
|
+
return 1 if total and not a.write else 0
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def cmd_prune(a) -> int:
|
|
480
|
+
st = _store(a)
|
|
481
|
+
target, keep = st.get_setting("dbt.target"), None
|
|
482
|
+
if target: # without the current project we cannot tell stale lineage cache entries from live ones
|
|
483
|
+
keep = lin.cache_keys(dbt_loader.load(target, st.get_setting("dbt.root") or Path(target).parent))
|
|
484
|
+
print(json.dumps(st.prune(a.days, keep_lineage=keep)))
|
|
485
|
+
return 0
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def cmd_fp(a) -> int:
|
|
489
|
+
_store(a).mark_false_positive(a.id, a.user, a.reason or "")
|
|
490
|
+
print(tr("marked as false positive (will not reopen)"))
|
|
491
|
+
return 0
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
def cmd_stats(a) -> int:
|
|
495
|
+
for c in _store(a).check_stats():
|
|
496
|
+
print(f"{c['check']:8} total={c['total']:3} open={c['open']:3} resolved={c['resolved']:3} false+={c['false_positive']:3} "
|
|
497
|
+
f"fp_rate={'—' if c['fp_rate'] is None else c['fp_rate']}")
|
|
498
|
+
return 0
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def cmd_diff(a) -> int:
|
|
502
|
+
from . import datadiff, warehouses
|
|
503
|
+
st = _store(a)
|
|
504
|
+
wh = warehouses.connect(lambda k: (a.duckdb if k == "warehouse.duckdb" and a.duckdb else a.postgres_env if k == "warehouse.postgres_env" and a.postgres_env
|
|
505
|
+
else st.get_setting(k)))
|
|
506
|
+
if wh is None:
|
|
507
|
+
err(tr("pass --duckdb/--postgres-env or configure `warehouse.type` (or `warehouse.duckdb`)"))
|
|
508
|
+
return 2
|
|
509
|
+
base, head = a.base, a.head
|
|
510
|
+
if a.model:
|
|
511
|
+
target = a.target or st.get_setting("dbt.target")
|
|
512
|
+
p = dbt_loader.load(target, Path(target).parent)
|
|
513
|
+
n = next((x for x in p.nodes.values() if x.name == a.model), None)
|
|
514
|
+
if n is None:
|
|
515
|
+
err(tr("model '{model}' not found", model=a.model))
|
|
516
|
+
return 2
|
|
517
|
+
parts = [x.strip('"`[]') for x in n.relation.split(".")]
|
|
518
|
+
if len(parts) != 3:
|
|
519
|
+
err(tr("model '{model}' not found", model=a.model))
|
|
520
|
+
return 2
|
|
521
|
+
db, sch, tbl = parts
|
|
522
|
+
q = wh.quote # engine quoting: ANSI double quotes are string literals in BigQuery/MySQL/Databricks
|
|
523
|
+
base = f"{q(db)}.{q(a.base_schema or sch)}.{q(tbl)}"
|
|
524
|
+
head = f"{q(db)}.{q(a.head_schema or sch)}.{q(tbl)}"
|
|
525
|
+
try:
|
|
526
|
+
d = datadiff.diff_relations(wh, base, head, a.key.split(","), a.sample, sample_pct=a.sample_pct)
|
|
527
|
+
except Exception as e:
|
|
528
|
+
err(str(e))
|
|
529
|
+
return 2
|
|
530
|
+
finally:
|
|
531
|
+
wh.close()
|
|
532
|
+
print(json.dumps(d, indent=2, default=str) if a.json else datadiff.to_markdown(d))
|
|
533
|
+
return 0 if d["identical"] or not a.fail_on_diff else 1
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def cmd_risks(a) -> int:
|
|
537
|
+
from . import external, risks
|
|
538
|
+
st = _store(a)
|
|
539
|
+
target = _target(a, st)
|
|
540
|
+
if not target:
|
|
541
|
+
return 2
|
|
542
|
+
p = dbt_loader.load(target, a.root or Path(target).parent)
|
|
543
|
+
res = lin.build(p, cache=st)
|
|
544
|
+
st.flush()
|
|
545
|
+
decl = a.declared or st.get_setting("lineage.declared") or str(Path(a.root or Path(target).parent) / external.DECLARED_FILE)
|
|
546
|
+
rep = risks.build(p, res, st, base=a.base, declared=decl, reads=external.load(st, decl, p))
|
|
547
|
+
print(json.dumps(rep, ensure_ascii=False, indent=1) if a.json else risks.to_markdown(rep))
|
|
548
|
+
return 1 if (a.fail_on_high and rep["summary"]["high"]) else 0
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
def cmd_overview(a) -> int:
|
|
552
|
+
print(json.dumps(ov.build(_store(a)), indent=2, default=str))
|
|
553
|
+
return 0
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
def cmd_ui(a) -> int:
|
|
557
|
+
from .web import serve
|
|
558
|
+
serve(a.store, a.port, a.host, a.tls_cert, a.tls_key, a.behind_proxy)
|
|
559
|
+
return 0
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
def cmd_user(a) -> int:
|
|
563
|
+
st = _store(a)
|
|
564
|
+
try:
|
|
565
|
+
if a.action == "add":
|
|
566
|
+
tok = st.add_user(a.name, a.role, expires_days=a.expires_days)
|
|
567
|
+
st.audit(os.environ.get("USER", "cli"), "user_add", {"name": a.name, "role": a.role})
|
|
568
|
+
print(tr("user {name} ({role}) created.\nToken (save it now; it will not be shown again):\n{token}", name=a.name, role=a.role, token=tok))
|
|
569
|
+
elif a.action == "rotate":
|
|
570
|
+
print(tr("new token (save it now):") + "\n" + st.rotate_token(a.name, a.expires_days))
|
|
571
|
+
elif a.action in ("disable", "enable"):
|
|
572
|
+
st.set_user(a.name, disabled=(a.action == "disable"))
|
|
573
|
+
print("ok")
|
|
574
|
+
elif a.action == "role":
|
|
575
|
+
st.set_user(a.name, role=a.role)
|
|
576
|
+
print("ok")
|
|
577
|
+
elif a.action == "mfa-recovery":
|
|
578
|
+
print(tr("recovery codes (save them; each works once):") + "\n" + "\n".join(st.mfa_recovery_codes(a.name)))
|
|
579
|
+
elif a.action == "mfa-begin":
|
|
580
|
+
from . import totp
|
|
581
|
+
sec = st.mfa_begin(a.name)
|
|
582
|
+
print(tr("TOTP secret for {name}: {secret}", name=a.name, secret=sec) + f"\n{totp.uri(sec, a.name)}\n"
|
|
583
|
+
+ tr("confirm with: intentflow user mfa-confirm {name} --code 123456", name=a.name))
|
|
584
|
+
elif a.action == "mfa-confirm":
|
|
585
|
+
print(tr("MFA enabled") if st.mfa_confirm(a.name, a.code or "") else tr("invalid code"))
|
|
586
|
+
return 0 if st.user_record(a.name)["totp_enabled"] else 1
|
|
587
|
+
elif a.action == "mfa-disable":
|
|
588
|
+
st.mfa_disable(a.name)
|
|
589
|
+
print(tr("MFA disabled"))
|
|
590
|
+
else:
|
|
591
|
+
for u in st.users():
|
|
592
|
+
print(f"{u['name']:24} {u['role']:9} {tr('disabled') if u['disabled'] else tr('active')}")
|
|
593
|
+
except ValueError as e:
|
|
594
|
+
err(str(e))
|
|
595
|
+
return 1
|
|
596
|
+
return 0
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
def cmd_assign(a) -> int:
|
|
600
|
+
try:
|
|
601
|
+
_store(a).assign(a.id, None if a.assignee == "-" else a.assignee, a.user)
|
|
602
|
+
except ValueError as e:
|
|
603
|
+
err(str(e))
|
|
604
|
+
return 1
|
|
605
|
+
print("ok")
|
|
606
|
+
return 0
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
def cmd_note(a) -> int:
|
|
610
|
+
try:
|
|
611
|
+
_store(a).add_note(a.id, a.user, a.text)
|
|
612
|
+
except ValueError as e:
|
|
613
|
+
err(str(e))
|
|
614
|
+
return 1
|
|
615
|
+
print("ok")
|
|
616
|
+
return 0
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
def cmd_ack(a) -> int:
|
|
620
|
+
until = time.time() + a.days * 86400 if a.days else None
|
|
621
|
+
_store(a).ack(a.id, a.user, a.reason, until)
|
|
622
|
+
print("ok")
|
|
623
|
+
return 0
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
def main(argv=None) -> int:
|
|
627
|
+
from . import notify
|
|
628
|
+
ap = argparse.ArgumentParser(prog="intentflow", description=__doc__)
|
|
629
|
+
ap.add_argument("--version", action="version", version=f"intentflow {__import__('intentflow').__version__}")
|
|
630
|
+
ap.add_argument("--store", default=os.environ.get("INTENTFLOW_STORE", ".intentflow.db"))
|
|
631
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
632
|
+
user_default = os.environ.get("USER", "unknown")
|
|
633
|
+
|
|
634
|
+
c = sub.add_parser("check", help=tr("run the preventive checks"))
|
|
635
|
+
c.add_argument("--target", help=tr("dbt target/ directory (default: saved setting `dbt.target`)"))
|
|
636
|
+
c.add_argument("--root", help=tr("dbt project root (default: parent of the target)"))
|
|
637
|
+
c.add_argument("--base", help=tr("target/ of the previous version (schema diff and impact)"))
|
|
638
|
+
c.add_argument("--base-root")
|
|
639
|
+
c.add_argument("--airflow-dags")
|
|
640
|
+
c.add_argument("--kestra-flows")
|
|
641
|
+
c.add_argument("--duckdb", help=tr("DuckDB file for probes"))
|
|
642
|
+
c.add_argument("--postgres-env", help=tr("variable holding the PostgreSQL URL for probes"))
|
|
643
|
+
c.add_argument("--save", action="store_true", help=tr("save the given sources as the default configuration"))
|
|
644
|
+
c.add_argument("--only", help=tr("comma-separated ids/prefixes (e.g. SQL,DBT001)"))
|
|
645
|
+
c.add_argument("--fail-on", choices=SEVERITIES)
|
|
646
|
+
c.add_argument("--json", action="store_true")
|
|
647
|
+
c.add_argument("--format", choices=["text", "json", "markdown", "github"], default="text")
|
|
648
|
+
c.add_argument("--stage", help=tr("limit to stages (pre-merge,pre-run,continuous)"))
|
|
649
|
+
c.set_defaults(fn=cmd_check)
|
|
650
|
+
|
|
651
|
+
gt = sub.add_parser("gate", help=tr("gate before execution (use in Airflow/Kestra before dbt run)"))
|
|
652
|
+
for arg in ("--target", "--root", "--base", "--base-root", "--airflow-dags", "--kestra-flows", "--duckdb", "--postgres-env", "--only"):
|
|
653
|
+
gt.add_argument(arg)
|
|
654
|
+
gt.add_argument("--fail-on", choices=SEVERITIES, default="critical")
|
|
655
|
+
gt.add_argument("--format", choices=["text", "json", "markdown", "github"], default="text")
|
|
656
|
+
gt.add_argument("--stage", default="pre-run,pre-merge")
|
|
657
|
+
gt.set_defaults(fn=cmd_check, save=False, json=False)
|
|
658
|
+
|
|
659
|
+
pf = sub.add_parser("preflight", help=tr("block promotion when full dbt build evidence or required checks are incomplete"))
|
|
660
|
+
for arg in ("--target", "--base", "--root"):
|
|
661
|
+
pf.add_argument(arg, required=True)
|
|
662
|
+
for arg in ("--base-root", "--duckdb", "--postgres-env"):
|
|
663
|
+
pf.add_argument(arg)
|
|
664
|
+
pf.add_argument("--require-check", action="append", default=[], help=tr("additional required check ids, comma separated"))
|
|
665
|
+
pf.add_argument("--max-age-hours", type=float, default=24)
|
|
666
|
+
pf.add_argument("--revision", help=tr("expected INTENTFLOW_REVISION in dbt custom artifact metadata"))
|
|
667
|
+
pf.add_argument("--base-revision", help=tr("expected deployed baseline revision in manifest and catalog"))
|
|
668
|
+
pf.add_argument("--require-source-freshness", action="store_true", help=tr("require current sources.json evidence for every declared source SLA"))
|
|
669
|
+
pf.add_argument("--warnings-as-errors", action="store_true")
|
|
670
|
+
pf.add_argument("--accept-change", action="append", default=[], metavar="ID=REASON", help=tr("acknowledge one exact change with a reason; does not waive other checks"))
|
|
671
|
+
pf.add_argument("--review-model-logic", action="store_true", help=tr("also require review of changed model SQL, Python or macro dependencies"))
|
|
672
|
+
pf.add_argument("--fail-on", choices=SEVERITIES, default="high")
|
|
673
|
+
pf.add_argument("--format", choices=["text", "json", "github"], default="text")
|
|
674
|
+
pf.set_defaults(fn=cmd_preflight)
|
|
675
|
+
|
|
676
|
+
ch = sub.add_parser("changes", help=tr("preview candidate changes and known impact against a trusted baseline"))
|
|
677
|
+
ch.add_argument("--target")
|
|
678
|
+
ch.add_argument("--base")
|
|
679
|
+
ch.add_argument("--format", choices=["text", "json"], default="text")
|
|
680
|
+
ch.add_argument("--fail-on-review", action="store_true")
|
|
681
|
+
ch.add_argument("--review-model-logic", action="store_true")
|
|
682
|
+
ch.add_argument("--base-revision")
|
|
683
|
+
ch.set_defaults(fn=cmd_changes)
|
|
684
|
+
|
|
685
|
+
br = sub.add_parser("rules", help=tr("business rules declared as dbt tests, results and recent history"))
|
|
686
|
+
br.add_argument("--target")
|
|
687
|
+
br.add_argument("--root")
|
|
688
|
+
br.add_argument("--all", action="store_true", help=tr("include tests without the business_rule tag"))
|
|
689
|
+
br.add_argument("--format", choices=["text", "json"], default="text")
|
|
690
|
+
br.set_defaults(fn=cmd_rules)
|
|
691
|
+
|
|
692
|
+
nt = sub.add_parser("notify", help=tr("outputs (Slack, webhook, e-mail, GitHub PR) and routes"))
|
|
693
|
+
nt.add_argument("action", choices=["list", "add-sink", "route", "send"])
|
|
694
|
+
nt.add_argument("name", nargs="?")
|
|
695
|
+
nt.add_argument("--type", help=", ".join(notify.sink_types()))
|
|
696
|
+
for opt in ("--url-env", "--to", "--repo", "--pr", "--api", "--token-env", "--owner", "--check-prefix"):
|
|
697
|
+
nt.add_argument(opt)
|
|
698
|
+
nt.add_argument("--min-severity", choices=SEVERITIES)
|
|
699
|
+
nt.add_argument("--dry-run", action="store_true")
|
|
700
|
+
nt.set_defaults(fn=cmd_notify)
|
|
701
|
+
|
|
702
|
+
r = sub.add_parser("runs", help=tr("collect runs from orchestrators"))
|
|
703
|
+
r.add_argument("--airflow")
|
|
704
|
+
r.add_argument("--airflow-api", choices=["v1", "v2"])
|
|
705
|
+
r.add_argument("--kestra")
|
|
706
|
+
r.add_argument("--argo", help=tr("Argo Server URL (token in ARGO_TOKEN; namespace in argo.namespace)"))
|
|
707
|
+
r.add_argument("--mage", help=tr("Mage URL"))
|
|
708
|
+
r.add_argument("--spark", help=tr("Spark UI/History Server URL (e.g. http://driver:4040)"))
|
|
709
|
+
r.add_argument("--databricks", help=tr("workspace host (token in DATABRICKS_TOKEN)"))
|
|
710
|
+
for opt in ("--airbyte", "--fivetran", "--prefect", "--dagster"):
|
|
711
|
+
r.add_argument(opt)
|
|
712
|
+
r.set_defaults(fn=cmd_runs)
|
|
713
|
+
|
|
714
|
+
m = sub.add_parser("monitor", help=tr("sample memory of the host/containers/pools"))
|
|
715
|
+
m.add_argument("--host", action="store_true")
|
|
716
|
+
m.add_argument("--docker", action="store_true")
|
|
717
|
+
m.set_defaults(fn=cmd_monitor)
|
|
718
|
+
|
|
719
|
+
l = sub.add_parser("lineage", help=tr("column lineage / precision report"))
|
|
720
|
+
l.add_argument("--target", help=tr("default: saved setting `dbt.target`"))
|
|
721
|
+
l.add_argument("--root")
|
|
722
|
+
l.add_argument("--column", help=tr("model.column"))
|
|
723
|
+
l.add_argument("--declared", help=tr("hand-declared lineage (default: <root>/intentflow.lineage.json)"))
|
|
724
|
+
l.add_argument("--alias", help=tr("DATASET=MODEL: save an alias in intentflow.lineage.json"))
|
|
725
|
+
l.add_argument("--coverage", action="store_true", help=tr("jobs whose propagation through outputs is conservative (reads without `feeds`)"))
|
|
726
|
+
l.add_argument("--unmatched", action="store_true", help=tr("list external job datasets that do not match a model (missing/ambiguous)"))
|
|
727
|
+
l.add_argument("--base", help=tr("target/ of the previous version: print column-lineage changes (+ added, - removed, ~ kind changed)"))
|
|
728
|
+
l.add_argument("--base-root")
|
|
729
|
+
l.add_argument("--json", action="store_true", help=tr("JSON: every column edge, or the diff with --base"))
|
|
730
|
+
l.add_argument("--impact", action="store_true", help=tr("with --column: also list the transitive downstream impact"))
|
|
731
|
+
l.set_defaults(fn=cmd_lineage)
|
|
732
|
+
|
|
733
|
+
d = sub.add_parser("diff", help=tr("data diff between two relations (runs in the warehouse)"))
|
|
734
|
+
d.add_argument("--base")
|
|
735
|
+
d.add_argument("--head")
|
|
736
|
+
d.add_argument("--model", help=tr("dbt model (uses --base-schema/--head-schema)"))
|
|
737
|
+
d.add_argument("--base-schema")
|
|
738
|
+
d.add_argument("--head-schema")
|
|
739
|
+
d.add_argument("--target")
|
|
740
|
+
d.add_argument("--key", required=True, help=tr("key column(s), comma-separated"))
|
|
741
|
+
d.add_argument("--sample", type=int, default=5)
|
|
742
|
+
d.add_argument("--sample-pct", type=float, default=None, help=tr("compare only ~N %% of the keys (hash); for huge tables"))
|
|
743
|
+
d.add_argument("--duckdb")
|
|
744
|
+
d.add_argument("--postgres-env")
|
|
745
|
+
d.add_argument("--json", action="store_true")
|
|
746
|
+
d.add_argument("--fail-on-diff", action="store_true")
|
|
747
|
+
d.set_defaults(fn=cmd_diff)
|
|
748
|
+
|
|
749
|
+
ol = sub.add_parser("openlineage", help=tr("OpenLineage: ingest <file> | serve | emit (send the project lineage to a catalog)"))
|
|
750
|
+
ol.add_argument("action", choices=["ingest", "serve", "emit"])
|
|
751
|
+
ol.add_argument("file", nargs="?")
|
|
752
|
+
ol.add_argument("--url", help=tr("emit: catalog base URL (Marquez/DataHub/OpenMetadata); token in OPENLINEAGE_API_KEY"))
|
|
753
|
+
ol.add_argument("--target", help=tr("emit: project (dbt target or SQLMesh)"))
|
|
754
|
+
ol.add_argument("--dry-run", action="store_true")
|
|
755
|
+
ol.add_argument("--port", type=int, default=5000)
|
|
756
|
+
ol.add_argument("--host", default="127.0.0.1", help=tr("serve: outside loopback requires INTENTFLOW_OL_TOKEN"))
|
|
757
|
+
ol.add_argument("--tls-cert")
|
|
758
|
+
ol.add_argument("--tls-key")
|
|
759
|
+
ol.add_argument("--behind-proxy", action="store_true", help=tr("TLS terminated at a reverse proxy"))
|
|
760
|
+
ol.set_defaults(fn=cmd_openlineage)
|
|
761
|
+
|
|
762
|
+
w = sub.add_parser("watch", help=tr("scheduler: collect, check and notify periodically"))
|
|
763
|
+
w.add_argument("--interval", type=float, help=tr("seconds (default: setting watch.interval_s or 300)"))
|
|
764
|
+
w.add_argument("--iterations", type=int)
|
|
765
|
+
w.set_defaults(fn=cmd_watch)
|
|
766
|
+
|
|
767
|
+
mg = sub.add_parser("migrate-store", help=tr("copy the whole store between backends (e.g. SQLite → PostgreSQL)"))
|
|
768
|
+
mg.add_argument("src", help=tr("source: SQLite file, postgresql://… or env:VAR"))
|
|
769
|
+
mg.add_argument("dst", help=tr("destination: SQLite file, postgresql://… or env:VAR"))
|
|
770
|
+
mg.add_argument("--overwrite", dest="dst_has_data_ok", action="store_true", default=False, help=tr("replace existing data in the destination"))
|
|
771
|
+
mg.set_defaults(fn=cmd_migrate_store)
|
|
772
|
+
|
|
773
|
+
bk = sub.add_parser("backup", help=tr("consistent copy of the store (safe while the UI is running)"))
|
|
774
|
+
bk.add_argument("dest")
|
|
775
|
+
bk.set_defaults(fn=cmd_backup)
|
|
776
|
+
|
|
777
|
+
dc = sub.add_parser("dbt-cloud", help=tr("dbt Cloud: runs | pull (artifacts of the job's last successful run)"))
|
|
778
|
+
dc.add_argument("action", choices=["runs", "pull"])
|
|
779
|
+
dc.add_argument("--account")
|
|
780
|
+
dc.add_argument("--host")
|
|
781
|
+
dc.add_argument("--job")
|
|
782
|
+
dc.add_argument("--run", help=tr("pull: a specific run instead of the last successful one"))
|
|
783
|
+
dc.add_argument("--dest", default=".dbt_cloud_target")
|
|
784
|
+
dc.add_argument("--limit", type=int, default=20)
|
|
785
|
+
dc.set_defaults(fn=cmd_dbt_cloud)
|
|
786
|
+
|
|
787
|
+
lv = sub.add_parser("lineage-verify", help=tr("measure lineage precision/recall by perturbing real data (DuckDB)"))
|
|
788
|
+
lv.add_argument("--target")
|
|
789
|
+
lv.add_argument("--duckdb")
|
|
790
|
+
lv.add_argument("--package", help=tr("only models of this dbt package (e.g. jaffle_shop)"))
|
|
791
|
+
lv.add_argument("--model", action="append", help=tr("only these models (repeatable)"))
|
|
792
|
+
lv.add_argument("--max-columns", type=int)
|
|
793
|
+
lv.add_argument("--source", action="append", default=None, help=tr("only these sources (`name` or `name.column`, repeatable)"))
|
|
794
|
+
lv.add_argument("--sample-rows", type=int, default=None, help=tr("shrink each source to ~N rows (key hash; keeps joins) in the temporary copy"))
|
|
795
|
+
lv.add_argument("--only-used", action="store_true", help=tr("test only columns the lineage says are read (fast, but hides false negatives)"))
|
|
796
|
+
lv.add_argument("--out", help=tr("write the JSON report"))
|
|
797
|
+
lv.add_argument("--show", type=int, default=15)
|
|
798
|
+
lv.add_argument("-v", "--verbose", action="store_true")
|
|
799
|
+
lv.set_defaults(fn=cmd_lineage_verify)
|
|
800
|
+
|
|
801
|
+
sc = sub.add_parser("secrets", help=tr("encryption at rest: status | migrate (encrypt old plain-text secrets) | rotate (re-encrypt with the current key)"))
|
|
802
|
+
sc.add_argument("action", choices=["status", "migrate", "rotate"])
|
|
803
|
+
sc.set_defaults(fn=cmd_secrets)
|
|
804
|
+
|
|
805
|
+
ot = sub.add_parser("otel-push", help=tr("send metrics to the OpenTelemetry Collector (OTLP/HTTP)"))
|
|
806
|
+
ot.add_argument("--endpoint", help=tr("default: OTEL_EXPORTER_OTLP_ENDPOINT"))
|
|
807
|
+
ot.set_defaults(fn=cmd_otel_push)
|
|
808
|
+
|
|
809
|
+
sx = sub.add_parser("sqlmesh-export", help=tr("export a SQLMesh project to JSON (usable as --target, without SQLMesh in CI)"))
|
|
810
|
+
sx.add_argument("project")
|
|
811
|
+
sx.add_argument("-o", "--output")
|
|
812
|
+
sx.add_argument("--gateway")
|
|
813
|
+
sx.set_defaults(fn=cmd_sqlmesh_export)
|
|
814
|
+
|
|
815
|
+
a3 = sub.add_parser("airflow3", help=tr("Airflow 2 → 3 migration: find what breaks in the DAGs and rewrite mechanical imports"))
|
|
816
|
+
a3.add_argument("dags", help=tr("folder with the DAGs"))
|
|
817
|
+
a3.add_argument("--write", action="store_true", help=tr("apply the mechanical import changes (keeps .af2.bak)"))
|
|
818
|
+
a3.add_argument("--json", action="store_true")
|
|
819
|
+
a3.set_defaults(fn=cmd_airflow3)
|
|
820
|
+
|
|
821
|
+
pr = sub.add_parser("prune", help=tr("delete old data from the store"))
|
|
822
|
+
pr.add_argument("--days", type=float, default=30)
|
|
823
|
+
pr.set_defaults(fn=cmd_prune)
|
|
824
|
+
|
|
825
|
+
fp = sub.add_parser("fp", help=tr("mark a finding as a false positive"))
|
|
826
|
+
fp.add_argument("id")
|
|
827
|
+
fp.add_argument("--reason")
|
|
828
|
+
fp.add_argument("--user", default=user_default)
|
|
829
|
+
fp.set_defaults(fn=cmd_fp)
|
|
830
|
+
|
|
831
|
+
sub.add_parser("stats", help=tr("precision per check (false positives)")).set_defaults(fn=cmd_stats)
|
|
832
|
+
sub.add_parser("overview", help=tr("overview as JSON")).set_defaults(fn=cmd_overview)
|
|
833
|
+
|
|
834
|
+
rk = sub.add_parser("risks", help=tr("what can break in the whole process: visibility gaps, fragile points and process failures"))
|
|
835
|
+
rk.add_argument("--target", help=tr("default: saved setting `dbt.target`"))
|
|
836
|
+
rk.add_argument("--root")
|
|
837
|
+
rk.add_argument("--base", help=tr("target of the base version (the PR gate depends on it)"))
|
|
838
|
+
rk.add_argument("--declared", help=tr("declared lineage (default: <root>/intentflow.lineage.json)"))
|
|
839
|
+
rk.add_argument("--json", action="store_true")
|
|
840
|
+
rk.add_argument("--fail-on-high", action="store_true", help=tr("exit 1 if there is a high severity item"))
|
|
841
|
+
rk.set_defaults(fn=cmd_risks)
|
|
842
|
+
|
|
843
|
+
u = sub.add_parser("ui", help=tr("web interface"))
|
|
844
|
+
u.add_argument("--port", type=int, default=8787)
|
|
845
|
+
u.add_argument("--host", default="127.0.0.1", help=tr("outside loopback requires users and HTTPS (or --behind-proxy)"))
|
|
846
|
+
u.add_argument("--tls-cert")
|
|
847
|
+
u.add_argument("--tls-key")
|
|
848
|
+
u.add_argument("--behind-proxy", action="store_true", help=tr("TLS terminated at a reverse proxy"))
|
|
849
|
+
u.set_defaults(fn=cmd_ui)
|
|
850
|
+
|
|
851
|
+
us = sub.add_parser("user", help=tr("team: users and roles (viewer, engineer, admin)"))
|
|
852
|
+
us.add_argument("action", choices=["list", "add", "rotate", "disable", "enable", "role", "mfa-begin", "mfa-confirm", "mfa-disable", "mfa-recovery"])
|
|
853
|
+
us.add_argument("name", nargs="?")
|
|
854
|
+
us.add_argument("--role", default="viewer", choices=["viewer", "engineer", "admin"])
|
|
855
|
+
us.add_argument("--code")
|
|
856
|
+
us.add_argument("--expires-days", dest="expires_days", type=float, help=tr("token validity (add/rotate)"))
|
|
857
|
+
us.set_defaults(fn=cmd_user)
|
|
858
|
+
|
|
859
|
+
asg = sub.add_parser("assign", help=tr("assign a finding to someone ('-' removes)"))
|
|
860
|
+
asg.add_argument("id")
|
|
861
|
+
asg.add_argument("assignee")
|
|
862
|
+
asg.add_argument("--user", default=user_default)
|
|
863
|
+
asg.set_defaults(fn=cmd_assign)
|
|
864
|
+
|
|
865
|
+
nt2 = sub.add_parser("note", help=tr("comment on a finding"))
|
|
866
|
+
nt2.add_argument("id")
|
|
867
|
+
nt2.add_argument("text")
|
|
868
|
+
nt2.add_argument("--user", default=user_default)
|
|
869
|
+
nt2.set_defaults(fn=cmd_note)
|
|
870
|
+
|
|
871
|
+
g = sub.add_parser("config", help=tr("settings (set/get/unset/list) kept in the store"))
|
|
872
|
+
g.add_argument("action", choices=["set", "get", "unset", "list"])
|
|
873
|
+
g.add_argument("key", nargs="?")
|
|
874
|
+
g.add_argument("value", nargs="?")
|
|
875
|
+
g.set_defaults(fn=cmd_config)
|
|
876
|
+
|
|
877
|
+
po = sub.add_parser("policy", help=tr("policies (allowed PII, SLA, limits)"))
|
|
878
|
+
po.add_argument("action", choices=["list", "pii-allow", "sla", "max-rows", "max-age", "disable-check", "airflow-target"])
|
|
879
|
+
po.add_argument("name", nargs="?", help=tr("model | pipeline | value"))
|
|
880
|
+
po.add_argument("value", nargs="?", help=tr("SLA minutes"))
|
|
881
|
+
po.add_argument("--remove", action="store_true")
|
|
882
|
+
po.set_defaults(fn=cmd_policy)
|
|
883
|
+
|
|
884
|
+
k = sub.add_parser("ack", help=tr("acknowledge a finding (optionally until a date)"))
|
|
885
|
+
k.add_argument("id")
|
|
886
|
+
k.add_argument("--reason", required=True)
|
|
887
|
+
k.add_argument("--days", type=float)
|
|
888
|
+
k.add_argument("--user", default=user_default)
|
|
889
|
+
k.set_defaults(fn=cmd_ack)
|
|
890
|
+
|
|
891
|
+
extensions.each("register_cli", sub)
|
|
892
|
+
|
|
893
|
+
a = ap.parse_args(argv)
|
|
894
|
+
import signal
|
|
895
|
+
import threading
|
|
896
|
+
|
|
897
|
+
def _term(*_):
|
|
898
|
+
raise KeyboardInterrupt # SIGTERM (docker stop / k8s) unwinds like Ctrl-C: finally blocks run, servers close
|
|
899
|
+
prev = signal.signal(signal.SIGTERM, _term) if threading.current_thread() is threading.main_thread() else None
|
|
900
|
+
try:
|
|
901
|
+
return a.fn(a)
|
|
902
|
+
except KeyboardInterrupt:
|
|
903
|
+
return 130
|
|
904
|
+
except (OSError, KeyError, ValueError, StopIteration) as e:
|
|
905
|
+
# exit 2 = could not evaluate; 1 stays reserved for "blocking findings" so CI gates can tell them apart
|
|
906
|
+
err(f"{type(e).__name__}: {e}")
|
|
907
|
+
return 2
|
|
908
|
+
finally:
|
|
909
|
+
if prev is not None:
|
|
910
|
+
signal.signal(signal.SIGTERM, prev)
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
if __name__ == "__main__":
|
|
914
|
+
sys.exit(main())
|