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
main: applications/gitlab/config.py · raw
1"""
2Configuration loader for the GitLab audit tool.
3
4Reads GITLAB_TOKEN, GITLAB_GROUP, and (optionally) GITLAB_URL from the
5environment.
6
7Usage:
8 export GITLAB_TOKEN=your_token
9 export GITLAB_GROUP=your_group_id_or_path
10 export GITLAB_URL=https://gitlab.example.com/api/v4 # self-hosted only
11"""
12
13import os
14import sys
15
16from collectors.api import DEFAULT_BASE_URL
17
18
19def load(group_override=None, base_url_override=None):
20 """Return a config dict. Exits with an error if required values are missing."""
21 token = os.environ.get("GITLAB_TOKEN", "").strip()
22 group = group_override or os.environ.get("GITLAB_GROUP", "").strip()
23 base_url = (
24 base_url_override
25 or os.environ.get("GITLAB_URL", "").strip()
26 or DEFAULT_BASE_URL
27 )
28
29 missing = []
30 if not token:
31 missing.append("GITLAB_TOKEN")
32 if not group:
33 missing.append("GITLAB_GROUP (or pass --group)")
34
35 if missing:
36 print(f"Error: missing required values: {', '.join(missing)}", file=sys.stderr)
37 sys.exit(1)
38
39 return {
40 "token": token,
41 "group": group,
42 "base_url": base_url.rstrip("/"),
43 "headers": {"PRIVATE-TOKEN": token},
44 "timeout": 30,
45 }