Skip to content

Commit b262bbf

Browse files
committed
refactor: rename automatic_linkage module and its internal functions
1 parent 72b4dfb commit b262bbf

5 files changed

Lines changed: 23 additions & 27 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ By discussing issues with security team members and other maintainers, they can
1717

1818
## Contributing
1919

20-
Please see the [**Contributing Guide**](CONTRIBUTING.md) for more information on how to get started.
20+
Please see the [**Contributing Guide**](CONTRIBUTING.md) for more information on how to get started.

src/shared/listeners/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import shared.listeners.nix_channels # noqa
22
import shared.listeners.nix_evaluation # noqa
3-
import shared.listeners.automatic_linkage # noqa
3+
import shared.listeners.cve_derivation_matcher # noqa
44
import shared.listeners.cache_suggestions # noqa
55
import shared.listeners.notify_users # noqa

src/shared/listeners/automatic_linkage.py renamed to src/shared/listeners/cve_derivation_matcher.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
logger = logging.getLogger(__name__)
1717

1818

19-
def produce_linkage_candidates(
19+
def find_linkage_candidates(
2020
container: Container,
2121
) -> dict[NixDerivation, ProvenanceFlags]:
2222
latest_complete_channels = (
@@ -93,22 +93,20 @@ def produce_linkage_candidates(
9393
return candidates
9494

9595

96-
def build_new_links(container: Container) -> bool:
96+
def create_derivation_proposal(container: Container) -> bool:
9797
if container.cve.triaged:
9898
logger.info(
99-
"Container received for '%s', but already triaged, skipping linkage.",
100-
container.cve,
99+
f"Container received for {container.cve}, but already triaged, skipping linkage.",
101100
)
102101
return False
103102

104103
if CVEDerivationClusterProposal.objects.filter(cve=container.cve).exists():
105-
logger.info("Suggestion already exists for '%s', skipping", container.cve)
104+
logger.info(f"Suggestion already exists for {container.cve}, skipping")
106105
return False
107106

108107
if container.tags.filter(value="exclusively-hosted-service").exists():
109108
logger.info(
110-
"Container for '%s' is exclusively-hosted-service, rejecting without match.",
111-
container.cve,
109+
f"Container for {container.cve} is exclusively-hosted-service, rejecting without match.",
112110
)
113111
CVEDerivationClusterProposal.objects.create(
114112
cve=container.cve,
@@ -117,16 +115,14 @@ def build_new_links(container: Container) -> bool:
117115
)
118116
return True
119117

120-
drvs = produce_linkage_candidates(container)
118+
drvs = find_linkage_candidates(container)
121119
if not drvs:
122-
logger.info("No derivations matching '%s', ignoring", container.cve)
120+
logger.info(f"No derivations matching {container.cve}, ignoring")
123121
return False
124122

125123
if len(drvs) > settings.MAX_MATCHES:
126124
logger.warning(
127-
"More than '%d' derivations matching '%s', ignoring",
128-
settings.MAX_MATCHES,
129-
container.cve,
125+
f"More than {settings.MAX_MATCHES} derivations matching {container.cve}, ignoring",
130126
)
131127
return False
132128

@@ -144,14 +140,12 @@ def build_new_links(container: Container) -> bool:
144140

145141
if drvs_throughs:
146142
logger.info(
147-
"Matching suggestion for '%s': %d derivations found.",
148-
container.cve,
149-
len(drvs_throughs),
143+
f"Matching suggestion for {container.cve}: {len(drvs_throughs)} derivations found.",
150144
)
151145

152146
return True
153147

154148

155149
@pgpubsub.post_insert_listener(ContainerChannel)
156-
def build_new_links_following_new_containers(old: Container, new: Container) -> None:
157-
build_new_links(new)
150+
def match_derivations_on_container_insert(old: Container, new: Container) -> None:
151+
create_derivation_proposal(new)

src/shared/management/commands/propose_cve_links.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django.core.management.base import BaseCommand, CommandError
88

99
from shared import models
10-
from shared.listeners.automatic_linkage import build_new_links
10+
from shared.listeners.cve_derivation_matcher import create_derivation_proposal
1111

1212
logger = logging.getLogger(__name__)
1313

@@ -40,15 +40,17 @@ def handle(self, *args: Any, **kwargs: Any) -> None:
4040
except ValueError:
4141
raise CommandError(f"Not a valid delta format: {_delta}")
4242

43-
logger.info("Proposing new CVE links starting '%s'", since_date.isoformat())
43+
logger.info(f"Proposing new CVE links starting {since_date.isoformat()}")
4444
success = Counter()
4545
# Collect all containers since that delta range.
4646
containers = models.Container.objects.filter(date_public__gte=since_date)
4747

4848
for container in containers.iterator():
49-
success[container.cve.cve_id] += 1 if build_new_links(container) else 0
49+
success[container.cve.cve_id] += (
50+
1 if create_derivation_proposal(container) else 0
51+
)
5052
print(".", end="", flush=True)
5153

5254
for cve_id, successes in success.items():
5355
if successes == 0:
54-
logger.warning("No derivation found for '%s', linkage failure.", cve_id)
56+
logger.warning(f"No derivation found for {cve_id}, linkage failure.")

src/shared/tests/test_linkage.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import pytest
55

6-
from shared.listeners.automatic_linkage import build_new_links
76
from shared.listeners.cache_suggestions import cache_new_suggestions
7+
from shared.listeners.cve_derivation_matcher import create_derivation_proposal
88
from shared.models.cve import Container, Tag
99
from shared.models.linkage import (
1010
CVEDerivationClusterProposal,
@@ -67,7 +67,7 @@ def test_link_only_latest_eval(
6767
)
6868

6969
container = make_container(package_name="foo", affected_version="<3.2")
70-
match = build_new_links(container)
70+
match = create_derivation_proposal(container)
7171
assert match
7272
suggestion = CVEDerivationClusterProposal.objects.first()
7373
assert suggestion
@@ -113,7 +113,7 @@ def test_link_product_or_package_name(
113113
container = make_container(package_name=package_name, product=product)
114114
drv = make_drv(pname=drv_pname)
115115

116-
match = build_new_links(container)
116+
match = create_derivation_proposal(container)
117117

118118
if expected_flags:
119119
assert match
@@ -133,7 +133,7 @@ def test_exclusively_hosted_service_creates_rejected_proposal(
133133
tag, _ = Tag.objects.get_or_create(value="exclusively-hosted-service")
134134
container.tags.add(tag)
135135

136-
result = build_new_links(container)
136+
result = create_derivation_proposal(container)
137137

138138
assert result is True
139139
proposal = CVEDerivationClusterProposal.objects.get(cve=container.cve)

0 commit comments

Comments
 (0)