Add versioned metric graph authority, owned browser evidence, paginated and all-tab traversal, deterministic sampling policies, and analyst-facing run inspection. Provision the DEV/PREPROD/PROD Superset, Gitea and million-row ClickHouse lab; retain reproducible lifecycle evidence and explicit incomplete-traversal limits.
107 lines
4.5 KiB
Python
107 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
|
# #region FullFlow.FinanceDrift [C:4] [TYPE Module] [SEMANTICS export,drift,readonly,redaction]
|
|
# @BRIEF Compare actual DEV/PREPROD Superset exports without persisting credentials or archives.
|
|
# @PRE Existing isolated private lab env; reads only authenticated dashboard exports.
|
|
# @POST Differences identify actual YAML field paths; string payloads retain only digests/lengths.
|
|
import argparse
|
|
from hashlib import sha256
|
|
from io import BytesIO
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
from zipfile import ZipFile
|
|
|
|
import httpx
|
|
import yaml
|
|
|
|
from release import private_environment
|
|
|
|
|
|
# #region FullFlow.FinanceDrift.Export [C:4] [TYPE Function]
|
|
# @BRIEF Read actual exported assets through the isolated Superset API.
|
|
def export(port, dashboard):
|
|
with httpx.Client(base_url=f"http://127.0.0.1:{port}", trust_env=False, timeout=120) as client:
|
|
login = client.post("/api/v1/security/login", json={"username": "admin", "provider": "db",
|
|
"password": os.environ["FIXTURE_PASSWORD"], "refresh": True})
|
|
login.raise_for_status()
|
|
client.headers["Authorization"] = "Bearer " + login.json()["access_token"]
|
|
response = client.get("/api/v1/dashboard/export/", params={"q": json.dumps([dashboard])})
|
|
response.raise_for_status()
|
|
files = {}
|
|
with ZipFile(BytesIO(response.content)) as archive:
|
|
for name in archive.namelist():
|
|
parts = name.split("/")
|
|
if len(parts) > 2 and parts[1] in {"dashboards", "charts", "datasets"} and name.endswith(".yaml"):
|
|
value = yaml.safe_load(archive.read(name))
|
|
files[(parts[1], value["uuid"])] = value
|
|
return files
|
|
# #endregion FullFlow.FinanceDrift.Export
|
|
|
|
|
|
# #region FullFlow.FinanceDrift.Fact [C:2] [TYPE Function]
|
|
# @BRIEF Keep safe structural scalar facts and digest all arbitrary content.
|
|
def fact(value):
|
|
if value is None or isinstance(value, (bool, int, float)):
|
|
return value
|
|
wire = json.dumps(value, sort_keys=True, ensure_ascii=False).encode()
|
|
return {"type": type(value).__name__, "length": len(wire), "sha256": sha256(wire).hexdigest()}
|
|
# #endregion FullFlow.FinanceDrift.Fact
|
|
|
|
|
|
# #region FullFlow.FinanceDrift.Diff [C:3] [TYPE Function]
|
|
# @BRIEF Recursively expose changed field paths with safe scalar/digest facts.
|
|
def differences(left, right, path=""):
|
|
if left == right:
|
|
return []
|
|
if isinstance(left, dict) and isinstance(right, dict):
|
|
rows = []
|
|
for key in sorted(set(left) | set(right)):
|
|
rows.extend(differences(left.get(key), right.get(key), path+"/"+str(key)))
|
|
return rows
|
|
if isinstance(left, list) and isinstance(right, list) and len(left) == len(right):
|
|
rows = []
|
|
for index, (before, after) in enumerate(zip(left, right)):
|
|
rows.extend(differences(before, after, path+f"/{index}"))
|
|
return rows
|
|
return [{"path": path, "dev": fact(left), "preprod": fact(right)}]
|
|
# #endregion FullFlow.FinanceDrift.Diff
|
|
|
|
|
|
# #region FullFlow.FinanceDrift.Decode [C:2] [TYPE Function]
|
|
# @BRIEF Decode known exported JSON wrappers for structural diagnostics only, never hash acceptance.
|
|
def decoded(value):
|
|
result = dict(value)
|
|
for key in ("params", "json_metadata", "position_json", "query_context"):
|
|
if isinstance(result.get(key), str):
|
|
try:
|
|
result[key] = json.loads(result[key])
|
|
except ValueError:
|
|
pass
|
|
return result
|
|
# #endregion FullFlow.FinanceDrift.Decode
|
|
|
|
|
|
# #region FullFlow.FinanceDrift.Main [C:3] [TYPE Function]
|
|
# @BRIEF Save safe raw-structure and decoded-JSON diffs without changing release policy.
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--env-file", type=Path, required=True)
|
|
parser.add_argument("--dashboard-id", type=int, default=2)
|
|
parser.add_argument("--output", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
private_environment(args.env_file)
|
|
left, right = export(18111, args.dashboard_id), export(18112, args.dashboard_id)
|
|
rows = []
|
|
for key in sorted(set(left) | set(right)):
|
|
before, after = left.get(key), right.get(key)
|
|
rows.append({"kind": key[0], "uuid": key[1], "changes": differences(before, after),
|
|
"decoded_changes": differences(decoded(before or {}), decoded(after or {}))})
|
|
args.output.write_text(json.dumps({"read_only": True, "assets": rows}, indent=2)+"\n")
|
|
print("Safe structural export diff retained")
|
|
# #endregion FullFlow.FinanceDrift.Main
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
# #endregion FullFlow.FinanceDrift
|