MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / IstioImporter

Class IstioImporter

vulnerabilities/importers/istio.py:41–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40
41class IstioImporter(Importer):
42 spdx_license_expression = "Apache-2.0"
43 license_url = "https://github.com/istio/istio.io/blob/master/LICENSE"
44 repo_url = "git+https://github.com/istio/istio.io/"
45 importer_name = "Istio Importer"
46
47 def advisory_data(self) -> Set[AdvisoryData]:
48 try:
49 self.clone(repo_url=self.repo_url)
50 base_path = Path(self.vcs_response.dest_dir)
51 vuln = base_path / "content/en/news/security/"
52 for file in vuln.glob("**/*.md"):
53 # Istio website has files with name starting with underscore, these contain metadata
54 # required for rendering the website. We're not interested in these.
55 # See also https://github.com/nexB/vulnerablecode/issues/563
56 file = str(file)
57 if file.endswith("_index.md"):
58 continue
59 yield from self.process_file(file=file, base_path=base_path)
60 finally:
61 if self.vcs_response:
62 self.vcs_response.delete()
63
64 def process_file(self, file, base_path):
65 advisory_url = get_advisory_url(
66 file, base_path, url="https://github.com/istio/istio.io/blob/master/"
67 )
68 data = self.get_data_from_md(file)
69 published_date = data.get("publishdate")
70 release_date = None
71 if published_date:
72 release_date = parser.parse(published_date).replace(tzinfo=pytz.UTC)
73
74 constraints = []
75
76 for release in data.get("releases") or []:
77 # If it is of form "All releases prior to x"
78 if "All releases prior" in release:
79 _, _, release = release.strip().rpartition(" ")
80 constraints.append(
81 VersionConstraint(version=SemverVersion(release), comparator="<")
82 )
83
84 # Eg. 'All releases 1.5 and later'
85 elif "All releases" in release and "and later" in release:
86 # remove All releases from string
87 release = release.replace("All releases", "").strip()
88 # remove and later from string
89 release = release.replace("and later", "").strip()
90 if not is_release(release):
91 continue
92 constraints.append(
93 VersionConstraint(version=SemverVersion(release), comparator=">=")
94 )
95
96 # Eg. 1.5 to 2.0
97 elif "to" in release:
98 lower, _, upper = release.strip().partition("to")

Callers 2

test_istio_process_fileFunction · 0.90

Calls

no outgoing calls

Tested by 2

test_istio_process_fileFunction · 0.72