Skip to content

Commit 0c62cc3

Browse files
committed
chore: rename detector in detector_display_name
1 parent bf9b526 commit 0c62cc3

12 files changed

+38
-25
lines changed

changelog.d/20250423_102414_salome.voltz_scrt_5438_ggshield_for_each_detected_secret_add_a_link_towards_our.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ Uncomment the section that is right (remove the HTML comment wrapper).
1313

1414
### Added
1515

16-
- Extra information in scan results (detector name, detector group name and documentation URL).
17-
- Link to detector documentation in text output.
16+
- `ggshield secret scan` output now contains a link to the detector documentation for each secret found.
1817

1918
<!--
2019
### Changed

ggshield/verticals/secret/output/secret_gitlab_webui_output_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def format_secret(secret: Secret) -> str:
1717
f'{x.match_type}: "{censor_match(x)}"' for x in secret.matches
1818
)
1919
validity = translate_validity(secret.validity)
20-
return f"{secret.detector} (Validity: {validity}, {match_str})"
20+
return f"{secret.detector_display_name} (Validity: {validity}, {match_str})"
2121

2222

2323
class SecretGitLabWebUIOutputHandler(SecretOutputHandler):

ggshield/verticals/secret/output/secret_json_output_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def serialized_secret(
118118
"occurrences": [],
119119
"ignore_sha": ignore_sha,
120120
"policy": secrets[0].policy,
121-
"detector": secrets[0].detector,
121+
"detector": secrets[0].detector_display_name,
122122
"total_occurrences": len(secrets),
123123
}
124124

ggshield/verticals/secret/output/secret_sarif_output_handler.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ def _create_sarif_result_dict(
7676
f"- [{m.match_type}]({id})" for id, m in enumerate(secret.matches)
7777
)
7878
extended_matches = cast(List[ExtendedMatch], secret.matches)
79-
message = f"Secret detected: {secret.detector}.\nMatches: {matches_str}"
80-
markdown_message = f"Secret detected: {secret.detector}\nMatches:\n{matches_li}"
79+
message = (
80+
f"Secret detected: {secret.detector_display_name}.\nMatches: {matches_str}"
81+
)
82+
markdown_message = (
83+
f"Secret detected: {secret.detector_display_name}\nMatches:\n{matches_li}"
84+
)
8185

8286
# Create dict
8387
dct = {
84-
"ruleId": secret.detector,
88+
"ruleId": secret.detector_display_name,
8589
"level": "error",
8690
"message": {
8791
"text": message,

ggshield/verticals/secret/output/secret_text_output_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def secret_header(
297297
)
298298

299299
start_line = format_text(">>", STYLE["detector_line_start"])
300-
secret_type = format_text(secret.detector, STYLE["secret_type"])
300+
secret_type = format_text(secret.detector_display_name, STYLE["secret_type"])
301301
number_occurrences = format_text(str(len(secrets)), STYLE["occurrence_count"])
302302
ignore_sha = format_text(ignore_sha, STYLE["ignore_sha"])
303303

ggshield/verticals/secret/secret_scan_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Secret:
8383
Named Secret since we are dropping other kind of policy breaks.
8484
"""
8585

86-
detector: str # Detector display name
86+
detector_display_name: str
8787
detector_name: str
8888
detector_group_name: str
8989
documentation_url: Optional[str]
@@ -189,7 +189,7 @@ def from_scan_result(
189189
validity=policy_break.validity,
190190
known_secret=policy_break.known_secret,
191191
incident_url=policy_break.incident_url,
192-
detector=policy_break.break_type,
192+
detector_display_name=policy_break.break_type,
193193
detector_name=policy_break.detector_name,
194194
detector_group_name=policy_break.detector_group_name,
195195
documentation_url=policy_break.documentation_url,

ggshield/verticals/secret/secret_scanner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def _collect_results(
216216
result = Result.from_scan_result(file, scan_result, self.secret_config)
217217
for secret in result.secrets:
218218
self.cache.add_found_policy_break(
219-
secret.detector,
219+
secret.detector_display_name,
220220
secret.get_ignore_sha(),
221221
file.filename,
222222
)

tests/factories.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ class SecretFactory(factory.Factory):
9797
class Meta:
9898
model = Secret
9999

100-
detector = factory.lazy_attribute(lambda obj: random.choice(DETECTOR_NAMES))
101-
detector_name = factory.lazy_attribute(lambda obj: obj.detector)
102-
detector_group_name = factory.lazy_attribute(lambda obj: obj.detector)
100+
detector_display_name = factory.lazy_attribute(
101+
lambda obj: random.choice(DETECTOR_NAMES)
102+
)
103+
detector_name = factory.lazy_attribute(lambda obj: obj.detector_display_name)
104+
detector_group_name = factory.lazy_attribute(lambda obj: obj.detector_display_name)
103105
documentation_url = None
104106
validity = "valid"
105107
known_secret = True

tests/unit/verticals/secret/output/test_gitlab_webui_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_format_secret():
1818
)
1919
out = format_secret(secret)
2020

21-
assert secret.detector in out
21+
assert secret.detector_display_name in out
2222
assert "Validity: Valid" in out
2323
for match in secret.matches:
2424
assert match.match_type in out

tests/unit/verticals/secret/output/test_json_output.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,18 @@ def test_ignore_known_secrets(verbose, ignore_known_secrets, secrets_types):
509509
incident_for_secret_type = {incident["type"]: incident for incident in incidents}
510510

511511
for secret in known_secrets:
512-
assert incident_for_secret_type[secret.detector]["known_secret"]
513-
assert incident_for_secret_type[secret.detector]["incident_url"].startswith(
514-
"https://dashboard.gitguardian.com/workspace/1/incidents/"
515-
)
512+
assert incident_for_secret_type[secret.detector_display_name]["known_secret"]
513+
assert incident_for_secret_type[secret.detector_display_name][
514+
"incident_url"
515+
].startswith("https://dashboard.gitguardian.com/workspace/1/incidents/")
516516

517517
for secret in new_secrets:
518-
assert not incident_for_secret_type[secret.detector]["known_secret"]
519-
assert not incident_for_secret_type[secret.detector]["incident_url"]
518+
assert not incident_for_secret_type[secret.detector_display_name][
519+
"known_secret"
520+
]
521+
assert not incident_for_secret_type[secret.detector_display_name][
522+
"incident_url"
523+
]
520524

521525

522526
@pytest.mark.parametrize("with_incident_details", [True, False])

0 commit comments

Comments
 (0)