Skip to content

Commit

Permalink
Merge pull request #99 from Yelp/whitelist_in_base_plugin
Browse files Browse the repository at this point in the history
check the whitelist regex in the base plugin class  (for #93)
  • Loading branch information
calvinli authored Dec 7, 2018
2 parents 138816f + 5b45888 commit 564615f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions detect_secrets/plugins/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from abc import ABCMeta
from abc import abstractmethod

from detect_secrets.plugins.core.constants import WHITELIST_REGEX


class BasePlugin(object):
"""This is an abstract class to define Plugins API"""
Expand All @@ -23,6 +25,8 @@ def analyze(self, file, filename):
"""
potential_secrets = {}
for line_num, line in enumerate(file.readlines(), start=1):
if WHITELIST_REGEX.search(line):
continue
secrets = self.analyze_string(line, line_num, filename)
potential_secrets.update(secrets)

Expand Down
4 changes: 0 additions & 4 deletions detect_secrets/plugins/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

from .base import BasePlugin
from detect_secrets.core.potential_secret import PotentialSecret
from detect_secrets.plugins.core.constants import WHITELIST_REGEX


BLACKLIST = (
Expand All @@ -54,9 +53,6 @@ class KeywordDetector(BasePlugin):
def analyze_string(self, string, line_num, filename):
output = {}

if WHITELIST_REGEX.search(string):
return output

for identifier in self.secret_generator(string):
secret = PotentialSecret(
self.secret_type,
Expand Down
2 changes: 2 additions & 0 deletions test_data/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ keyB = 456789123
567891234

keyC =

password = 12345678901234 # pragma: whitelist secret

0 comments on commit 564615f

Please sign in to comment.