Skip to content

Commit

Permalink
nicer secret_generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Loo committed Jan 4, 2019
1 parent 17654e7 commit a599f89
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ test:
clean:
find -name '*.pyc' -delete
find -name '__pycache__' -delete

.PHONY: super-clean
super-clean: clean
rm -rf .tox
rm -rf venv
9 changes: 2 additions & 7 deletions detect_secrets/core/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ..plugins.common import initialize
from ..plugins.common.filetype import determine_file_type
from ..plugins.high_entropy_strings import HighEntropyStringsPlugin
from ..plugins.keyword import KeywordDetector
from .baseline import format_baseline_for_output
from .baseline import merge_results
from .bidirectional_iterator import BidirectionalIterator
Expand Down Expand Up @@ -586,12 +585,8 @@ def _highlight_secret(

def _raw_secret_generator(plugin, secret_line, filetype):
"""Generates raw secrets by re-scanning the line, with the specified plugin"""
if isinstance(plugin, KeywordDetector):
for raw_secret in plugin.secret_generator(secret_line, filetype=filetype):
yield raw_secret
else:
for raw_secret in plugin.secret_generator(secret_line):
yield raw_secret
for raw_secret in plugin.secret_generator(secret_line, filetype=filetype):
yield raw_secret

if issubclass(plugin.__class__, HighEntropyStringsPlugin):
with plugin.non_quoted_string_regex(strict=False):
Expand Down
4 changes: 2 additions & 2 deletions detect_secrets/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def analyze_string(self, string, line_num, filename):
raise NotImplementedError

@abstractmethod
def secret_generator(self, string):
def secret_generator(self, string, *args, **kwargs):
"""Flags secrets in a given string, and yields the raw secret value.
Used in self.analyze_string for PotentialSecret creation.
Expand Down Expand Up @@ -127,7 +127,7 @@ def analyze_string(self, string, line_num, filename):

return output

def secret_generator(self, string):
def secret_generator(self, string, *args, **kwargs):
for regex in self.blacklist:
for match in regex.findall(string):
yield match
2 changes: 1 addition & 1 deletion detect_secrets/plugins/high_entropy_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def analyze_string(self, string, line_num, filename):

return output

def secret_generator(self, string):
def secret_generator(self, string, *args, **kwargs):
# There may be multiple strings on the same line
results = self.regex.findall(string)
for result in results:
Expand Down

0 comments on commit a599f89

Please sign in to comment.