-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·114 lines (90 loc) · 2.62 KB
/
entrypoint.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
set -e
if [ -z "$CDN_CLOUD" ]; then
echo "CDN_CLOUD is not set. Default to myhuaweicloud.com."
export CDN_CLOUD=myhuaweicloud.com
fi
if [ -z "$CDN_REGION" ]; then
echo "CDN_REGION is not set. Default to cn-north-1."
export CDN_REGION=cn-north-1
fi
if [ -z "$CDN_ENDPOINT" ]; then
echo "CDN_ENDPOINT is not set. Default to https://cdn.myhuaweicloud.com/v1.0/."
export CDN_ENDPOINT=https://cdn.myhuaweicloud.com/v1.0/
fi
if [ -z "$CDN_PROJECTID" ]; then
echo "CDN_PROJECTID is not set. Default to null."
export CDN_PROJECTID=""
fi
if [ -z "$CDN_AK" ]; then
echo "CDN_AK is not set. Quitting."
exit 1
fi
if [ -z "$CDN_SK" ]; then
echo "CDN_SK is not set. Quitting."
exit 1
fi
if [ -z "$CDN_URLS" ]; then
echo "CDN_URLS is not set. Quitting."
exit 1
fi
if [ -z "$OBS_AK" ]; then
echo "OBS_AK is not set. Quitting."
exit 1
fi
if [ -z "$OBS_SK" ]; then
echo "OBS_AK is not set. Quitting."
exit 1
fi
if [ -z "$OBS_SERVER" ]; then
echo "OBS_AK is not set. Quitting."
exit 1
fi
if [ -z "$OBS_BUCKET" ]; then
echo "OBS_AK is not set. Quitting."
exit 1
fi
cat > main.py <<EOF
# -*- coding:utf-8 -*-
import os
from obs import *
from openstack import connection
obs_ak = os.getenv('OBS_AK')
obs_sk = os.getenv('OBS_SK')
obs_server = os.getenv('OBS_SERVER')
obs_bucket = os.getenv('OBS_BUCKET')
cdn_projectId = os.getenv('CDN_PROJECTID')
cdn_cloud = os.getenv('CDN_CLOUD')
cdn_region = os.getenv('CDN_REGION')
cdn_ak = os.getenv('CDN_AK')
cdn_sk = os.getenv('CDN_SK')
cdn_urls = os.getenv('CDN_URLS')
cdn_endpoint = os.getenv('CDN_ENDPOINT')
def preheat_create(_preheat_task):
os.environ.setdefault('OS_CDN_ENDPOINT_OVERRIDE', cdn_endpoint)
conn = connection.Connection(project_id=cdn_projectId, cloud=cdn_cloud, region=cdn_region, ak=cdn_ak, sk=cdn_sk)
task = conn.cdn.create_preheat_task(**_preheat_task)
print(task)
def obs_list(obs_ak, obs_sk, obs_server, obs_bucket):
obsClient = ObsClient(access_key_id=obs_ak, secret_access_key=obs_sk, server=obs_server)
try:
resp = obsClient.listObjects(obs_bucket)
if resp.status <= 1000:
listkey = []
for content in resp.body.contents:
key = cdn_urls + content.key
listkey.append(key)
return listkey
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
except:
import traceback
print(traceback.format_exc())
if __name__ == "__main__":
preheat_task = {
"urls": obs_list(obs_ak, obs_sk, obs_server, obs_bucket)
}
preheat_create(preheat_task)
EOF
python main.py