Skip to content

Commit f8fbf83

Browse files
author
Aaron Loo
committed
Merge branch 'master' of github.com:Yelp/detect-secrets into feature/adding-alphanumerical-filter
2 parents e819add + c86ca85 commit f8fbf83

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ For baselines older than version 0.9, just recreate it.
7171
**Scanning Staged Files Only:**
7272

7373
```bash
74-
$ detect-secret-hook --baseline .secrets.baseline $(git diff --staged --name-only)
74+
$ detect-secrets-hook --baseline .secrets.baseline $(git diff --staged --name-only)
7575
```
7676

7777
**Scanning All Tracked Files:**

detect_secrets/core/log.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ def set_debug_level(self, debug_level: int) -> None:
6464
)
6565

6666

67-
log = get_logger()
67+
log = get_logger('detect-secrets')

detect_secrets/filters/heuristic.py

+12
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,15 @@ def is_not_alphanumeric_string(secret: str) -> bool:
203203
This helps avoid clear false positives, like `*****`.
204204
"""
205205
return not bool(set(string.ascii_letters) & set(secret))
206+
207+
208+
def is_swagger_file(filename: str) -> bool:
209+
"""
210+
Filters swagger files and paths, like swagger-ui.html or /swagger/.
211+
"""
212+
return bool(_get_swagger_regex().search(filename))
213+
214+
215+
@lru_cache(maxsize=1)
216+
def _get_swagger_regex() -> Pattern:
217+
return re.compile(r'.*swagger.*')

detect_secrets/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def clear(self) -> None:
120120
'detect_secrets.filters.heuristic.is_indirect_reference',
121121
'detect_secrets.filters.heuristic.is_lock_file',
122122
'detect_secrets.filters.heuristic.is_not_alphanumeric_string',
123+
'detect_secrets.filters.heuristic.is_swagger_file',
123124
}
124125
}
125126

docs/filters.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ the `detect_secrets.filters` namespace.
5555
| `heuristic.is_potential_uuid` | Ignores uuid looking secret values. |
5656
| `heuristic.is_prefixed_with_dollar_sign` | Primarily for `KeywordDetector`, filters secrets like `secret = $variableName;`. |
5757
| `heuristic.is_sequential_string` | Ignores secrets like `abcdefg`. |
58+
| `heuristic.is_swagger_file` | Ignores swagger files and paths, like swagger-ui.html or /swagger/. |
5859
| `heuristic.is_templated_secret` | Ignores secrets like `secret = <key>`, `secret = {{key}}` and `secret = ${key}`. |
5960
| `regex.should_exclude_line` | Powers the [`--exclude-lines` functionality](../README.md#--exclude-lines). |
6061
| `regex.should_exclude_file` | Powers the [`--exclude-files` functionality](../README.md#--exclude-files). |

requirements-dev.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pycodestyle==2.3.1
2727
pyflakes==1.6.0
2828
pyparsing==2.4.7
2929
pytest==6.1.2
30-
PyYAML==5.3.1
30+
PyYAML==5.4
3131
requests==2.25.0
3232
responses==0.12.1
3333
six==1.15.0
@@ -37,6 +37,6 @@ tox-pip-extensions==1.6.0
3737
typed-ast==1.4.1
3838
typing-extensions==3.7.4.3
3939
unidiff==0.6.0
40-
urllib3==1.26.2
40+
urllib3==1.26.3
4141
virtualenv==20.2.1
4242
zipp==3.4.0

tests/filters/heuristic_filter_test.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import pytest
24

35
from detect_secrets import filters
@@ -141,3 +143,15 @@ def test_is_lock_file():
141143
)
142144
def test_is_not_alphanumeric_string(secret, result):
143145
assert filters.heuristic.is_not_alphanumeric_string(secret) is result
146+
147+
148+
@pytest.mark.parametrize(
149+
'filename, result',
150+
(
151+
('{sep}path{sep}swagger-ui.html', True),
152+
('{sep}path{sep}swagger{sep}config.yml', True),
153+
('{sep}path{sep}non{sep}swager{sep}files', False),
154+
),
155+
)
156+
def test_is_swagger_file(filename, result):
157+
assert filters.heuristic.is_swagger_file(filename.format(sep=os.path.sep)) is result

0 commit comments

Comments
 (0)