Skip to content

Instantly share code, notes, and snippets.

@runapp
Last active July 5, 2019 20:26
Show Gist options
  • Save runapp/d8cf6827389bf1a71b1eb6bf7c3cc2d2 to your computer and use it in GitHub Desktop.
Save runapp/d8cf6827389bf1a71b1eb6bf7c3cc2d2 to your computer and use it in GitHub Desktop.
import datetime
import random
import urllib.parse
import hmac
import hashlib
import base64
import requests
import pytz
""" To setup RAM sub-accounts, use the following policy:
{
"Version": "1",
"Statement": [
{
"Action": [
"alidns:DescribeDomainRecords",
"alidns:AddDomainRecord",
"alidns:DeleteDomainRecord"
],
"Resource": "acs:alidns:*:*:domain/YOUR_DOMAIN_HERE",
"Effect": "Allow"
}
]
}
"""
sec = 'YOUR_SEC_KEY_HERE'
a = {'AccessKeyId': 'YOUR_ID_HERE',
'SignatureMethod': 'HMAC-SHA1',
'SignatureVersion': '1.0',
'Version': '2015-01-09'}
a['Action'] = 'DescribeDomainRecords'
a['DomainName'] = 'YOUR_DOMAIN_HERE'
a['SignatureNonce'] = str(random.randint(0, 100000))
a['Timestamp'] = datetime.datetime.now(tz=pytz.utc).strftime('%Y-%m-%dT%H:%M:%S')
t = []
for k in sorted(a.keys()):
t.append('='.join(map(urllib.parse.quote, [k, a[k]])))
t = 'GET&%2F&'+urllib.parse.quote('&'.join(t))
a['Signature'] = base64.b64encode(hmac.new((sec+'&').encode(), t.encode(), hashlib.sha1).digest())
r = requests.get("https://alidns.aliyuncs.com/", params=a)
print(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment