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

Fix improver framework not accepting severities #684

Merged
merged 2 commits into from
Apr 8, 2022
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
8 changes: 4 additions & 4 deletions vulnerabilities/import_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ class ImportRunner:
- No valid data from the data source must be skipped or truncated.
"""

def __init__(self, importer: Importer):
self.importer = importer
def __init__(self, importer_class: Importer):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your type annotation is now incorrect?

self.importer_class = importer_class

def run(self) -> None:
"""
Create a data source for the given importer and store the data retrieved in the database.
"""
importer_name = self.importer.qualified_name
importer_class = self.importer
importer_name = self.importer_class.qualified_name
importer_class = self.importer_class
logger.info(f"Starting import for {importer_name}")
advisory_datas = importer_class().advisory_data()
count = process_advisories(advisory_datas=advisory_datas, importer_name=importer_name)
Expand Down
12 changes: 6 additions & 6 deletions vulnerabilities/improve_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ class ImproveRunner:
improver and parsing the returned Inferences into proper database fields
"""

def __init__(self, improver):
self.improver = improver
def __init__(self, improver_class):
self.improver_class = improver_class

def run(self) -> None:
improver = self.improver()
improver = self.improver_class()
logger.info(f"Running improver: {improver.qualified_name}")
for advisory in improver.interesting_advisories:
inferences = improver.get_inferences(advisory_data=advisory.to_advisory_data())
process_inferences(
inferences=inferences, advisory=advisory, improver_name=improver.qualified_name
)
logger.info("Finished improving using %s.", self.improver.qualified_name)
logger.info("Finished improving using %s.", self.improver_class.qualified_name)


@transaction.atomic
Expand Down Expand Up @@ -62,15 +62,15 @@ def process_inferences(inferences: List[Inference], advisory: Advisory, improver
continue

for ref in inference.references:
ref, _ = models.VulnerabilityReference.objects.get_or_create(
reference, _ = models.VulnerabilityReference.objects.get_or_create(
vulnerability=vuln, reference_id=ref.reference_id, url=ref.url
)

for severity in ref.severities:
obj, updated = models.VulnerabilitySeverity.objects.update_or_create(
vulnerability=vuln,
scoring_system=severity.system.identifier,
reference=ref,
reference=reference,
defaults={"value": str(severity.value)},
)
if updated:
Expand Down