Skip to content

Commit

Permalink
add support for raw dump
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Jul 19, 2022
1 parent a123e7c commit daa8a1c
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions vulntotal/vulntotal-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# Visit https://github.com/nexB/vulnerablecode/ for support and download.

import argparse
import json
import pydoc

from packageurl import PackageURL
Expand All @@ -43,7 +44,7 @@ def get_help():
Usage: vulntotal-cli.py [-h] [-p PURL] [-l] [-d validator [validator ...]]
[-e validator [validator ...]]
Discription:
Description:
When no -e/-d flag is provided CLI will run the PURL through
all the available validators.
Expand All @@ -53,6 +54,7 @@ def get_help():
-p PURL, --purl PURL PackageURL to run through validator/s
-l, --list Lists all the available validators
-r, --raw List of all the raw response from vendor
-e validator [validator ...] Enable these validator/s only
--enable validator [validator ...]
Expand All @@ -64,6 +66,7 @@ def get_help():
python vulntotal-cli.py -p 'pkg:pypi/[email protected]'
python vulntotal-cli.py -e osv vulnerablecode -p 'pkg:pypi/[email protected]'
python vulntotal-cli.py -d osv -p 'pkg:pypi/[email protected]'
python vulntotal-cli.py -r -e osv -p 'pkg:pypi/[email protected]'
"""


Expand Down Expand Up @@ -102,6 +105,19 @@ def formatted_row(validator, advisory):
return [validator.upper(), aliases, affected, fixed]


def get_raw_response(purl, validators):
if not validators:
print("No validators available!")
return

all_raw_responses = {}
for key, validator in validators.items():
vendor = validator()
vendor_advisories = vendor.validator_advisory(PackageURL.from_string(purl))
all_raw_responses[key] = vendor.raw_dump
print(all_raw_responses)


def run_validators(purl, validators):
if not validators:
print("No validators available!")
Expand All @@ -116,14 +132,11 @@ def run_validators(purl, validators):
for key, validator in validators.items():
vendor = validator()
vendor_advisories = vendor.validator_advisory(PackageURL.from_string(purl))
not_vulnerable_in_vendor_advisory = True

for advisory in vendor_advisories:
if not_vulnerable_in_vendor_advisory:
not_vulnerable_in_vendor_advisory = False
table.add_row(formatted_row(key, advisory))

if not_vulnerable_in_vendor_advisory:
if vendor_advisories:
for advisory in vendor_advisories:
table.add_row(formatted_row(key, advisory))
else:
table.add_row([key.upper(), "None", "None", "None"])

pydoc.pager(table.draw())
Expand All @@ -138,6 +151,9 @@ def handler():
parser.add_argument(
"-l", "--list", action="store_true", help="Lists all the available validators"
)
parser.add_argument(
"-r", "--raw", action="store_true", help="List of all the raw response from vendor"
)
parser.add_argument(
"-e", "--enable", metavar="validator", nargs="+", help="Enable these validator/s only"
)
Expand All @@ -157,6 +173,17 @@ def handler():
elif args.list:
list_validators()

elif args.raw:
if args.purl:
if args.enable:
get_raw_response(args.purl, get_enabled_validator(args.enable))

elif args.disable:
get_raw_response(args.purl, get_undisabled_validator(args.disable))

else:
get_raw_response(args.purl, VALIDATORS_REGISTRY)

elif args.purl:
if args.enable:
run_validators(args.purl, get_enabled_validator(args.enable))
Expand Down

0 comments on commit daa8a1c

Please sign in to comment.