Skip to content

Commit

Permalink
Merge pull request #4336 from Osmose/pyup-api-key
Browse files Browse the repository at this point in the history
Fix bug 1437223: Add config for Pyup API key.
  • Loading branch information
Osmose committed Feb 13, 2018
2 parents 47671ec + 9f30ec0 commit 9030ee1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
17 changes: 11 additions & 6 deletions socorro/cron/jobs/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class DependencySecurityCheckCronApp(BaseCronApp):
Path to the nsp binary for checking Node dependencies.
crontabber.class-DependencySecurityCheckCronApp.safety_path
Path to the PyUp Safety binary for checking Python dependencies.
crontabber.class-DependencySecurityCheckCronApp.safety_api_key
Optional API key to pass to Safety.
crontabber.class-DependencySecurityCheckCronApp.package_json_path
Path to the package.json file to run nsp against.
secrets.sentry.dsn
Expand All @@ -74,6 +76,10 @@ class DependencySecurityCheckCronApp(BaseCronApp):
'safety_path',
doc='Path to the PyUp safety binary',
)
required_config.add_option(
'safety_api_key',
doc='API key for Safety to use latest Pyup vulnerability database',
)
required_config.add_option(
'package_json_path',
doc='Path to the package.json file to run nsp against',
Expand Down Expand Up @@ -128,12 +134,11 @@ def get_python_vulnerabilities(self):
"""
# Safety checks what's installed in the current virtualenv, so no need
# for any paths.
process = Popen(
[self.config.safety_path, 'check', '--json'],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
)
cmd = [self.config.safety_path, 'check', '--json']
if self.config.get('safety_api_key'):
cmd += ['--key', self.config.safety_api_key]

process = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, error_output = process.communicate()

if process.returncode == 0:
Expand Down
14 changes: 14 additions & 0 deletions socorro/unittest/cron/jobs/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ def test_get_python_vulnerabilities_none(self, mock_popen, app_config):
assert app.get_python_vulnerabilities() == []
assert popen.call_args[0][0] == [app_config['safety_path'], 'check', '--json']

def test_get_python_vulnerabilities_with_key(self, mock_popen, app_config):
app_config['safety_api_key'] = 'fake-api-key'
app = self.get_app(app_config)
popen = mock_popen(0)

assert app.get_python_vulnerabilities() == []
assert popen.call_args[0][0] == [
app_config['safety_path'],
'check',
'--json',
'--key',
'fake-api-key',
]

def test_get_python_vulnerabilities_failure(self, mock_popen, app_config):
"""Handle failures like being unable to connect to the network.
Expand Down

0 comments on commit 9030ee1

Please sign in to comment.