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/gitlab/collectors/projects.py · raw

 1"""
 2Enumerate the projects in a GitLab group.
 3
 4fetch_projects() returns the raw project objects once; the per-project
 5collectors reuse that cache to avoid re-listing the group.
 6"""
 7
 8from .api import enc, paginate
 9
10
11def fetch_projects(group, cfg):
12    """List all projects in the group, including subgroups."""
13    return paginate(
14        f"{cfg['base_url']}/groups/{enc(group)}/projects",
15        cfg,
16        {"include_subgroups": "true", "archived": "false"},
17    )
18
19
20def project_list(_group, _cfg, projects):
21    """Format the project cache into audit rows."""
22    return [
23        {
24            "id": p["id"],
25            "name": p["name"],
26            "path": p.get("path_with_namespace", ""),
27            "visibility": p.get("visibility", ""),
28            "default_branch": p.get("default_branch", ""),
29            "archived": p.get("archived", False),
30            "web_url": p.get("web_url", ""),
31        }
32        for p in projects
33    ]