Skip to content

Commit

Permalink
↪️Merge pull request #463 from ninoseki/add-plugin-for-sendgrid
Browse files Browse the repository at this point in the history
Add a plugin for SendGrid
  • Loading branch information
KevinHock authored Aug 1, 2021
2 parents a1ab77d + 232d21d commit 3f806f1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions detect_secrets/plugins/sendgrid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
This plugin searches for SendGrid API keys
"""
import re

from detect_secrets.plugins.base import RegexBasedDetector


class SendGridDetector(RegexBasedDetector):
"""Scans for SendGrid API keys."""
secret_type = 'SendGrid API key'

denylist = [
# SendGrid API key
# ref. https://d2w67tjf43xwdp.cloudfront.net/Classroom/Basics/API/what_is_my_api_key.html
re.compile(r'SG\.[a-zA-Z0-9_-]{22}\.[a-zA-Z0-9_-]{43}'),
]
20 changes: 20 additions & 0 deletions tests/plugins/sendgrid_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from detect_secrets.plugins.sendgrid import SendGridDetector


class TestSendGridDetector:

@pytest.mark.parametrize(
'payload, should_flag',
[
('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', True),
('SG.ngeVfQFYQlKU0ufo8x5d1A..TwL2iGABf9DHoTf-09kqeF8tAmbihYzrnopKc-1s5cr', False),
('AG.ngeVfQFYQlKU0ufo8x5d1A.TwL2iGABf9DHoTf-09kqeF8tAmbihYzrnopKc-1s5cr', False),
('foo', False),
],
)
def test_analyze(self, payload, should_flag):
logic = SendGridDetector()
output = logic.analyze_line(filename='mock_filename', line=payload)
assert len(output) == int(should_flag)

0 comments on commit 3f806f1

Please sign in to comment.