Skip to content

Commit

Permalink
🐍 Remove useless WordListSupportedDetector class
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinHock committed Sep 24, 2019
1 parent 19d22da commit b440623
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
25 changes: 0 additions & 25 deletions detect_secrets/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions detect_secrets/plugins/high_entropy_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions detect_secrets/plugins/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -247,7 +247,7 @@
}


class KeywordDetector(WordListSupportedDetector):
class KeywordDetector(BasePlugin):
"""This checks if denylisted keywords
are present in the analyzed string.
"""
Expand All @@ -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
)

Expand All @@ -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 (
Expand Down

0 comments on commit b440623

Please sign in to comment.