-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathreport.py
More file actions
89 lines (79 loc) · 2.59 KB
/
Copy pathreport.py
File metadata and controls
89 lines (79 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import logging
import sys
from typing import List, Optional, Tuple
import click
from mythx_models.response import AnalysisInputResponse, DetectedIssuesResponse
from pythx import Client
from mythx_cli.formatter import FORMAT_RESOLVER, util
from mythx_cli.formatter.base import BaseFormatter
from mythx_cli.util import write_or_print
LOGGER = logging.getLogger("mythx-cli")
@click.command("report")
@click.argument("uuids", default=None, nargs=-1)
@click.option(
"--min-severity",
type=click.Choice(["low", "medium", "high"]),
help="Ignore SWC IDs below the designated level",
default=None,
)
@click.option(
"--swc-blacklist",
type=click.STRING,
help="A comma-separated list of SWC IDs to ignore",
default=None,
)
@click.option(
"--swc-whitelist",
type=click.STRING,
help="A comma-separated list of SWC IDs to include",
default=None,
)
@click.pass_obj
def analysis_report(
ctx,
uuids: List[str],
min_severity: Optional[str],
swc_blacklist: Optional[List[str]],
swc_whitelist: Optional[List[str]],
) -> None:
"""Fetch the report for a single or multiple job UUIDs.
\f
:param ctx: Click context holding group-level parameters
:param uuids: List of UUIDs to display the report for
:param min_severity: Ignore SWC IDs below the designated level
:param swc_blacklist: A comma-separated list of SWC IDs to ignore
:param swc_whitelist: A comma-separated list of SWC IDs to include
:param table_sort_key: The column to sort the default table output by
:return:
"""
issues_list: List[
Tuple[str, DetectedIssuesResponse, Optional[AnalysisInputResponse]]
] = []
formatter: BaseFormatter = FORMAT_RESOLVER[ctx["fmt"]]
ctx["client"]: Client
for uuid in uuids:
LOGGER.debug(f"{uuid}: Fetching report")
resp = ctx["client"].report(uuid)
LOGGER.debug(f"{uuid}: Fetching input")
inp = (
ctx["client"].request_by_uuid(uuid)
if formatter.report_requires_input
else None
)
LOGGER.debug(f"{uuid}: Applying SWC filters")
util.filter_report(
resp,
min_severity=min_severity,
swc_blacklist=swc_blacklist,
swc_whitelist=swc_whitelist,
)
issues_list.append((uuid, resp, inp))
LOGGER.debug(
f"{uuid}: Printing report for {len(issues_list)} issue items with sort key \"{ctx['table_sort_key']}\""
)
write_or_print(
formatter.format_detected_issues(
issues_list, table_sort_key=ctx["table_sort_key"]
)
)
sys.exit(ctx["retval"])