Generate a translation of Advisory data - returned by the importers - into full confidence inferences. These are basic database relationships for unstructured data present in the Advisory model without any other information source.
| 29 | |
| 30 | |
| 31 | class DefaultImprover(Improver): |
| 32 | """ |
| 33 | Generate a translation of Advisory data - returned by the importers - into |
| 34 | full confidence inferences. These are basic database relationships for |
| 35 | unstructured data present in the Advisory model without any other |
| 36 | information source. |
| 37 | """ |
| 38 | |
| 39 | importer: Importer |
| 40 | |
| 41 | @property |
| 42 | def interesting_advisories(self) -> QuerySet: |
| 43 | if hasattr(self, "importer"): |
| 44 | return ( |
| 45 | Advisory.objects.filter(Q(created_by=self.importer.qualified_name)) |
| 46 | .order_by("-date_collected") |
| 47 | .paginated() |
| 48 | ) |
| 49 | return Advisory.objects.all().order_by("-date_collected").paginated() |
| 50 | |
| 51 | def get_inferences(self, advisory_data: AdvisoryData) -> Iterable[Inference]: |
| 52 | if not advisory_data: |
| 53 | return [] |
| 54 | |
| 55 | if advisory_data.affected_packages: |
| 56 | for affected_package in advisory_data.affected_packages: |
| 57 | # To deal with multiple fixed versions in a single affected package |
| 58 | affected_purls, fixed_purls = get_exact_purls(affected_package) |
| 59 | if not fixed_purls: |
| 60 | yield Inference( |
| 61 | aliases=advisory_data.aliases, |
| 62 | confidence=MAX_CONFIDENCE, |
| 63 | summary=advisory_data.summary, |
| 64 | affected_purls=affected_purls, |
| 65 | fixed_purl=None, |
| 66 | references=advisory_data.references, |
| 67 | weaknesses=advisory_data.weaknesses, |
| 68 | ) |
| 69 | else: |
| 70 | for fixed_purl in fixed_purls or []: |
| 71 | yield Inference( |
| 72 | aliases=advisory_data.aliases, |
| 73 | confidence=MAX_CONFIDENCE, |
| 74 | summary=advisory_data.summary, |
| 75 | affected_purls=affected_purls, |
| 76 | fixed_purl=fixed_purl, |
| 77 | references=advisory_data.references, |
| 78 | weaknesses=advisory_data.weaknesses, |
| 79 | ) |
| 80 | |
| 81 | else: |
| 82 | yield Inference.from_advisory_data( |
| 83 | advisory_data, confidence=MAX_CONFIDENCE, fixed_purl=None |
| 84 | ) |
| 85 | |
| 86 | |
| 87 | def get_exact_purls(affected_package: AffectedPackage) -> Tuple[List[PackageURL], PackageURL]: |
no outgoing calls