"""Export the producer's one online client; never maintain a consumer fork.""" from pathlib import Path import argparse import hashlib import json ROOT = Path(__file__).resolve().parent.parent DESTINATION = ROOT / 'adapters/go/tokenstatus' def main(): parser = argparse.ArgumentParser() parser.add_argument('--check', action='store_true') args = parser.parse_args() client = (ROOT / 'src/internal/authclient/online.go').read_bytes() assert client.startswith(b'package authclient\n') output = { 'pkg/tokenstatus/client.go': client.replace(b'package authclient\n', b'package tokenstatus\n', 1), 'internal/jose/jose.go': (ROOT / 'src/internal/jose/jose.go').read_bytes(), 'LICENSE': (ROOT / 'LICENSE').read_bytes(), 'go.mod': b'module keycape\n\ngo 1.23.0\n', } metadata = { 'source_of_truth': 'key-cape source; generated by tools/export_tokenstatus_client.py', 'source_files': ['src/internal/authclient/online.go', 'src/internal/jose/jose.go', 'LICENSE'], 'transformation': 'replace only the first package declaration authclient with tokenstatus; all remaining client bytes and shared JOSE bytes exact', 'module': 'keycape', 'profile': 'issuer online access-token status; no policy evaluator or deployment', 'supported_file_boundary': 'Linux owner execution profile; POSIX mode checks; not a Windows ACL contract', 'sha256': {name: 'sha256:' + hashlib.sha256(raw).hexdigest() for name,raw in sorted(output.items())}, } output['producer-source.json'] = (json.dumps(metadata, indent=2) + '\n').encode() actual = {str(p.relative_to(DESTINATION)) for p in DESTINATION.rglob('*') if p.is_file()} if actual - set(output): raise SystemExit('unexpected generated adapter file; reconcile explicitly') if args.check: if any(not (DESTINATION / name).is_file() or (DESTINATION / name).read_bytes()!=raw for name,raw in output.items()): raise SystemExit('producer/consumer token-status source drift') else: for name, raw in output.items(): path=DESTINATION/name;path.parent.mkdir(parents=True, exist_ok=True);path.write_bytes(raw) print(json.dumps({'status':'verified' if args.check else 'exported','files':len(output)})) if __name__ == '__main__': main()