Skip to content

Commit

Permalink
Add label collection to help with multiple label comparisons (#116)
Browse files Browse the repository at this point in the history
* add label collection

Signed-off-by: Alex Goodman <[email protected]>

* update lock file

Signed-off-by: Alex Goodman <[email protected]>

---------

Signed-off-by: Alex Goodman <[email protected]>
  • Loading branch information
wagoodman authored Aug 17, 2023
1 parent a7ea334 commit dc54ea7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 73 deletions.
71 changes: 2 additions & 69 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = [
]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.9"
click = "^8"
dataclasses-json = "^0.5.8"
tabulate = "^0.9.0"
Expand Down
4 changes: 2 additions & 2 deletions src/yardstick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def compare_results_against_labels( # pylint: disable=too-many-arguments
for result in results:
result.matches = matches_filter(result.matches)

if not label_entries:
if label_entries is None:
label_entries = store.labels.load_all(
year_max_limit=year_max_limit,
year_from_cve_only=year_from_cve_only,
Expand All @@ -102,7 +102,7 @@ def compare_results_against_labels_by_ecosystem(
results = store.result_set.load_scan_results(result_set, year_max_limit=year_max_limit, skip_sbom_results=True)
results_by_image = arrange.scan_results_by_image(results)

if not label_entries:
if label_entries is None:
label_entries = store.labels.load_all(year_max_limit=year_max_limit, year_from_cve_only=year_from_cve_only)

stats = comparison.of_results_against_label_by_ecosystem(
Expand Down
10 changes: 10 additions & 0 deletions src/yardstick/artifact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections
import functools
import getpass
import hashlib
import json
Expand Down Expand Up @@ -499,6 +500,15 @@ def effective_year(self, by_cve=False) -> Optional[int]:
return year


class LabelEntryCollection:
def __init__(self, entries: List[LabelEntry]):
self.entries = entries

@functools.cache
def for_image(self, image: str) -> List[LabelEntry]:
return [e for e in self.entries if e.matches_image(image)]


@dataclass()
class ScanRequest:
image: str
Expand Down
1 change: 0 additions & 1 deletion src/yardstick/store/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def load_label_file(
# why note take a file path? in this way we control that all input/output data was derived from the same store,
# and not another store.
path = store_path(filename=filename, store_root=store_root)
logging.debug(f"loading labels location={path}")

try:
with open(path, "r", encoding="utf-8") as data_file:
Expand Down

0 comments on commit dc54ea7

Please sign in to comment.