Skip to content

Commit

Permalink
Change: Rename "CVE Change History" to "CVE Changes"
Browse files Browse the repository at this point in the history
  • Loading branch information
n-thumann committed Nov 10, 2023
1 parent 4090381 commit 1ba86c4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from argparse import ArgumentParser, Namespace
from typing import Callable

from pontos.nvd.cve_change_history.api import CVEChangeHistoryApi
from pontos.nvd.cve_changes.api import CVEChangesApi

__all__ = ("CVEChangeHistoryApi",)
__all__ = ("CVEChangesApi",)


async def query_changes(args: Namespace) -> None:
async with CVEChangeHistoryApi(token=args.token) as api:
async for cve in api.cve_changes(
async with CVEChangesApi(token=args.token) as api:
async for cve in api.changes(
cve_id=args.cve_id, event_name=args.event_name
):
print(cve)
Expand All @@ -22,7 +22,7 @@ async def query_changes(args: Namespace) -> None:
def cve_changes() -> None:
parser = ArgumentParser()
parser.add_argument("--token", help="API key to use for querying.")
parser.add_argument("--cve-id", help="Get history for a specific CVE")
parser.add_argument("--cve-id", help="Get changes for a specific CVE")
parser.add_argument(
"--event-name", help="Get all CVE associated with a specific event name"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
)
from pontos.nvd.models.cve_change import CVEChange, EventName

__all__ = ("CVEChangeHistoryApi",)
__all__ = ("CVEChangesApi",)

DEFAULT_NIST_NVD_CVE_HISTORY_URL = (
"https://services.nvd.nist.gov/rest/json/cvehistory/2.0"
)


class CVEChangeHistoryApi(NVDApi):
class CVEChangesApi(NVDApi):
"""
API for querying the NIST NVD CVE Change History information.
Expand All @@ -35,10 +35,10 @@ class CVEChangeHistoryApi(NVDApi):
Example:
.. code-block:: python
from pontos.nvd.cve_change_history import CVEChangeHistoryApi
from pontos.nvd.cve_changes import CVEChangesApi
async with CVEChangeHistoryApi() as api:
async for cve_change in api.cve_changes(event_name=EventName.INITIAL_ANALYSIS):
async with CVEChangesApi() as api:
async for cve_change in api.changes(event_name=EventName.INITIAL_ANALYSIS):
print(cve_change)
"""

Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(
rate_limit=rate_limit,
)

async def cve_changes(
async def changes(
self,
*,
change_start_date: Optional[datetime] = None,
Expand All @@ -96,10 +96,10 @@ async def cve_changes(
Example:
.. code-block:: python
from pontos.nvd.cve_change_history import CVEChangeHistoryApi
from pontos.nvd.cve_changes import CVEChangesApi
async with CVEChangeHistoryApi() as api:
async for cve_change in api.cve_changes(event_name=EventName.INITIAL_ANALYSIS):
async with CVEChangesApi() as api:
async for cve_change in api.changes(event_name=EventName.INITIAL_ANALYSIS):
print(cve_change)
"""
total_results: Optional[int] = None
Expand Down Expand Up @@ -150,6 +150,6 @@ async def cve_changes(

start_index += results_per_page # type: ignore

async def __aenter__(self) -> "CVEChangeHistoryApi":
async def __aenter__(self) -> "CVEChangesApi":
await super().__aenter__()
return self
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pontos-github-actions = 'pontos.github.actions:main'
pontos-github-script = 'pontos.github.script:main'
pontos-nvd-cve = 'pontos.nvd.cve:cve_main'
pontos-nvd-cves = 'pontos.nvd.cve:cves_main'
pontos-nvd-cve-change-history = 'pontos.nvd.cve_change_history:cve_changes'
pontos-nvd-cve-changes = 'pontos.nvd.cve_changes:cve_changes'
pontos-nvd-cpe = 'pontos.nvd.cpe:cpe_main'
pontos-nvd-cpes = 'pontos.nvd.cpe:cpes_main'

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from pontos.errors import PontosError
from pontos.nvd.api import now
from pontos.nvd.cve_change_history.api import CVEChangeHistoryApi
from pontos.nvd.cve_changes.api import CVEChangesApi
from pontos.nvd.models.cve_change import Detail, EventName
from tests import AsyncMock, IsolatedAsyncioTestCase, aiter, anext
from tests.nvd import get_cve_change_data
Expand Down Expand Up @@ -40,17 +40,17 @@ def create_cve_changes_responses(count: int = 2) -> list[MagicMock]:
]


class CVEChangeHistoryApiTestCase(IsolatedAsyncioTestCase):
class CVEChangesApiTestCase(IsolatedAsyncioTestCase):
@patch("pontos.nvd.api.AsyncClient", spec=AsyncClient)
def setUp(self, async_client: MagicMock) -> None:
self.http_client = AsyncMock()
async_client.return_value = self.http_client
self.api = CVEChangeHistoryApi(token="token")
self.api = CVEChangesApi(token="token")

async def test_cve_changes(self):
self.http_client.get.side_effect = create_cve_changes_responses()

it = aiter(self.api.cve_changes())
it = aiter(self.api.changes())
cve_change = await anext(it)

self.assertEqual(cve_change.cve_id, "CVE-1")
Expand Down Expand Up @@ -108,7 +108,7 @@ async def test_cve_changes_change_dates(self):
self.http_client.get.side_effect = create_cve_changes_responses()

it = aiter(
self.api.cve_changes(
self.api.changes(
change_start_date=datetime(2022, 12, 1),
change_end_date=datetime(2022, 12, 31),
)
Expand Down Expand Up @@ -148,7 +148,7 @@ async def test_cve_changes_change_dates(self):
async def test_cve_changes_cve_id(self):
self.http_client.get.side_effect = create_cve_changes_responses()

it = aiter(self.api.cve_changes(cve_id="CVE-1"))
it = aiter(self.api.changes(cve_id="CVE-1"))
cve_changes = await anext(it)

self.assertEqual(cve_changes.cve_id, "CVE-1")
Expand Down Expand Up @@ -179,7 +179,7 @@ async def test_cve_changes_cve_id(self):
async def test_cve_changes_event_name(self):
self.http_client.get.side_effect = create_cve_changes_responses()

it = aiter(self.api.cve_changes(event_name=EventName.INITAL_ANALYSIS))
it = aiter(self.api.changes(event_name=EventName.INITAL_ANALYSIS))
cve_changes = await anext(it)

self.assertEqual(cve_changes.cve_id, "CVE-1")
Expand Down Expand Up @@ -207,13 +207,13 @@ async def test_cve_changes_event_name(self):
with self.assertRaises(StopAsyncIteration):
await anext(it)

@patch("pontos.nvd.cve_change_history.api.now", spec=now)
@patch("pontos.nvd.cve_changes.api.now", spec=now)
async def test_cve_changes_calculate_end_date(self, now_mock: MagicMock):
now_mock.return_value = datetime(2023, 1, 2, tzinfo=timezone.utc)
self.http_client.get.side_effect = create_cve_changes_responses()

it = aiter(
self.api.cve_changes(
self.api.changes(
change_start_date=datetime(2023, 1, 1, tzinfo=timezone.utc)
)
)
Expand All @@ -230,15 +230,15 @@ async def test_cve_changes_calculate_end_date(self, now_mock: MagicMock):
},
)

@patch("pontos.nvd.cve_change_history.api.now", spec=now)
@patch("pontos.nvd.cve_changes.api.now", spec=now)
async def test_cve_changes_calculate_end_date_with_limit(
self, now_mock: MagicMock
):
now_mock.return_value = datetime(2023, 5, 2, tzinfo=timezone.utc)
self.http_client.get.side_effect = create_cve_changes_responses()

it = aiter(
self.api.cve_changes(
self.api.changes(
change_start_date=datetime(2023, 1, 1, tzinfo=timezone.utc)
)
)
Expand All @@ -259,7 +259,7 @@ async def test_cve_changes_calculate_start_date(self):
self.http_client.get.side_effect = create_cve_changes_responses()

it = aiter(
self.api.cve_changes(
self.api.changes(
change_end_date=datetime(2023, 5, 1, tzinfo=timezone.utc)
)
)
Expand All @@ -278,7 +278,7 @@ async def test_cve_changes_calculate_start_date(self):

async def test_cve_changes_range_too_long(self):
it = aiter(
self.api.cve_changes(
self.api.changes(
change_start_date=datetime(2023, 1, 1),
change_end_date=datetime(2023, 5, 2),
)
Expand Down

0 comments on commit 1ba86c4

Please sign in to comment.