-
Notifications
You must be signed in to change notification settings - Fork 0
/
up.sh
executable file
·205 lines (179 loc) · 5.58 KB
/
up.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
if grep -q "TYK_DB_LICENSEKEY" ./confs/tyk_analytics.env; then
echo "TYK_DB_LICENSEKEY exists in the file! Skipping.."
else
read -n2048 -s -p 'Please enter your Tyk Pro License key: ' license_key
echo TYK_DB_LICENSEKEY=$license_key >> confs/tyk_analytics.env
echo PORTAL_LICENSEKEY=$license_key >> confs/tyk_portal.env
fi
echo "Bringing Tyk Trial deployment UP..."
docker-compose up -d
if [ $? -ne 0 ]; then
echo "docker-compose up failed"
exit 1
fi
status=""
desired_status="200"
attempt_count=0
attempt_max=10
while [ "$status" != "$desired_status" ] && [ $attempt_count -le $attempt_max ]
do
status=$(curl -s -o /dev/null -I -w "%{http_code}" http://localhost:3000/hello)
if [ $attempt_count -eq $attempt_max ]; then
echo " Attempt $attempt_count of $attempt_max unsuccessful, received '$status'"
fi
attempt_count=$((attempt_count + 1))
sleep 1
done
echo "Tyk configured. Bootstrapping environment..."
# Create default Org
createOrgResponse=$(curl -s --location 'http://localhost:3000/admin/organisations/' \
--header 'admin-auth: 12345' \
--header 'Content-Type: application/json' \
--data '{
"owner_name": "Tyk Demo",
"cname_enabled": true,
"event_options": {
"hashed_key_event": {
"redis": true
},
"key_event": {
"redis": true
}
},
"hybrid_enabled": true
}')
orgId=$(echo "$createOrgResponse" | awk -F'"' '/"Meta":/{print $(NF-1)}')
echo "Created org"
# Create default user
createUserResponse=$(curl -s --location 'http://localhost:3000/admin/users/' \
--header 'Content-Type: application/json' \
--header 'admin-auth: 12345' \
--data-raw '{
"org_id": "'$orgId'",
"first_name": "Dev",
"last_name": "Trial",
"email_address": "dev@tyk.io",
"active": true,
"user_permissions": { "IsAdmin": "admin" }
}')
user_id=$(echo "$createUserResponse" | awk -F'"id":"' '{split($2,a,"\""); print a[1]}')
user_api_key=$(echo "$createUserResponse" | awk -F'"access_key":"' '{split($2,a,"\""); print a[1]}')
echo "Created default user"
# Reset User Password
curl -s -o /dev/null --location 'http://localhost:3000/api/users/'$user_id'/actions/reset' \
--header 'Content-Type: application/json' \
--header 'authorization: '$user_api_key \
--data '{
"new_password":"topsecret",
"user_permissions": { "IsAdmin": "admin" }
}'
echo "Created user password"
# Creating API
createApiResponse=$(curl -s --location 'http://localhost:3000/api/apis' \
--header 'authorization: '$user_api_key'' \
--header 'Content-Type: application/json' \
--data '{
"api_definition": {
"name": "Httpbin",
"auth": {
"auth_header_name": "authorization"
},
"definition": {
"location": "header",
"key": ""
},
"proxy": {
"target_url": "http://echo.tyk-demo.com:8080/trial",
"listen_path": "/httpbin"
},
"version_data": {
"use_extended_paths": true,
"not_versioned": true,
"versions": {
"Default": {
"expires": "",
"name": "Default",
"paths": {
"ignored": [],
"white_list": [],
"black_list": []
},
"use_extended_paths": false
}
}
},
"enable_ip_whitelisting": true,
"active": true,
"enable_batch_request_support": true
}
}')
apiId=$(echo "$createApiResponse" | awk -F'"' '/"ID":/{print $(NF-1)}')
echo "Created Httpbin sample API"
# Create Policy
createPolicyResponse=$(curl -s --location 'localhost:3000/api/portal/policies/' \
--header 'Authorization: '$user_api_key'' \
--header 'Content-Type: application/json' \
--data '{
"access_rights": {
"'$apiId'": {
"allowed_urls": [],
"api_id": "'$apiId'",
"api_name": "Httpbin",
"limit": null,
"versions": [
"Default"
]
}
},
"active": true,
"name": "Default Security Policyy",
"org_id": "'$orgId'",
"per": 10,
"rate": 2,
"quota_max": -1,
"quota_remaining": -1,
"quota_renewal_rate": -1,
"quota_renews": -1,
"throttle_interval": -1,
"throttle_retry_limit": -1,
"tags": [],
"allowance": 0,
"auth_type": "other",
"expires": 0,
"key_expires_in": 0,
"last_check": 0
}')
policyId=$(echo "$createPolicyResponse" | grep -o '"Message":"[^"]*"' | cut -d":" -f2 | tr -d '"')
echo "Created HttpBin Security Policy"
sleep 4
# Create Httpbin API key
keyName=my_custom_key
curl -s -o /dev/null --location 'localhost:3000/api/keys/'$keyName \
--header 'authorization: '$user_api_key'' \
--header 'Content-Type: application/json' \
--data-raw '{
"apply_policies": [
"'$policyId'"
],
"org_id": "'$orgId'",
"allowance": -1,
"per": -1,
"quota_max": -1,
"rate": -1
}'
echo "Created Httpbin API Key"
echo "Generating keys"
make gen-keys
echo "Created keys"
# Send a setup ping
curl -s -o /dev/null http://localhost:8080/httpbin/anything/hello -H "Authorization: my_custom_key"
tput setaf 2;
echo '
---------------------------
Please sign in at http://localhost:3000
user: dev@tyk.io
pw: topsecret
Your Tyk Gateway is found at http://localhost:8080
Press Enter to exit'
read