From cc48f1ccb4f5994d9de2d837cee224e937c85a90 Mon Sep 17 00:00:00 2001 From: Joe Jabs Date: Wed, 26 Nov 2025 12:22:15 +0100 Subject: [PATCH] Fixed CSV --- Containerfile | 2 +- check_gitlab.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Containerfile b/Containerfile index b4cc648..9fe6516 100644 --- a/Containerfile +++ b/Containerfile @@ -16,4 +16,4 @@ echo "Running check" python3 -u check_gitlab.py EOF -ENTRYPOINT ["/opt/hulud_check/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/opt/hulud_check/entrypoint.sh"] diff --git a/check_gitlab.py b/check_gitlab.py index 5ab80e2..0d25d0d 100755 --- a/check_gitlab.py +++ b/check_gitlab.py @@ -50,7 +50,7 @@ class Report(): def write_report(self, filename): with open(filename, 'w', newline='') as csvfile: - writer = csv.writer(csvfile, delimiter=';', quotechar='|', quoting=csv.QUOTE_MINIMAL) + writer = csv.writer(csvfile, delimiter=';', dialect='unix', quotechar='|', quoting=csv.QUOTE_MINIMAL) for row in self.findings: writer.writerow(row) @@ -79,13 +79,13 @@ def clone_repo_with_http(repo_url=None): repo_http_scheme = repo_url.split('://')[0] repo_credentials = f"token:{session.pat}" repo_remote = f"{repo_http_scheme}://{repo_credentials}@{repo_host_path}" - repo_name = repo_host_path.split('/')[-1].rstrip('.git') + repo_name = repo_host_path.replace('/', '_').rstrip('.git') repo_path = f"{git_tmp_root}/{repo_name}" if os.path.isdir(repo_path) and os.listdir(repo_path): return repo_path - print(f"Processing Repository {repo_name}") + print(f"Processing Repository {repo_host_path}") try: repo = Repo.clone_from(repo_remote, repo_path) repo.close() @@ -121,7 +121,7 @@ def scan_repo(path=None, repo=None): scan_matches += [{ 'repo': repo, 'full_path': line_data["data"]["path"]["text"], - 'path': line_data["data"]["path"]["text"].replace(path, '').lstrip('/'), + 'path': line_data["data"]["path"]["text"].replace(path, '').lstrip('/').rstrip(), 'line_number': line_data["data"]["line_number"], 'matches': line_data["data"]["submatches"] }] @@ -134,19 +134,20 @@ def evaluate_findings(findings=[]): if filename.startswith("package"): print(f"Found potential match - {finding['path']} - {finding['matches'][0]['match']['text']}") detail = check_line_in_file(file=finding['full_path'], line_number=finding['line_number']) - finding_results += [[finding['repo'], finding['path'],finding['line_number'],detail.lstrip(),finding['matches'][0]['match']['text']]] + finding_results += [[finding['repo'], finding['path'], finding['line_number'], detail.lstrip(),finding['matches'][0]['match']['text']]] return finding_results def check_line_in_file(file=None, line_number=None): with open(file) as fp: for i, line in enumerate(fp, 1): if i == line_number: - return line + print(line) + return line.rstrip().replace(',', '') def check_repos(): repos = get_all_projects() - + print(f"Found {len(repos)} Repositories..") for repo in repos: scan_path = clone_repo_with_http(repo['http_url_to_repo']) findings = scan_repo(scan_path, repo['web_url'])