"""Validate dataset entries against schema/ and the cross-field rules in FORMAT.md. Usage: python tools/validate.py [dataset_dir ...] (exit 1 on any error) """ import ast, hashlib, json, os, re, subprocess, sys import jsonschema import yaml ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SCHEMA = {n: json.load(open(os.path.join(ROOT, "schema", f"{n}.schema.json"))) for n in ("family", "manifest", "parity", "timing", "multicore")} # Hygiene: internal hosts and identifiers must never ship. FORBIDDEN = [ (re.compile(r"git\.amazon\.com|code\.amazon\.com|gitlab\.aws\.dev|\.corp\.amazon\.com|amazon\.com/"), "internal URL"), (re.compile(r"\bi-0[0-9a-f]{8,16}\b"), "instance id"), (re.compile(r"\bcr-0[0-9a-f]{8,16}\b"), "capacity reservation id"), (re.compile(r"\b\d{12}\b(?=.*(arn|account))", re.I), "account id"), (re.compile(r"\barn:aws:"), "ARN"), (re.compile(r"\b(?:\d{1,3}\.){3}\d{1,3}\b(?/.nkb_hygiene. # Format, one item per line ('#' comments allowed): # extra forbidden pattern (reported as "internal name"; the match is not printed) # registry: directory of *.md registry files with a "**Customer**: " line; the # customer names and their file stems become forbidden patterns as well # $NKB_REGISTRY_DIR overrides the registry directory. Without a config only the generic checks run. HYGIENE_FILE = os.environ.get("NKB_HYGIENE_FILE") or os.path.join(ROOT, ".nkb_hygiene") def _local_hygiene(): pats, registry = [], os.environ.get("NKB_REGISTRY_DIR") if os.path.isfile(HYGIENE_FILE): for ln in open(HYGIENE_FILE, errors="ignore").read().splitlines(): ln = ln.strip() if not ln or ln.startswith("#"): continue if ln.startswith("registry:"): p = os.path.expanduser(ln.split(":", 1)[1].strip()) registry = registry or (p if os.path.isabs(p) else os.path.join(os.path.dirname(HYGIENE_FILE), p)) else: pats.append(re.compile(ln)) return pats, registry LOCAL_PATTERNS, REGISTRY = _local_hygiene() def _confidential_patterns(): """Confidential names read at runtime from the optional local registry (never written anywhere). Empty when no registry is configured (public copy).""" pats = list(LOCAL_PATTERNS) if not REGISTRY or not os.path.isdir(REGISTRY): return pats for f in os.listdir(REGISTRY): if not f.endswith(".md") or f.startswith(("_", "README")): continue m = re.search(r"^\*\*Customer\*\*:\s*(.+)$", open(os.path.join(REGISTRY, f), errors="ignore").read(), re.M) if not m: continue val = m.group(1).strip() if re.match(r"(?i)(n/a|none|tbd|-)\b", val): continue name = re.split(r"\s+--|\s+\(|,|;", val)[0].strip(" *`") for tok in {name, f[:-3]}: if len(tok) >= 4: pats.append(re.compile(r"(?i)(?-troubleshooting" if len(part) >= 5 and part.lower() == name.lower()[:len(part)].lower(): pats.append(re.compile(r"(?i)(?