diff --git a/pyvulnerabilitylookup/api.py b/pyvulnerabilitylookup/api.py index 89f1470..090fe51 100644 --- a/pyvulnerabilitylookup/api.py +++ b/pyvulnerabilitylookup/api.py @@ -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 ####