#!/usr/bin/env python3 """Identifier check for Clouds Against Humanity. This repository is public. The check scans every tracked text file for cloud account identifiers written in a structural form (an AWS ARN with an account id, an account id next to the word "account", an AWS key id, an Azure subscription or tenant id next to its key, a GCP project id next to its key) and fails when it finds one. It never prints the matched value, nor any part of it. A finding is reported as file:line and the kind, so the CI log does not become a second copy of the leak. It does not look for secrets. Secret scanning is Gitleaks' job; this catches identifiers that are not secrets but that a public repository should still not publish. Rules worth knowing: - Synthetic placeholders are allowed by name (ALLOWED_VALUES), and a value containing "example" is allowed. A placeholder like is not an id-shaped value, so it never matches in the first place. A real id wrapped in angle brackets is still a finding. - A line may end with a comment carrying the ignore marker (see IGNORE_RE); the run prints how many were used. - A file that is not valid UTF-8 is decoded with replacement characters and scanned anyway. UTF-16 is decoded when it has a byte order mark. A file with NUL bytes and no byte order mark is binary and is counted, not scanned. - A bad root, or a run that scanned no file, fails. - docs/superpowers/plans is skipped. """ from __future__ import annotations import argparse import re import subprocess import sys from pathlib import Path SKIP_DIRS = frozenset({".git", ".terraform", ".venv"}) SKIP_PREFIXES = ("docs/superpowers/plans/",) # The marker counts only inside a comment at the end of the line. IGNORE_RE = re.compile(r"(?:#|//|