Skip to content

Commit

Permalink
Output reasons for signatures in verbose mode
Browse files Browse the repository at this point in the history
Potential fix for Issue godaddy#342
  • Loading branch information
mgaspar-godaddy committed Aug 16, 2022
1 parent 7c78708 commit 2a384dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions tartufo/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,21 +384,21 @@ def excluded_signatures(self) -> Tuple[str, ...]:
:returns: The signatures to be excluded from scan results
"""
if self._excluded_signatures is None:
signatures: Set[str] = set()
signatures: Set[Dict[str, str]] = []
deprecated = False
for signature in tuple(
self.global_options.exclude_signatures or []
) + tuple(self.config_data.get("exclude_signatures", [])):
if isinstance(signature, dict):
try:
signatures.add(signature["signature"])
signatures.append(signature)
except KeyError as exc:
raise types.ConfigException(
"Required key signature missing in exclude-signatures"
) from exc
elif isinstance(signature, str):
deprecated = True
signatures.add(signature)
signatures.append({"signature": signature})
else:
raise types.ConfigException(
f"{type(signature).__name__} signature is illegal in exclude-signatures"
Expand All @@ -411,7 +411,7 @@ def excluded_signatures(self) -> Tuple[str, ...]:
"reason of excluding the signature'}]",
DeprecationWarning,
)
self._excluded_signatures = tuple(signatures)
self._excluded_signatures = list(signatures)
return self._excluded_signatures

def signature_is_excluded(self, blob: str, file_path: str) -> bool:
Expand All @@ -420,10 +420,11 @@ def signature_is_excluded(self, blob: str, file_path: str) -> bool:
:param blob: The piece of data which is being scanned
:param file_path: The path and file name for the data being scanned
"""
signature = [str(excluded_signature["signature"]) for excluded_signature in self.excluded_signatures]
return (
blob
in self.excluded_signatures # Signatures themselves pop up as entropy matches
or util.generate_signature(blob, file_path) in self.excluded_signatures
in signature # Signatures themselves pop up as entropy matches
or util.generate_signature(blob, file_path) in signature
)

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions tartufo/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def echo_result(
"output_dir": str(output_dir) if output_dir else None,
"excluded_paths": [str(path.pattern) for path in scanner.excluded_paths],
"excluded_signatures": [
str(signature) for signature in scanner.excluded_signatures
str(signature["signature"]) for signature in scanner.excluded_signatures
],
"exclude_entropy_patterns": [
str(pattern) for pattern in options.exclude_entropy_patterns
Expand Down Expand Up @@ -112,7 +112,7 @@ def echo_result(
click.echo("\nExcluded paths:")
click.echo("\n".join([str(path) for path in scanner.excluded_paths]))
click.echo("\nExcluded signatures:")
click.echo("\n".join(scanner.excluded_signatures))
click.echo("\n".join([str(signature) for signature in scanner.excluded_signatures]))
click.echo("\nExcluded entropy patterns:")
click.echo("\n".join(str(path) for path in scanner.excluded_entropy))

Expand Down

0 comments on commit 2a384dd

Please sign in to comment.