Skip to content

Commit 0cab5f9

Browse files
committed
Modify Elixir Security v2 importer pipeline to support package-first mode #1933
Signed-off-by: Michael Ehab Mikhail <michael.ehab@hotmail.com>
1 parent b40bb9b commit 0cab5f9

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

vulnerabilities/pipelines/v2_importers/elixir_security_importer.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,36 @@ class ElixirSecurityImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
4141
repo_url = "git+https://github.com/dependabot/elixir-security-advisories"
4242
unfurl_version_ranges = True
4343

44-
def __init__(self, *args, **kwargs):
44+
is_batch_run = True
45+
46+
def __init__(self, *args, purl=None, **kwargs):
4547
super().__init__(*args, **kwargs)
46-
self.purl = kwargs.get("purl")
48+
self.purl = purl
4749
if self.purl:
50+
ElixirSecurityImporterPipeline.is_batch_run = False
4851
if self.purl.type != "hex":
4952
self.log(
5053
f"Warning: PURL type {self.purl.type} is not 'hex', may not match any advisories"
5154
)
5255

5356
@classmethod
5457
def steps(cls):
58+
if not cls.is_batch_run:
59+
return (cls.collect_and_store_advisories,)
5560
return (cls.clone, cls.collect_and_store_advisories, cls.clean_downloads)
5661

5762
def clean_downloads(self):
58-
if self.vcs_response:
63+
if self.is_batch_run and self.vcs_response:
5964
self.log(f"Removing cloned repository")
6065
self.vcs_response.delete()
6166

6267
def clone(self):
63-
self.log(f"Cloning `{self.repo_url}`")
64-
self.vcs_response = fetch_via_vcs(self.repo_url)
68+
if self.is_batch_run:
69+
self.log(f"Cloning `{self.repo_url}`")
70+
self.vcs_response = fetch_via_vcs(self.repo_url)
6571

6672
def advisories_count(self) -> int:
67-
if self.purl:
73+
if not self.is_batch_run:
6874
return self._count_package_advisories()
6975

7076
base_path = Path(self.vcs_response.dest_dir)
@@ -88,7 +94,7 @@ def _count_package_advisories(self) -> int:
8894
return 0
8995

9096
def collect_advisories(self) -> Iterable[AdvisoryData]:
91-
if self.purl:
97+
if not self.is_batch_run:
9298
return self._collect_package_advisories()
9399

94100
return self._collect_batch_advisories()

0 commit comments

Comments
 (0)