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

Quiet Mode should not generate any output #830

Merged
merged 2 commits into from Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cve_bin_tool/cli.py
Expand Up @@ -260,9 +260,9 @@ def main(argv=None):
)
)

with CVEScanner(score=score) as cve_scanner:
total_files: int = 0
with CVEScanner(score=score, error_mode=error_mode) as cve_scanner:
triage_data: TriageData
total_files: int = 0
parsed_data: Dict[tuple, TriageData] = {}

if args.input_file:
Expand Down
24 changes: 18 additions & 6 deletions cve_bin_tool/cve_scanner.py
Expand Up @@ -11,6 +11,7 @@
from rich.panel import Panel

from .cvedb import DISK_LOCATION_DEFAULT, DBNAME
from .error_handler import ErrorMode
from .input_engine import Remarks, TriageData
from .log import LOGGER

Expand Down Expand Up @@ -53,8 +54,14 @@ class CVEScanner:
CONSOLE: Console = Console(file=sys.stderr)
ALPHA_TO_NUM: Dict[str, int] = dict(zip(ascii_lowercase, range(26)))

def __init__(self, score: int = 0, logger: Logger = None):
def __init__(
self,
score: int = 0,
logger: Logger = None,
error_mode: ErrorMode = ErrorMode.TruncTrace,
):
self.logger = logger or LOGGER.getChild(self.__class__.__name__)
self.error_mode = error_mode
self.score = score
self.products_with_cve = 0
self.products_without_cve = 0
Expand Down Expand Up @@ -185,11 +192,16 @@ def get_cves(
if cves:
self.products_with_cve += 1
self.logger.info(f"Known CVEs in {product}-{version}")
self.CONSOLE.print(
Columns(
[Panel(f"[yellow]{cve.cve_number}[/yellow]") for cve in cves]
),
)
# error_mode.value will only be greater than 1 if quiet mode.
if self.error_mode.value > 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, but I'd like some comments in here to mention quiet mode to explain why these are like this, mostly so it's there as a reminder for folk adding any further output.

self.CONSOLE.print(
Columns(
[
Panel(f"[yellow]{cve.cve_number}[/yellow]")
for cve in cves
]
),
)
else:
# No cves found for (product, vendor, version) tuple in the NVD database.
self.products_without_cve += 1
Expand Down
27 changes: 20 additions & 7 deletions cve_bin_tool/cvedb.py
Expand Up @@ -210,12 +210,19 @@ async def refresh(self):
],
)
)
total_tasks = len(nvd_metadata) + 1
for task in track(
asyncio.as_completed(tasks),
description="Downloading CVEs...",
total=total_tasks,
):
total_tasks = len(tasks)

# error_mode.value will only be greater than 1 if quiet mode.
if self.error_mode.value > 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also mention quiet mode here.

iter_tasks = track(
asyncio.as_completed(tasks),
description="Downloading CVEs...",
total=total_tasks,
)
else:
iter_tasks = asyncio.as_completed(tasks)

for task in iter_tasks:
await task
self.was_updated = True
await self.session.close()
Expand Down Expand Up @@ -310,7 +317,13 @@ def populate_db(self):
"""
del_cve_range = "DELETE from cve_range where CVE_number=?"

for year in track(self.nvd_years(), description="Updating CVEs from NVD..."):
# error_mode.value will only be greater than 1 if quiet mode.
if self.error_mode.value > 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

years = track(self.nvd_years(), description="Updating CVEs from NVD...")
else:
years = self.nvd_years()

for year in years:
cve_data = self.load_nvd_year(year)
self.LOGGER.debug(
f'Time = {datetime.datetime.today().strftime("%H:%M:%S")}'
Expand Down
2 changes: 2 additions & 0 deletions cve_bin_tool/egg_updater.py
Expand Up @@ -26,6 +26,7 @@ def update_egg():
cwd = os.getcwd()
os.chdir(os.path.join(os.path.dirname(__file__), ".."))
sys.stdout = f
sys.stderr = f
dist = Distribution(
dict(
script_name="setup.py",
Expand Down Expand Up @@ -56,6 +57,7 @@ def update_egg():
dist.parse_command_line()
dist.run_commands()
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
os.chdir(cwd)


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,5 +1,5 @@
jsonschema
rich
rich==4.0.0
plotly
jinja2
beautifulsoup4
Expand Down