Fixed CSV

This commit is contained in:
2025-11-26 12:22:15 +01:00
parent 49b3011cc3
commit cc48f1ccb4
2 changed files with 9 additions and 8 deletions

View File

@@ -50,7 +50,7 @@ class Report():
def write_report(self, filename): def write_report(self, filename):
with open(filename, 'w', newline='') as csvfile: 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: for row in self.findings:
writer.writerow(row) writer.writerow(row)
@@ -79,13 +79,13 @@ def clone_repo_with_http(repo_url=None):
repo_http_scheme = repo_url.split('://')[0] repo_http_scheme = repo_url.split('://')[0]
repo_credentials = f"token:{session.pat}" repo_credentials = f"token:{session.pat}"
repo_remote = f"{repo_http_scheme}://{repo_credentials}@{repo_host_path}" 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}" repo_path = f"{git_tmp_root}/{repo_name}"
if os.path.isdir(repo_path) and os.listdir(repo_path): if os.path.isdir(repo_path) and os.listdir(repo_path):
return repo_path return repo_path
print(f"Processing Repository {repo_name}") print(f"Processing Repository {repo_host_path}")
try: try:
repo = Repo.clone_from(repo_remote, repo_path) repo = Repo.clone_from(repo_remote, repo_path)
repo.close() repo.close()
@@ -121,7 +121,7 @@ def scan_repo(path=None, repo=None):
scan_matches += [{ scan_matches += [{
'repo': repo, 'repo': repo,
'full_path': line_data["data"]["path"]["text"], '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"], 'line_number': line_data["data"]["line_number"],
'matches': line_data["data"]["submatches"] 'matches': line_data["data"]["submatches"]
}] }]
@@ -134,19 +134,20 @@ def evaluate_findings(findings=[]):
if filename.startswith("package"): if filename.startswith("package"):
print(f"Found potential match - {finding['path']} - {finding['matches'][0]['match']['text']}") 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']) 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 return finding_results
def check_line_in_file(file=None, line_number=None): def check_line_in_file(file=None, line_number=None):
with open(file) as fp: with open(file) as fp:
for i, line in enumerate(fp, 1): for i, line in enumerate(fp, 1):
if i == line_number: if i == line_number:
return line print(line)
return line.rstrip().replace(',', '')
def check_repos(): def check_repos():
repos = get_all_projects() repos = get_all_projects()
print(f"Found {len(repos)} Repositories..")
for repo in repos: for repo in repos:
scan_path = clone_repo_with_http(repo['http_url_to_repo']) scan_path = clone_repo_with_http(repo['http_url_to_repo'])
findings = scan_repo(scan_path, repo['web_url']) findings = scan_repo(scan_path, repo['web_url'])