forked from Yelp/detect-secrets
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmailchimp.py
38 lines (31 loc) · 1001 Bytes
/
mailchimp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
This plugin searches for Mailchimp keys
"""
import re
from base64 import b64encode
import requests
from .base import RegexBasedDetector
from detect_secrets.core.constants import VerifiedResult
class MailchimpDetector(RegexBasedDetector):
"""Scans for Mailchimp keys."""
secret_type = 'Mailchimp Access Key'
denylist = (
re.compile(r'[0-9a-z]{32}-us[0-9]{1,2}'),
)
def verify(self, token, *args, **kwargs): # pragma: no cover
_, datacenter_number = token.split('-us')
response = requests.get(
'https://us{}.api.mailchimp.com/3.0/'.format(
datacenter_number,
),
headers={
'Authorization': b'Basic ' + b64encode(
'any_user:{}'.format(token).encode('utf-8'),
),
},
)
return (
VerifiedResult.VERIFIED_TRUE
if response.status_code == 200
else VerifiedResult.VERIFIED_FALSE
)