Skip to content

Commit

Permalink
use https.OK
Browse files Browse the repository at this point in the history
Signed-off-by: thebigbone <pacman@duck.com>
  • Loading branch information
thebigbone committed Mar 30, 2024
1 parent 4a6734b commit 198f16a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions vulnerabilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from unittest.mock import MagicMock
from urllib.parse import urljoin
from uuid import uuid4
from http import HTTPStatus

import requests
import saneyaml
Expand Down Expand Up @@ -167,14 +168,17 @@ def nearest_patched_package(
Return a list of Affected Packages for each Patched package.
"""

vulnerable_packages = sorted([VersionedPackage(package) for package in vulnerable_packages])
resolved_packages = sorted([VersionedPackage(package) for package in resolved_packages])
vulnerable_packages = sorted(
[VersionedPackage(package) for package in vulnerable_packages])
resolved_packages = sorted([VersionedPackage(package)
for package in resolved_packages])

resolved_package_count = len(resolved_packages)
affected_package_with_patched_package_objects = []

for vulnerable_package in vulnerable_packages:
patched_package_index = bisect.bisect_right(resolved_packages, vulnerable_package)
patched_package_index = bisect.bisect_right(
resolved_packages, vulnerable_package)
patched_package = None
if patched_package_index < resolved_package_count:
patched_package = resolved_packages[patched_package_index]
Expand Down Expand Up @@ -405,7 +409,7 @@ def base32_custom(btes):
from_bytes = int.from_bytes

for i in range(0, len(btes), 5):
c = from_bytes(btes[i : i + 5], "big")
c = from_bytes(btes[i: i + 5], "big")
encoded += (
_base32_table[c >> 30]
+ _base32_table[(c >> 20) & 0x3FF] # bits 1 - 10
Expand All @@ -420,9 +424,10 @@ def fetch_response(url):
Fetch and return `response` from the `url`
"""
response = requests.get(url)
if response.status_code == 200:
if response.status_code == HTTPStatus.OK:
return response
raise Exception(f"Failed to fetch data from {url!r} with status code: {response.status_code!r}")
raise Exception(
f"Failed to fetch data from {url!r} with status code: {response.status_code!r}")


# This should be a method on PackageURL
Expand Down

0 comments on commit 198f16a

Please sign in to comment.