Skip to content

Commit e454bd8

Browse files
committed
setting DEFAULT_REGEXES variable
1 parent 430759a commit e454bd8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/scrapy_settings_log/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
logger = logging.getLogger(__name__)
1111

12+
DEFAULT_REGEXES = [
13+
".*(?i)(api[\W_]*key).*", # apikey and variations e.g: shub_apikey or SC_APIKEY
14+
".*(?i)(AWS[\W_]*(SECRET[\W_]*)?(ACCESS)?[\W_]*(KEY|ACCESS[\W_]*KEY))", # AWS_SECRET_ACCESS_KEY and variations
15+
".*(?i)([\W_]*password[\W_]*).*" # password word
16+
]
17+
1218

1319
def prepare_for_json_serialization(obj):
1420
"""Prepare the obj recursively for JSON serialization.
@@ -52,12 +58,7 @@ def spider_closed(self, spider):
5258
if regex is not None:
5359
settings = {k: v for k, v in settings.items() if re.search(regex, k)}
5460
if spider.settings.getbool("MASKED_SENSITIVE_SETTINGS_ENABLED", True):
55-
default_regexes = [
56-
".*(?i)(api[\W_]*key).*", # apikey and possible variations e.g: shub_apikey or SC_APIKEY
57-
".*(?i)(AWS[\W_]*(SECRET[\W_]*)?(ACCESS)?[\W_]*(KEY|ACCESS[\W_]*KEY))", # AWS_SECRET_ACCESS_KEY and possible variations
58-
".*(?i)([\W_]*password[\W_]*).*" # password word
59-
]
60-
regex_list = spider.settings.getlist("MASKED_SENSITIVE_SETTINGS_REGEX_LIST", default_regexes)
61+
regex_list = spider.settings.getlist("MASKED_SENSITIVE_SETTINGS_REGEX_LIST", DEFAULT_REGEXES)
6162
for reg in regex_list:
6263
updated_settings = {k: '**********' if v else v for k, v in settings.items() if re.match(reg, k)}
6364
settings = {**settings, **updated_settings}

0 commit comments

Comments
 (0)