Skip to content

Commit 01fc4f3

Browse files
committed
add support for listing supported ecosystem
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent d6b3998 commit 01fc4f3

1 file changed

Lines changed: 37 additions & 6 deletions

File tree

vulntotal/vulntotal-cli.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_help():
4141
╚██╔╝ ╚██████╔╝███████╗██║ ╚███║ ██║ ╚█████╔╝ ██║ ██║ ██║███████╗
4242
╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚══╝ ╚═╝ ╚════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝
4343
44-
Usage: vulntotal-cli.py [-h] [-l] [-r] [-d validator [validator ...]]
44+
Usage: vulntotal-cli.py [-h] [-l] [-le] [-r] [-d validator [validator ...]]
4545
[-e validator [validator ...]] [-p PURL]
4646
4747
Description:
@@ -52,6 +52,7 @@ def get_help():
5252
Optional arguments:
5353
-h, --help Show this help message and exit
5454
-l, --list Lists all the available validators
55+
-le, --ecosystem Lists ecosystem supported by active vendor
5556
-r, --raw List of all the raw response from vendor
5657
5758
-e validator [validator ...] Enable these validator/s only
@@ -64,6 +65,7 @@ def get_help():
6465
6566
Examples:
6667
python vulntotal-cli.py --list
68+
python vulntotal-cli.py -le
6769
python vulntotal-cli.py -p 'pkg:pypi/jinja2@2.4.1'
6870
python vulntotal-cli.py -e osv vulnerablecode -p 'pkg:go/github.com/cloudflare/cfrpki@v1.4.1'
6971
python vulntotal-cli.py -d osv -p 'pkg:maven/org.apache.tomcat/tomcat@10.1.0-M8'
@@ -75,10 +77,11 @@ def get_valid_validators(validators):
7577
valid_validators = {}
7678
unknown_validators = []
7779
for validator in validators:
80+
key = validator.lower()
7881
try:
79-
valid_validators[validator] = VALIDATORS_REGISTRY[validator]
82+
valid_validators[key] = VALIDATORS_REGISTRY[key]
8083
except KeyError:
81-
unknown_validators.append(validator)
84+
unknown_validators.append(key)
8285
if unknown_validators:
8386
raise CommandError(f"Unknown validator: {unknown_validators}")
8487
return valid_validators
@@ -94,9 +97,21 @@ def get_enabled_validator(validators):
9497

9598

9699
def list_validators():
97-
validators = list(VALIDATORS_REGISTRY)
100+
validators = [x.upper() for x in list(VALIDATORS_REGISTRY)]
98101
print("Currently supported validators:")
99-
print("\n".join(validators))
102+
print("\n".join(sorted(validators)))
103+
104+
105+
def list_supported_ecosystem(validators):
106+
ecosystems = []
107+
for key, validator in validators.items():
108+
vendor_supported_ecosystem = validator.supported_ecosystem()
109+
ecosystems.extend([x.upper() for x in vendor_supported_ecosystem.keys()])
110+
111+
active_validator = [x.upper() for x in validators.keys()]
112+
print("Active Validators:", ", ".join(sorted(active_validator)), end="\n\n")
113+
print("Ecosystem supported by active validators")
114+
print("\n".join(sorted(set(ecosystems))))
100115

101116

102117
def formatted_row(validator, advisory):
@@ -123,8 +138,11 @@ def run_validators(purl, validators):
123138
if not validators:
124139
print("No validators available!")
125140
return
141+
126142
print("PURL: ", purl)
127-
print("Active Validators: ", ", ".join(validators.keys()))
143+
active_validator = [x.upper() for x in validators.keys()]
144+
print("Active Validators:", ", ".join(sorted(active_validator)), end="\n\n")
145+
128146
table = Texttable()
129147
table.set_cols_dtype(["t", "t", "t", "t"])
130148
table.set_cols_align(["c", "l", "l", "l"])
@@ -152,6 +170,9 @@ def handler():
152170
parser.add_argument(
153171
"-l", "--list", action="store_true", help="Lists all the available validators"
154172
)
173+
parser.add_argument(
174+
"-le", "--ecosystem", action="store_true", help="Lists ecosystem supported by active vendor"
175+
)
155176
parser.add_argument(
156177
"-r", "--raw", action="store_true", help="List of all the raw response from vendor"
157178
)
@@ -174,6 +195,16 @@ def handler():
174195
elif args.list:
175196
list_validators()
176197

198+
elif args.ecosystem:
199+
if args.enable:
200+
list_supported_ecosystem(get_enabled_validator(args.enable))
201+
202+
elif args.disable:
203+
list_supported_ecosystem(get_undisabled_validator(args.disable))
204+
205+
else:
206+
list_supported_ecosystem(VALIDATORS_REGISTRY)
207+
177208
elif args.raw:
178209
if args.purl:
179210
if args.enable:

0 commit comments

Comments
 (0)