audit-labs/audit-tools

A collection of scripts, queries, and other goodies you can use in an audit.

clone: git clone https://gitbay.org/audit-labs/audit-tools.git

v1.0.0: applications/github/config.py · raw

 1"""
 2Configuration loader for the GitHub audit tool.
 3
 4Reads GITHUB_TOKEN and GITHUB_ORG from environment variables.
 5
 6Usage:
 7    export GITHUB_TOKEN=your_token
 8    export GITHUB_ORG=your_organization
 9"""
10
11import os
12import sys
13
14
15def load(org_override=None):
16    """
17    Return a config dict. Exits with an error if required values are missing.
18    """
19    token = os.environ.get("GITHUB_TOKEN", "").strip()
20    org = org_override or os.environ.get("GITHUB_ORG", "").strip()
21
22    missing = []
23    if not token:
24        missing.append("GITHUB_TOKEN")
25    if not org:
26        missing.append("GITHUB_ORG (or pass --org)")
27
28    if missing:
29        print(f"Error: missing required values: {', '.join(missing)}", file=sys.stderr)
30        sys.exit(1)
31
32    return {
33        "token": token,
34        "org": org,
35        "headers": {
36            "Authorization": f"token {token}",
37            "Accept": "application/vnd.github.v3+json",
38        },
39        "timeout": 30,
40    }