Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove file-scoped noqa from NVD #355

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions src/vunnel/providers/nvd/api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# flake8: noqa
from __future__ import annotations

import datetime
import logging
import urllib.parse
from typing import Any, Generator
from typing import TYPE_CHECKING, Any

import orjson
import requests

from vunnel import utils

if TYPE_CHECKING:
from collections.abc import Generator


class NvdAPI:
_cve_api_url_: str = "https://services.nvd.nist.gov/rest/json/cves/2.0"
Expand Down Expand Up @@ -58,7 +60,7 @@ def cve_history(
message="fetching CVE history",
)

def cve(
def cve( # noqa: PLR0913
self,
cve_id: str | None = None,
results_per_page: int
Expand Down Expand Up @@ -99,7 +101,10 @@ def cve(
)

def _request_all_pages(
self, url: str, parameters: dict[str, str], message: str = "fetching results"
self,
url: str,
parameters: dict[str, str],
message: str = "fetching results",
) -> Generator[dict[str, Any], Any, None]:
headers = {
"content-type": "application/json",
Expand Down Expand Up @@ -157,4 +162,4 @@ def _request(self, url: str, parameters: dict[str, str], headers: dict[str, str]
def clean_date(dt: datetime.datetime | str) -> str:
if isinstance(dt, datetime.datetime):
return dt.isoformat()
return datetime.datetime.strptime(dt, "%Y-%m-%d %H:%M").isoformat()
return datetime.datetime.strptime(dt, "%Y-%m-%d %H:%M").isoformat() # noqa: DTZ007
20 changes: 12 additions & 8 deletions src/vunnel/providers/nvd/manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# flake8: noqa
from __future__ import annotations

import datetime
import logging
import os
from typing import Any, Generator

from vunnel.workspace import Workspace
from typing import TYPE_CHECKING, Any

from .api import NvdAPI

if TYPE_CHECKING:
from collections.abc import Generator

from vunnel.workspace import Workspace


class Manager:
def __init__(
Expand All @@ -26,13 +28,15 @@ def __init__(
self.logger = logger

self.api = NvdAPI(api_key=api_key, logger=logger, timeout=download_timeout)
self.urls = [self.api._cve_api_url_]
self.urls = [self.api._cve_api_url_] # noqa: SLF001

def get(
self, last_updated: datetime.datetime | None, skip_if_exists: bool = False
self,
last_updated: datetime.datetime | None,
skip_if_exists: bool = False,
) -> Generator[tuple[str, dict[str, Any]], Any, None]:
if skip_if_exists and self._can_update_incrementally(last_updated):
yield from self._download_updates(last_updated) # type: ignore
yield from self._download_updates(last_updated) # type: ignore # noqa: PGH003
else:
yield from self._download_all()

Expand All @@ -45,7 +49,7 @@ def _can_update_incrementally(self, last_updated: datetime.datetime | None) -> b

if days_since_last_sync >= NvdAPI.max_date_range_days:
self.logger.info(
f"last sync was {days_since_last_sync} days ago (more than {NvdAPI.max_date_range_days} days, the max range value of the NVD API), downloading all data"
f"last sync was {days_since_last_sync} days ago (more than {NvdAPI.max_date_range_days} days, the max range value of the NVD API), downloading all data", # noqa: E501
)
return False

Expand Down
Loading