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

refactor: use http get wrapper in SLES provider #393

Merged
merged 1 commit into from
Nov 13, 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
14 changes: 2 additions & 12 deletions src/vunnel/providers/sles/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}")
Expand All @@ -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):
Expand Down
8 changes: 0 additions & 8 deletions tests/unit/providers/sles/test_sles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
Loading