Skip to content

Commit

Permalink
Fix announcements load and telemetry.
Browse files Browse the repository at this point in the history
  • Loading branch information
yeisonvargasf committed Nov 20, 2022
1 parent be1a7a8 commit 14db471
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions safety/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ def check(ctx, key, db, full_report, stdin, files, cache, ignore, output, json,
packages = get_packages(files, stdin)
proxy_dictionary = get_proxy_dict(proxy_protocol, proxy_host, proxy_port)

announcements = []
if not db or is_a_remote_mirror(db):
LOG.info('Not local DB used, Getting announcements')
announcements = safety.get_announcements(key=key, proxy=proxy_dictionary, telemetry=ctx.parent.telemetry)

if key:
server_policies = fetch_policy(key=key, proxy=proxy_dictionary)
server_audit_and_monitor = server_policies["audit_and_monitor"]
Expand Down Expand Up @@ -157,6 +152,11 @@ def check(ctx, key, db, full_report, stdin, files, cache, ignore, output, json,
LOG.info('Safety is going to calculate remediations')
remediations = safety.calculate_remediations(vulns, db_full)

announcements = []
if not db or is_a_remote_mirror(db):
LOG.info('Not local DB used, Getting announcements')
announcements = safety.get_announcements(key=key, proxy=proxy_dictionary, telemetry=ctx.parent.telemetry)

json_report = None
if save_json or (server_audit_and_monitor and audit_and_monitor):
default_name = 'safety-report.json'
Expand All @@ -183,7 +183,7 @@ def check(ctx, key, db, full_report, stdin, files, cache, ignore, output, json,
output_report = json_report
else:
output_report = SafetyFormatter(output=output).render_vulnerabilities(announcements, vulns, remediations,
full_report, packages)
full_report, packages)

# Announcements are send to stderr if not terminal, it doesn't depend on "exit_code" value
stderr_announcements = filter_announcements(announcements=announcements, by_type='error')
Expand Down Expand Up @@ -227,7 +227,6 @@ def review(ctx, full_report, output, file):
Show an output from a previous exported JSON report.
"""
LOG.info('Running check command')
announcements = safety.get_announcements(key=None, proxy=None, telemetry=ctx.parent.telemetry)
report = {}

try:
Expand All @@ -243,6 +242,7 @@ def review(ctx, full_report, output, file):
params = {'file': file}
vulns, remediations, packages = safety.review(report, params=params)

announcements = safety.get_announcements(key=None, proxy=None, telemetry=ctx.parent.telemetry)
output_report = SafetyFormatter(output=output).render_vulnerabilities(announcements, vulns, remediations,
full_report, packages)

Expand Down Expand Up @@ -279,10 +279,6 @@ def license(ctx, key, db, output, cache, files, proxyprotocol, proxyhost, proxyp
packages = get_packages(files, False)

proxy_dictionary = get_proxy_dict(proxyprotocol, proxyhost, proxyport)
announcements = []
if not db:
announcements = safety.get_announcements(key=key, proxy=proxy_dictionary, telemetry=ctx.parent.telemetry)

licenses_db = {}

try:
Expand All @@ -298,6 +294,10 @@ def license(ctx, key, db, output, cache, files, proxyprotocol, proxyhost, proxyp

filtered_packages_licenses = get_packages_licenses(packages=packages, licenses_db=licenses_db)

announcements = []
if not db:
announcements = safety.get_announcements(key=key, proxy=proxy_dictionary, telemetry=ctx.parent.telemetry)

output_report = SafetyFormatter(output=output).render_licenses(announcements, filtered_packages_licenses)

click.secho(output_report, nl=True)
Expand Down
2 changes: 1 addition & 1 deletion safety/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def get_announcements(key, proxy, telemetry=True):
url = source
method = 'get'
data = {
'telemetry': json.dumps(build_telemetry_data(telemetry=telemetry))}
'telemetry': json.dumps(data)}
data_keyword = 'params'

request_kwargs[data_keyword] = data
Expand Down

0 comments on commit 14db471

Please sign in to comment.