Skip to content

Commit 5e61f66

Browse files
committed
fixup! feat(text-output): only display introduced secrets unless verbose is enabled
1 parent 5e4d350 commit 5e61f66

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

ggshield/verticals/secret/output/secret_text_output_handler.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import shutil
22
from io import StringIO
3-
from typing import Dict, List, Optional, Tuple
3+
from typing import Dict, List, Optional, Set, Tuple
44

55
from pygitguardian.client import VERSIONS
66
from pygitguardian.models import DiffKind, PolicyBreak
@@ -31,9 +31,9 @@
3131
class SecretTextOutputHandler(SecretOutputHandler):
3232
def _process_scan_impl(self, scan: SecretScanCollection) -> str:
3333
"""Output Secret Scan Collection in text format"""
34-
diff_kinds = [DiffKind.ADDITION]
34+
diff_kinds: Set[DiffKind] = {DiffKind.ADDITION}
3535
if self.verbose:
36-
diff_kinds += [DiffKind.DELETION, DiffKind.CONTEXT]
36+
diff_kinds.update((DiffKind.DELETION, DiffKind.CONTEXT))
3737

3838
processed_scan_results = self.process_scan_results(scan, diff_kinds=diff_kinds)
3939
scan_buf = StringIO()
@@ -77,7 +77,7 @@ def _process_scan_impl(self, scan: SecretScanCollection) -> str:
7777
def process_scan_results(
7878
self,
7979
scan: SecretScanCollection,
80-
diff_kinds: List[DiffKind],
80+
diff_kinds: Set[DiffKind],
8181
show_only_known_secrets: bool = False,
8282
) -> str:
8383
"""Iterate through the scans and sub-scan results to prepare the display."""
@@ -108,7 +108,7 @@ def process_scan_results(
108108
def process_result(
109109
self,
110110
result: Result,
111-
diff_kinds: List[DiffKind],
111+
diff_kinds: Set[DiffKind],
112112
show_only_known_secrets: bool = False,
113113
) -> str:
114114
"""
@@ -122,7 +122,7 @@ def process_result(
122122
result_buf = StringIO()
123123

124124
sha_dict = group_policy_breaks_by_ignore_sha(
125-
result.policy_breaks(diff_kinds=diff_kinds)
125+
result.get_policy_breaks(diff_kinds=diff_kinds)
126126
)
127127

128128
if not self.show_secrets:

ggshield/verticals/secret/secret_scan_collection.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
from dataclasses import dataclass, field
22
from pathlib import Path
3-
from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple, Union, cast
3+
from typing import (
4+
Any,
5+
Dict,
6+
Iterable,
7+
List,
8+
NamedTuple,
9+
Optional,
10+
Set,
11+
Tuple,
12+
Union,
13+
cast,
14+
)
415

516
from pygitguardian import GGClient
617
from pygitguardian.models import (
@@ -77,17 +88,16 @@ def censor(self) -> None:
7788
def has_policy_breaks(self) -> bool:
7889
return self.scan.has_policy_breaks
7990

80-
def policy_breaks(
81-
self, *, diff_kinds: Optional[List[DiffKind]] = None
91+
def get_policy_breaks(
92+
self, *, diff_kinds: Optional[Set[DiffKind]] = None
8293
) -> List[PolicyBreak]:
83-
policy_breaks = self.scan.policy_breaks
8494
if diff_kinds is not None and self.scan.is_diff:
85-
policy_breaks = [
95+
return [
8696
policy_break
8797
for policy_break in self.scan.policy_breaks
8898
if policy_break.diff_kind in diff_kinds
8999
]
90-
return policy_breaks
100+
return self.scan.policy_breaks
91101

92102

93103
class Error(NamedTuple):

0 commit comments

Comments
 (0)