Skip to content

Commit

Permalink
🎉 Add verification for Mailchimp API keys
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinHock committed Sep 21, 2019
1 parent 6c6e028 commit 977c4fb
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions detect_secrets/plugins/mailchimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,37 @@
from __future__ import absolute_import

import re
from base64 import b64encode

import requests

from .base import RegexBasedDetector
from detect_secrets.core.constants import VerifiedResult


class MailchimpDetector(RegexBasedDetector):

secret_type = 'Mailchimp Access Key'

denylist = (
# Mailchimp key
re.compile(r'[0-9a-z]{32}(-us[0-9]{1,2})'),
re.compile(r'[0-9a-z]{32}-us[0-9]{1,2}'),
)

def verify(self, token, **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
)

0 comments on commit 977c4fb

Please sign in to comment.