Skip to content

Commit

Permalink
Use RegexBasedDetector.assign_regex_generator (Yelp#215)
Browse files Browse the repository at this point in the history
* feat: use assign regex in cloudant

* feat: use assign regex in db2

* feat: use assign regex in gh

* feat: use assign regex in iam

* feat: use assign regex in sl

* address comments

* address comments

* address comments
  • Loading branch information
XIANJUN ZHU committed Oct 28, 2019
1 parent 7258002 commit a5b485e
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions ibm_cloud_iam.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import absolute_import

import re

import requests

from .base import RegexBasedDetector
Expand All @@ -13,31 +11,17 @@ class IBMCloudIAMDetector(RegexBasedDetector):
secret_type = 'IBM Cloud IAM Key'

# opt means optional
opt_quote = r'(?:"|\'|)'
opt_dashes = r'(?:--|)'
ibm_cloud_iam = r'(?:ibm(?:_|-|)cloud(?:_|-|)iam|cloud(?:_|-|)iam|' + \
r'ibm(?:_|-|)cloud|ibm(?:_|-|)iam|ibm|iam|cloud)'
opt_dash_undrscr = r'(?:_|-|)'
opt_api = r'(?:api|)'
key_or_pass = r'(?:key|pwd|password|pass|token)'
opt_space = r'(?: *)'
opt_assignment = r'(?:=|:|:=|=>|)'
secret = r'([a-zA-z0-9_\-]{44})'
denylist = [
re.compile(
r'{opt_quote}{opt_dashes}{ibm_cloud_iam}{opt_dash_undrscr}{opt_api}{opt_dash_undrscr}'
'{key_or_pass}{opt_quote}{opt_space}{opt_assignment}{opt_space}{opt_quote}'
'{secret}{opt_quote}'.format(
opt_quote=opt_quote,
opt_dashes=opt_dashes,
ibm_cloud_iam=ibm_cloud_iam,
opt_dash_undrscr=opt_dash_undrscr,
opt_api=opt_api,
key_or_pass=key_or_pass,
opt_space=opt_space,
opt_assignment=opt_assignment,
secret=secret,
), flags=re.IGNORECASE,
RegexBasedDetector.assign_regex_generator(
prefix_regex=ibm_cloud_iam + opt_dash_undrscr + opt_api,
password_keyword_regex=key_or_pass,
password_regex=secret,
),
]

Expand Down

0 comments on commit a5b485e

Please sign in to comment.