Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
packages = list(read_requirements(sys.stdin))
else:
import pkg_resources
packages = [
d for d in pkg_resources.working_set
if d.key not in {"python", "wsgiref", "argparse"}
]
proxy_dictionary = {}
if proxyhost is not None:
if proxyprotocol in ["http", "https"]:
proxy_dictionary = {proxyprotocol: "{0}://{1}:{2}".format(proxyprotocol, proxyhost, str(proxyport))}
else:
click.secho("Proxy Protocol should be http or https only.", fg="red")
sys.exit(-1)
try:
vulns = safety.check(packages=packages, key=key, db_mirror=db, cached=cache, ignore_ids=ignore, proxy=proxy_dictionary)
output_report = report(vulns=vulns,
full=full_report,
json_report=json,
bare_report=bare,
checked_packages=len(packages),
db=db,
key=key)
if output:
with open(output, 'w+') as output_file:
output_file.write(output_report)
else:
click.secho(output_report, nl=False if bare and not vulns else True)
sys.exit(-1 if vulns else 0)
except InvalidKeyError:
click.secho("Your API Key '{key}' is invalid. See {link}".format(
packages = list(read_requirements(sys.stdin))
else:
import pkg_resources
packages = [
d for d in pkg_resources.working_set
if d.key not in {"python", "wsgiref", "argparse"}
]
proxy_dictionary = {}
if proxyhost is not None:
if proxyprotocol in ["http", "https"]:
proxy_dictionary = {proxyprotocol: "{0}://{1}:{2}".format(proxyprotocol, proxyhost, str(proxyport))}
else:
click.secho("Proxy Protocol should be http or https only.", fg="red")
sys.exit(-1)
try:
vulns = safety.check(packages=packages, key=key, db_mirror=db, cached=cache, ignore_ids=ignore, proxy=proxy_dictionary)
output_report = report(vulns=vulns,
full=full_report,
json_report=json,
bare_report=bare,
checked_packages=len(packages),
db=db,
key=key)
if output:
with open(output, 'w+') as output_file:
output_file.write(output_report)
else:
click.secho(output_report, nl=False if bare and not vulns else True)
sys.exit(-1 if vulns else 0)
except InvalidKeyError:
click.secho("Your API Key '{key}' is invalid. See {link}".format(
def is_insecure(self):
if self._is_insecure is None:
if not settings.api_key:
self._is_insecure = False
else:
self._is_insecure = len(safety.check(
packages=(self,),
cached=True,
key=settings.api_key,
db_mirror="",
ignore_ids=()
)) != 0
return self._is_insecure
def safety_provider(dependencies):
"""Pypi source is scanned with `safety`."""
for dependency in dependencies:
packages = [safetyutil.Package(key=dependency['name'],
version=dependency['version'])]
vulns = safety.check(packages=packages,
key=Config.SAFETY_API_KEY,
db_mirror='',
cached=False,
ignore_ids=[],
proxy=None)
for vuln in vulns:
Vulnerability.get_or_create(
artifact=dependency['id'],
provider="safety",
reference=vuln.vuln_id,
details=vuln._asdict())