Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update send-scan.py with gh meta and verbosity #141

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/cve-reports/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ send-scan.py --report-path <path-to-report(s)> --jira-url <URL-to-Jira>

- `--report-path` - Specifies location of report(s). If it is single file, it will be parsed on its own. If it is a directory all files in the directory will be parsed one by one. Only JSON and SARIF formats are supported.
- `--jira-url` - Specifies URL of Jira automation to which reports should be sent.
- `--add-github-meta` - Adds GitHub metadata to sent request.
maci3jka marked this conversation as resolved.
Show resolved Hide resolved
- `--verbose` - Prints out sent body and return code of request.
maci3jka marked this conversation as resolved.
Show resolved Hide resolved

## Testing

Expand Down
29 changes: 22 additions & 7 deletions scripts/cve-reports/send-scan.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python3
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
#

Expand All @@ -19,6 +19,16 @@
}


def get_github_meta():
maci3jka marked this conversation as resolved.
Show resolved Hide resolved
"""Get GitHub Metadata"""
maci3jka marked this conversation as resolved.
Show resolved Hide resolved
return {
"github_server_url": os.getenv("GITHUB_SERVER_URL"),
"github_run_id": os.getenv("GITHUB_RUN_ID"),
"github_sha": os.getenv("GITHUB_SHA"),
"github_repository": os.getenv("GITHUB_REPOSITORY"),
}


def parse_json(filename):
"""Parse JSON file"""
record_list = []
Expand Down Expand Up @@ -58,7 +68,6 @@ def parse_json(filename):
"priority": severity_to_priority_map.get(vuln["Severity"], "Lowest"),
}
)

return record_list


Expand Down Expand Up @@ -100,13 +109,12 @@ def parse_sarif(filename):
"priority": severity_to_priority_map.get(severity, "Lowest"),
}
)

return record_list


def main(report_path, jira_url):
def main(report_path, jira_url, gh_meta=False, verbose=False):
maci3jka marked this conversation as resolved.
Show resolved Hide resolved
input_path = Path(report_path)

gh_metadata = get_github_meta() if gh_meta else None
maci3jka marked this conversation as resolved.
Show resolved Hide resolved
file_list = []
if input_path.is_dir():
# directory is supplied, retrieve list of files
Expand All @@ -133,12 +141,19 @@ def main(report_path, jira_url):

# send records
for record in records:
requests.post(jira_url, json=record)
if gh_metadata is not None:
record = {**record, **gh_metadata}
res = requests.post(jira_url, json=record)
if verbose:
print(record)
print(res)
maci3jka marked this conversation as resolved.
Show resolved Hide resolved
maci3jka marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--report-path")
parser.add_argument("--jira-url")
parser.add_argument("--add-github-meta", action="store_true")
parser.add_argument("--verbose", action="store_true")
args = parser.parse_args()
main(args.report_path, args.jira_url)
main(args.report_path, args.jira_url, args.add_github_meta, args.verbose)
Loading