-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathrefresh_cdn_cache.py
64 lines (42 loc) · 1.43 KB
/
refresh_cdn_cache.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# /usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Author: samzong.lu
E-mail: [email protected]
"""
import logging
import sys
import requests
import hashlib
import collections
def sort_dict(data: dict = None):
return collections.OrderedDict(sorted(data.items()))
def dict_to_str(data: dict = None):
data = sort_dict(data)
return ''.join(['{}{}'.format(k, v) for k, v in data.items()])
def signature(payload, privatekey):
sign_str = dict_to_str(payload) + privatekey
return hashlib.sha1(sign_str.encode('utf-8')).hexdigest()
def refresh_cdn_cache(privatekey, publickey, domain):
url = "https://api.ucloud.cn/?Action=RefreshNewUcdnDomainCache"
headers = {
'Content-Type': 'application/json'
}
payload = {
"PublicKey": publickey,
"Action": "RefreshNewUcdnDomainCache",
"ProjectId": "org-ismsmp",
"Type": "dir",
"UrlList.0": domain
}
payload['Signature'] = signature(payload, privatekey)
resp = requests.post(url, headers=headers, json=payload)
logging.info("refresh cdn cache respone code: ".format(resp.status_code))
if __name__ == '__main__':
argv = sys.argv
publickey = argv[1].split('=')[1]
privatekey = argv[2].split('=')[1]
# domain = argv[3].split('=')[1]
domains = ["https://docs.daocloud.io/","http://docs.daocloud.io/"]
for domain in domains:
refresh_cdn_cache(privatekey, publickey, domain)