Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions pyvulnerabilitylookup/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,37 @@ def get_vendor_products(self, vendor: str) -> list[str]:
r = self.session.get(urljoin(self.root_url, str(PurePosixPath('api', 'browse', vendor))))
return r.json()

def get_vendor_product_vulnerabilities(self, vendor: str, product: str) -> list[str]:
def get_vendor_product_vulnerabilities(self, vendor: str, product: str, since: date | datetime | None=None) -> list[str]:
'''Get the the vulnerabilities per vendor and a specific product

:param vendor: A vendor owning products (must be in the known vendor list)
:param product: A product owned by that vendor
:param since: The date from which to get vulnerabilities
'''
r = self.session.get(urljoin(self.root_url, str(PurePosixPath('api', 'vulnerability', 'search', vendor, product))))
return r.json()

params: dict[str, Any] = {}
if since:
if isinstance(since, datetime):
since = since.date()
params['since'] = since.isoformat()

params['page'] = 1
params['per_page'] = 10
r = self.session.get(urljoin(self.root_url, str(PurePosixPath('api', 'vulnerability', 'search', vendor, product))), params=params)
res = r.json()
r_length = 0
for source in r.json():
r_length += len(r.json()[source])

while r_length == params['per_page']:
params['page'] += 1
r = self.session.get(urljoin(self.root_url, str(PurePosixPath('api', 'vulnerability', 'search', vendor, product))), params=params)
r_length = 0
for source in r.json():
res[source] = res.get(source, []) + r.json()[source]
r_length += len(r.json()[source])

return res

# #### Comments ####

Expand Down
Loading