From 057cb52e7ae8d1b6384e8d31e2283ec9cc23ef3c Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Thu, 9 Nov 2023 14:39:30 -0500 Subject: [PATCH] refactor: use http get wrapper in SLES provider Signed-off-by: Will Murphy --- src/vunnel/providers/sles/parser.py | 14 ++------------ tests/unit/providers/sles/test_sles.py | 8 -------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/vunnel/providers/sles/parser.py b/src/vunnel/providers/sles/parser.py index 805a50f3..45f6c16c 100644 --- a/src/vunnel/providers/sles/parser.py +++ b/src/vunnel/providers/sles/parser.py @@ -8,11 +8,10 @@ from decimal import Decimal, DecimalException from typing import TYPE_CHECKING -import requests from cvss import CVSS3 from cvss.exceptions import CVSS3MalformedError -from vunnel import utils +from vunnel.utils import http from vunnel.utils.oval_v2 import ( ArtifactParser, Impact, @@ -73,7 +72,6 @@ def __init__( # this is pretty odd, but there are classmethods that need logging Parser.logger = logger - @utils.retry_with_backoff() def _download(self, major_version: str) -> str: if not os.path.exists(self.oval_dir_path): self.logger.debug(f"creating workspace for OVAL source data at {self.oval_dir_path}") @@ -88,15 +86,7 @@ def _download(self, major_version: str) -> str: major_version, download_url, ) - r = requests.get(download_url, stream=True, timeout=self.download_timeout) - if r.status_code != 200: - self.logger.error( - "GET %s failed with HTTP %s. Unable to download OVAL file for SLES %s", - download_url, - r.status_code, - major_version, - ) - r.raise_for_status() + r = http.get(download_url, self.logger, stream=True, timeout=self.download_timeout) with open(oval_file_path, "wb") as fp: for chunk in r.iter_content(chunk_size=1024): diff --git a/tests/unit/providers/sles/test_sles.py b/tests/unit/providers/sles/test_sles.py index a2e6f885..4f3193a5 100644 --- a/tests/unit/providers/sles/test_sles.py +++ b/tests/unit/providers/sles/test_sles.py @@ -281,14 +281,6 @@ def test_transform_oval_vulnerabilities(self, parsed_vulnerabilities, helpers): assert actual == parsed_vulnerabilities -@pytest.fixture -def disable_get_requests(monkeypatch): - def disabled(*args, **kwargs): - raise RuntimeError("requests disabled but HTTP GET attempted") - - monkeypatch.setattr(parser.requests, "get", disabled) - - def test_provider_schema(helpers, disable_get_requests, monkeypatch): workspace = helpers.provider_workspace_helper(name=Provider.name())