-
Notifications
You must be signed in to change notification settings - Fork 3
validate the exemption allow list #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import json | ||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| ALLOW_FILE = Path(__file__).parent / "allow.json" | ||
| ENTRY_PATTERN = re.compile(r"^[a-zA-Z0-9_\-]+:[a-zA-Z0-9_\-\.]+:[a-zA-Z0-9_\-\.]+$") | ||
|
|
||
|
Comment on lines
+6
to
+8
|
||
| def validate(): | ||
| if not ALLOW_FILE.exists(): | ||
| print("❌ allow.json not found") | ||
| sys.exit(1) | ||
|
|
||
| try: | ||
| data = json.loads(ALLOW_FILE.read_text()) | ||
| except json.JSONDecodeError as e: | ||
| print(f"❌ Invalid JSON: {e}") | ||
| sys.exit(1) | ||
|
|
||
| if not isinstance(data, list): | ||
| print("❌ allow.json must be a list") | ||
| sys.exit(1) | ||
|
|
||
| if len(data) == 0: | ||
| print("❌ allow.json is empty") | ||
| sys.exit(1) | ||
|
|
||
| errors = [] | ||
| for i, entry in enumerate(data): | ||
| if not isinstance(entry, str): | ||
| errors.append(f" [{i}] not a string: {entry}") | ||
| elif not ENTRY_PATTERN.match(entry): | ||
| errors.append(f" [{i}] invalid format: '{entry}' (expected format:name:version)") | ||
|
|
||
| if errors: | ||
| print("❌ Invalid entries:") | ||
| for e in errors: | ||
| print(e) | ||
| sys.exit(1) | ||
|
|
||
| print(f"✅ {len(data)} entries valid") | ||
|
|
||
| if __name__ == "__main__": | ||
| validate() | ||
Uh oh!
There was an error while loading. Please reload this page.