From b440623b0109304c9900fa5efaa602ef5dec8be2 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Mon, 23 Sep 2019 18:27:45 -0700 Subject: [PATCH] :snake: Remove useless WordListSupportedDetector class --- detect_secrets/plugins/base.py | 25 ------------------- .../plugins/high_entropy_strings.py | 6 ++--- detect_secrets/plugins/keyword.py | 7 +++--- 3 files changed, 7 insertions(+), 31 deletions(-) diff --git a/detect_secrets/plugins/base.py b/detect_secrets/plugins/base.py index bc654039..2e8bc8a2 100644 --- a/detect_secrets/plugins/base.py +++ b/detect_secrets/plugins/base.py @@ -239,28 +239,3 @@ def secret_generator(self, string, *args, **kwargs): for regex in self.denylist: for match in regex.findall(string): yield match - - -class WordListSupportedDetector(BasePlugin): - """Parent class for detectors supporting a word list. - - To create a new word list supported detector, subclass this - and pass `automaton` in __init__ like: - - class BarDetector(WordListSupportedDetector): - - secret_type = "bar" - - def __init__(self, automaton=None, **kwargs): - super(BarDetector, self).__init__( - automaton, - **kwargs - ) - ... - """ - __metaclass__ = ABCMeta - - def __init__(self, automaton=None, **kwargs): - super(WordListSupportedDetector, self).__init__(**kwargs) - - self.automaton = automaton diff --git a/detect_secrets/plugins/high_entropy_strings.py b/detect_secrets/plugins/high_entropy_strings.py index caedfc09..ee3ce363 100644 --- a/detect_secrets/plugins/high_entropy_strings.py +++ b/detect_secrets/plugins/high_entropy_strings.py @@ -14,7 +14,7 @@ import yaml -from .base import WordListSupportedDetector +from .base import BasePlugin from .common.filetype import determine_file_type from .common.filetype import FileType from .common.filters import is_false_positive @@ -23,7 +23,7 @@ from detect_secrets.core.potential_secret import PotentialSecret -class HighEntropyStringsPlugin(WordListSupportedDetector): +class HighEntropyStringsPlugin(BasePlugin): """Base class for string pattern matching""" __metaclass__ = ABCMeta @@ -38,11 +38,11 @@ def __init__(self, charset, limit, exclude_lines_regex, automaton, *args): self.charset = charset self.entropy_limit = limit + self.automaton = automaton self.regex = re.compile(r'([\'"])([%s]+)(\1)' % charset) super(HighEntropyStringsPlugin, self).__init__( exclude_lines_regex=exclude_lines_regex, - automaton=automaton, ) def analyze(self, file, filename): diff --git a/detect_secrets/plugins/keyword.py b/detect_secrets/plugins/keyword.py index d7526937..ec3edd17 100644 --- a/detect_secrets/plugins/keyword.py +++ b/detect_secrets/plugins/keyword.py @@ -28,7 +28,7 @@ import re -from .base import WordListSupportedDetector +from .base import BasePlugin from .common.filetype import determine_file_type from .common.filetype import FileType from .common.filters import is_false_positive @@ -247,7 +247,7 @@ } -class KeywordDetector(WordListSupportedDetector): +class KeywordDetector(BasePlugin): """This checks if denylisted keywords are present in the analyzed string. """ @@ -257,7 +257,6 @@ class KeywordDetector(WordListSupportedDetector): def __init__(self, keyword_exclude=None, exclude_lines_regex=None, automaton=None, **kwargs): super(KeywordDetector, self).__init__( exclude_lines_regex=exclude_lines_regex, - automaton=automaton, **kwargs ) @@ -268,6 +267,8 @@ def __init__(self, keyword_exclude=None, exclude_lines_regex=None, automaton=Non re.IGNORECASE, ) + self.automaton = automaton + def analyze_string_content(self, string, line_num, filename): output = {} if (