-
Notifications
You must be signed in to change notification settings - Fork 0
/
waltid-enterprise
executable file
·174 lines (143 loc) · 4.25 KB
/
waltid-enterprise
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
#!/bin/bash
set -e
export WORKDIR=$(cd $(dirname $0) && pwd)
auth_token=""
init() {
info "Checking dependencies..."
# jq
}
log() {
script_name=${0##*/}
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "== $script_name $timestamp $1"
}
info() {
log "[INFO] $1"
}
error() {
log "[ERROR] $1"
}
help() {
cli_name=${0##*/}
echo "Walt.id Enterprise Stack Quickstarter v$(cat $WORKDIR/VERSION)
Usage: $cli_name [command]
Commands:
run Run the Enterprise Stack
superadmin-create-account Create the super admin account
superadmin-login Log in the super admin
init-db Initialize the database
create-organization Create (an | the root) Organization
* Help
"
exit 1
}
docker_hub_login(){
password=$(cat .docker-token | grep -v "#" | grep -v -e '^[[:space:]]*$')
info "Autheticating to Docker Hub. Please use the password provided..."
docker login -u waltid -p $password
echo
}
pull_docker_image() {
info "Pulling Enterprise Stack v0.1.0"
docker pull waltid/waltid-enterprise-api:0.1.0
echo
}
start_container() {
info "Starting up Enterprise Stack v0.1.0"
docker compose up
}
run() {
docker_hub_login
pull_docker_image
start_container
}
superadmin_create_account() {
superadmin_token=$(cat config/superadmin-registration.conf | sed -n '2 p' | cut -d \" -f 2)
info "Registering token \"${superadmin_token}\" provided in the superadmin-registration.conf file"
response=$(curl -X 'POST' \
'http://localhost:3000/v1/superadmin/create-by-token' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d "${superadmin_token}" 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "Super admin account could not be created."
error "$response"
else
info "Super admin account successfully created."
fi
}
superadmin_login() {
superadmin_email=$(cat config/superadmin-registration.conf | grep identifier | cut -d \" -f 2)
superadmin_password=$(cat config/superadmin-registration.conf | grep password | cut -d \" -f 2)
info "Logging in super admin with credentials provided in the superadmin-registration.conf file"
response=$(curl -X 'POST' \
'http://localhost:3000/auth/account/emailpass' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "{
\"email\": \"${superadmin_email}\",
\"password\": \"${superadmin_password}\"
}" 2> /dev/null)
if [[ $response == *"exception"* ]]; then
error "Super admin could not be logged in."
error "$response"
else
info "Super admin logged in successfully."
info "$response"
auth_token=$(echo $response | jq .token | tr -d '"')
fi
}
init_db() {
superadmin_login
info "Initializing the database based on the config/database.conf file"
response=$(curl -X 'POST' \
'http://localhost:3000/v1/admin/initial-setup' \
-H 'accept: */*' \
-H "Authorization: Bearer $auth_token" \
-d '' 2> /dev/null)
if [[ $response == *"Unauthorized"* ]]; then
error "Database could not be initialized. Access denied."
error "$response"
else
info "Database successfully initialized."
fi
}
create_organization() {
response=$(curl -X 'POST' \
'http://localhost:3000/v1/organization/create' \
-H 'accept: */*' \
-H "Authorization: Bearer $auth_token" \
-H 'Content-Type: application/json' \
-d '{
"_id": "waltid",
"profile": {
"name": "walt.id GmbH"
},
"billing": {
"billingCountry": "AT",
"billingAddress": "Liechtensteinstraße 111/115, 1090 Vienna",
"vatNr": "ATU75569617"
}
}')
echo $response
}
case "$1" in
run|step1)
run
;;
superadmin-create-account|step2)
superadmin_create_account
;;
superadmin-login|step3)
superadmin_login
;;
init-db|step4)
init_db
;;
create-organization|step5)
create_organization
;;
*)
help
;;
esac