Skip to content

Commit

Permalink
add alpine-linux importer to importer registry
Browse files Browse the repository at this point in the history
Signed-off-by: Tushar Goel <[email protected]>
  • Loading branch information
TG1999 committed Feb 11, 2022
1 parent 34ef7dd commit 7baa3d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
3 changes: 2 additions & 1 deletion vulnerabilities/importers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# VulnerableCode is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
from vulnerabilities.importers import nginx
from vulnerabilities.importers import alpine_linux

IMPORTERS_REGISTRY = [nginx.NginxImporter]
IMPORTERS_REGISTRY = [nginx.NginxImporter, alpine_linux.AlpineImporter]

IMPORTERS_REGISTRY = {x.qualified_name: x for x in IMPORTERS_REGISTRY}
39 changes: 24 additions & 15 deletions vulnerabilities/importers/alpine_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@
# for any legal advice.
# VulnerableCode is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
from typing import Any, Iterable
from typing import Any
from typing import Iterable
from typing import List
from typing import Mapping

import requests
import saneyaml
from bs4 import BeautifulSoup

from vulnerabilities.importer import AdvisoryData
from vulnerabilities.helpers import is_cve
from vulnerabilities.importer import AdvisoryData
from vulnerabilities.importer import Importer
from vulnerabilities.importer import Reference
from vulnerabilities.helpers import is_cve

BASE_URL = "https://secdb.alpinelinux.org/"


class AlpineImporter(Importer):
Expand All @@ -44,6 +43,7 @@ def advisory_data(self) -> Iterable[AdvisoryData]:


def fetch_advisory_links():
BASE_URL = "https://secdb.alpinelinux.org/"
index_page = BeautifulSoup(requests.get(BASE_URL).content, features="lxml")

alpine_versions = [
Expand All @@ -52,34 +52,43 @@ def fetch_advisory_links():

advisory_directory_links = [f"{BASE_URL}{version}" for version in alpine_versions]

advisory_links = []
for advisory_directory_link in advisory_directory_links:
advisory_directory_page = requests.get(advisory_directory_link).content
advisory_directory_page = BeautifulSoup(
advisory_directory_page, features="lxml"
)
yield [
f"{advisory_directory_link}{anchore_tag.text}"
for anchore_tag in advisory_directory_page.find_all("a")
if anchore_tag.text.endswith("yaml")
]
advisory_links.extend(
[
f"{advisory_directory_link}{anchore_tag.text}"
for anchore_tag in advisory_directory_page.find_all("a")
if anchore_tag.text.endswith("yaml")
]
)

return advisory_links


def process_link(link) -> List[AdvisoryData]:
def process_link(link) -> Iterable[Iterable[AdvisoryData]]:
yaml_response = requests.get(link).content
record = saneyaml.load(yaml_response)
advisories: List[AdvisoryData] = []

if record["packages"] is None:
return []
return advisories

for package in record["packages"]:
yield load_advisories(
package["pkg"],
advisories.extend(
load_advisories(
package["pkg"],
)
)
return advisories


def load_advisories(
pkg_infos: Mapping[str, Any],
) -> List[AdvisoryData]:
) -> Iterable[AdvisoryData]:

assert isinstance(pkg_infos["secfixes"], Mapping[str, List])

Expand Down

0 comments on commit 7baa3d2

Please sign in to comment.