-
Notifications
You must be signed in to change notification settings - Fork 35
/
setup.sh
executable file
·76 lines (60 loc) · 2.66 KB
/
setup.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
#! /bin/bash
# This script will set up a full tyk environment on your machine
# and also create a demo user for you with one command
# USAGE
# -----
#
# $> ./setup.sh {IP ADDRESS OF DOCKER VM}
# OSX users will need to specify a virtual IP, linux users can use 127.0.0.1
# Tyk dashboard settings
TYK_DASHBOARD_USERNAME="test$RANDOM@test.com"
TYK_DASHBOARD_PASSWORD="test123"
# Tyk portal settings
TYK_PORTAL_DOMAIN="www.tyk-portal-test.com"
DOCKER_IP=127.0.0.1
if [ -n "$DOCKER_HOST" ]
then
echo "Detected a Docker VM..."
REMTCP=${DOCKER_HOST#tcp://}
DOCKER_IP=${REMTCP%:*}
fi
if [ -n "$1" ]
then
DOCKER_IP=$1
echo "Docker host address explicitly set."
echo "Using $DOCKER_IP as Tyk host address."
fi
if [ -n "$2" ]
then
TYK_PORTAL_DOMAIN=$2
echo "Docker portal domain address explicitly set."
echo "Using $TYK_PORTAL_DOMAIN as Tyk host address."
fi
if [ -z "$1" ]
then
echo "Using $DOCKER_IP as Tyk host address."
echo "If this is wrong, please specify the instance IP address (e.g. ./setup.sh 192.168.1.1)"
fi
echo "Creating Organisation"
ORG_DATA=$(curl --silent --header "admin-auth: 12345" --header "Content-Type:application/json" --data '{"owner_name": "TestOrg5 Ltd.","owner_slug": "testorg", "cname_enabled":true}' http://$DOCKER_IP:3000/admin/organisations 2>&1)
ORG_ID=$(echo $ORG_DATA | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["Meta"]')
echo "ORG ID: $ORG_ID"
echo "Adding new user"
USER_DATA=$(curl --silent --header "admin-auth: 12345" --header "Content-Type:application/json" --data '{"first_name": "John","last_name": "Smith","email_address": "'$TYK_DASHBOARD_USERNAME'","active": true,"org_id": "'$ORG_ID'"}' http://$DOCKER_IP:3000/admin/users 2>&1)
USER_AUTH=$(echo $USER_DATA | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["Message"]')
USER_LIST=$(curl --silent --header "authorization: $USER_AUTH" http://$DOCKER_IP:3000/api/users 2>&1)
USER_ID=$(echo $USER_LIST | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["users"][0]["id"]')
echo "USER AUTH: $USER_AUTH"
echo "USER ID: $USER_ID"
echo "Setting password"
OK=$(curl --silent --header "authorization: $USER_AUTH" --header "Content-Type:application/json" http://$DOCKER_IP:3000/api/users/$USER_ID/actions/reset --data '{"new_password":"'$TYK_DASHBOARD_PASSWORD'"}')
echo "Setting up the portal domain"
OK=$(curl --silent -d "domain="$TYK_PORTAL_DOMAIN"" -H "admin-auth:12345" http://$DOCKER_IP:3000/admin/organisations/$ORG_ID/generate-portals)
echo ""
echo "DONE"
echo "===="
echo "Login at http://$DOCKER_IP:3000/"
echo "Username: $TYK_DASHBOARD_USERNAME"
echo "Password: $TYK_DASHBOARD_PASSWORD"
echo "Portal: http://$TYK_PORTAL_DOMAIN"
echo ""