Skip to content

Commit 3f806f1

Browse files
authoredAug 1, 2021
↪️Merge pull request #463 from ninoseki/add-plugin-for-sendgrid
Add a plugin for SendGrid
2 parents a1ab77d + 232d21d commit 3f806f1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
 

‎detect_secrets/plugins/sendgrid.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
This plugin searches for SendGrid API keys
3+
"""
4+
import re
5+
6+
from detect_secrets.plugins.base import RegexBasedDetector
7+
8+
9+
class SendGridDetector(RegexBasedDetector):
10+
"""Scans for SendGrid API keys."""
11+
secret_type = 'SendGrid API key'
12+
13+
denylist = [
14+
# SendGrid API key
15+
# ref. https://d2w67tjf43xwdp.cloudfront.net/Classroom/Basics/API/what_is_my_api_key.html
16+
re.compile(r'SG\.[a-zA-Z0-9_-]{22}\.[a-zA-Z0-9_-]{43}'),
17+
]

‎tests/plugins/sendgrid_test.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
3+
from detect_secrets.plugins.sendgrid import SendGridDetector
4+
5+
6+
class TestSendGridDetector:
7+
8+
@pytest.mark.parametrize(
9+
'payload, should_flag',
10+
[
11+
('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', True),
12+
('SG.ngeVfQFYQlKU0ufo8x5d1A..TwL2iGABf9DHoTf-09kqeF8tAmbihYzrnopKc-1s5cr', False),
13+
('AG.ngeVfQFYQlKU0ufo8x5d1A.TwL2iGABf9DHoTf-09kqeF8tAmbihYzrnopKc-1s5cr', False),
14+
('foo', False),
15+
],
16+
)
17+
def test_analyze(self, payload, should_flag):
18+
logic = SendGridDetector()
19+
output = logic.analyze_line(filename='mock_filename', line=payload)
20+
assert len(output) == int(should_flag)

0 commit comments

Comments
 (0)
Please sign in to comment.