Skip to content

Commit

Permalink
Add: Allow to request only a number of results in CVE, CVE changes an…
Browse files Browse the repository at this point in the history
…d CPE CLI

Extend pontos-nvd-cves, pontos-nvd-cve-changes and pontos-nvd-cpes CLIs
to allow requesting only a specific number of CVEs/CPEs.
  • Loading branch information
bjoernricks authored and greenbonebot committed Dec 1, 2023
1 parent 60693a0 commit 8c16e51
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
12 changes: 9 additions & 3 deletions pontos/nvd/cpe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ async def query_cpe(args: Namespace) -> None:

async def query_cpes(args: Namespace) -> None:
async with CPEApi(token=args.token) as api:
async for cpe in api.cpes(
keywords=args.keywords, cpe_match_string=args.cpe_match_string
):
response = api.cpes(
keywords=args.keywords,
cpe_match_string=args.cpe_match_string,
request_results=args.number,
)
async for cpe in response:
print(cpe)


Expand All @@ -61,6 +64,9 @@ def cpes_main() -> None:
help="Search for CPEs containing the keyword in their titles and "
"references.",
)
parser.add_argument(
"--number", "-n", metavar="N", help="Request only N CPEs", type=int
)

main(parser, query_cpes)

Expand Down
4 changes: 4 additions & 0 deletions pontos/nvd/cve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def query_cves(args: Namespace) -> None:
cvss_v2_vector=args.cvss_v2_vector,
cvss_v3_vector=args.cvss_v3_vector,
source_identifier=args.source_identifier,
request_results=args.number,
):
print(cve)

Expand Down Expand Up @@ -66,6 +67,9 @@ def cves_main() -> None:
help="Get all CVE information with the source identifier. For example: "
"[email protected]",
)
parser.add_argument(
"--number", "-n", metavar="N", help="Request only N CVEs", type=int
)

main(parser, query_cves)

Expand Down
7 changes: 6 additions & 1 deletion pontos/nvd/cve_changes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
async def query_changes(args: Namespace) -> None:
async with CVEChangesApi(token=args.token) as api:
async for cve in api.changes(
cve_id=args.cve_id, event_name=args.event_name
cve_id=args.cve_id,
event_name=args.event_name,
request_results=args.number,
):
print(cve)

Expand All @@ -25,6 +27,9 @@ def parse_args() -> Namespace:
parser.add_argument(
"--event-name", help="Get all CVE associated with a specific event name"
)
parser.add_argument(
"--number", "-n", metavar="N", help="Request only N CPEs", type=int
)
return parser.parse_args()


Expand Down

0 comments on commit 8c16e51

Please sign in to comment.