Skip to content

Commit

Permalink
Add: Source API CLI interface
Browse files Browse the repository at this point in the history
  • Loading branch information
n-thumann authored and greenbonebot committed Mar 6, 2025
1 parent c21f851 commit d3e5d75
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pontos/nvd/source/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-FileCopyrightText: 2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

import asyncio
from argparse import Namespace

from pontos.nvd.source.api import SourceApi

from ._parser import parse_args

__all__ = ("SourceApi",)


async def query_changes(args: Namespace) -> None:
async with SourceApi() as api:
async for source in api.sources(
source_identifier=args.source_identifier,
request_results=args.number,
start_index=args.start,
):
print(source)


def main() -> None:
try:
args = parse_args()
asyncio.run(query_changes(args))
except KeyboardInterrupt:
pass


if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions pontos/nvd/source/_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: 2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later

from argparse import ArgumentParser, Namespace
from typing import Optional, Sequence

import shtab


def parse_args(args: Optional[Sequence[str]] = None) -> Namespace:
parser = ArgumentParser()
shtab.add_argument_to(parser)
parser.add_argument(
"--source-identifier",
help="Get sources record for this source identifier",
)
parser.add_argument(
"--number", "-n", metavar="N", help="Request only N sources", type=int
)
parser.add_argument(
"--start",
"-s",
help="Index of the first source to request.",
type=int,
default=0,
)
return parser.parse_args(args)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pontos-nvd-cpe = 'pontos.nvd.cpe:cpe_main'
pontos-nvd-cpes = 'pontos.nvd.cpe:cpes_main'
pontos-nvd-cpe-match = 'pontos.nvd.cpe_matches:cpe_match_main'
pontos-nvd-cpe-matches = 'pontos.nvd.cpe_matches:cpe_matches_main'
pontos-nvd-sources = 'pontos.nvd.source:main'

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down

0 comments on commit d3e5d75

Please sign in to comment.