Commit 24fb65a1 authored by Adrian DC's avatar Adrian DC
Browse files

feat(gitlab): detect 'Token Access' usage for 'CI/CD' features

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 3470932b
Loading
Loading
Loading
Loading
+18 −2
Changes for src/features/gitlab.py: 18 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ from typing import List

# Modules libraries
from gitlab import Gitlab
from gitlab.exceptions import GitlabListError
from gitlab.exceptions import GitlabGetError, GitlabListError
from gitlab.v4.objects import Group, Project

# GitLabFeature class
@@ -241,7 +241,23 @@ class GitLabFeature:
            result += ['Git LFS']

        # Disable unused feature (CI/CD)
        if project.jobs_enabled and not project.jobs.list(get_all=False):
        try:
            if project.jobs.list(get_all=False):
                pass
            elif any('name' in item and item['name'] == '.gitlab-ci.yml'
                     for item in project.repository_tree(get_all=True)):
                pass
            elif any('path_with_namespace' in item
                     and item['path_with_namespace'] != project.path_with_namespace
                     for item in self.__gitlab.http_get(
                         f'/projects/{project.id}/job_token_scope/allowlist',
                         get_all=True,
                     )):
                pass
            else:
                assert False
        except (AssertionError, GitlabGetError, GitlabListError):
            if project.jobs_enabled:
                project.jobs_enabled = False
                result += ['CI/CD']