-
Notifications
You must be signed in to change notification settings - Fork 2
/
curl_villasAPI.sh
executable file
·123 lines (110 loc) · 3.69 KB
/
curl_villasAPI.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
#!/bin/bash
##########################################################################################
# This file is part of VILLASweb-backend-go
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
##########################################################################################
# Handy bash script using curl for testing the checkpoint of the
# VILLASweb frontend. See at the end of the file for usage cases
port='4000'
version='v2'
apiBase='localhost:'"$port"'/api/'"$version"
login () {
printf "> POST "$apiBase"/authenticate\n"
curl "$apiBase"/authenticate -s \
-H "Contet-Type: application/json" \
-X POST \
--data "$1" | jq -r '.token' > auth.jwt \
&& printf '\n'
}
create_user () {
printf "> POST "$apiBase"/users to create newUser\n"
curl "$apiBase"/users -s \
-H "Contet-Type: application/json" \
-H "Authorization: Bearer $(< auth.jwt)" \
-X POST \
--data "$1" | jq -r '.' && printf '\n'
}
read_users () {
printf "> GET "$apiBase"/users\n"
curl "$apiBase"/users -s \
-H "Contet-Type: application/json" \
-H "Authorization: Bearer $(< auth.jwt)" \
-X GET | jq '.' && printf '\n'
}
read_infrastructure_components () {
printf "> GET "$apiBase"/ic\n"
curl "$apiBase"/ic -s \
-H "Contet-Type: application/json" \
-H "Authorization: Bearer $(< auth.jwt)" \
-X GET | jq '.' && printf '\n'
}
read_user () {
printf "> GET "$apiBase"/users/$1\n"
curl "$apiBase"/users/$1 -s \
-H "Contet-Type: application/json" \
-H "Authorization: Bearer $(< auth.jwt)" \
-X GET | jq '.' && printf '\n'
}
update_user () {
printf "> PUT "$apiBase"/users to update newUser\n"
curl "$apiBase"/users/$1 -s \
-H "Contet-Type: application/json" \
-H "Authorization: Bearer $(< auth.jwt)" \
-X PUT \
--data "$2" | jq -r '.' && printf '\n'
}
delete_user () {
printf "> DELETE "$apiBase"/users/$1\n"
curl "$apiBase"/users/$1 -s \
-H "Contet-Type: application/json" \
-H "Authorization: Bearer $(< auth.jwt)" \
-X DELETE | jq '.' && printf '\n'
}
admin='{ "Username" : "User_0",
"Password" : "xyz789",
"Role" : "Admin" }'
userA='{ "Username" : "User_A",
"Password" : "abc123",
"Mail" : "m@i.l" }'
newUserW='{ "user": { "Username" : "User_W",
"Password" : "www747_tst",
"Role" : "User",
"Mail" : "m@i.l" } }'
updUserW='{ "user": { "Mail" : "lalala",
"Role" : "Admin" } }'
#updUserW='{ "user": { "Username" : "User_Wupdated",
#"Password" : "pie314_test",
#"Role" : "Admin",
#"Mail" : "NEW_m@i.l" } }'
userC='{ "user": { "Username" : "User_C",
"Password" : "abc123",
"Mail" : "C_m@i.l",
"Role" : "User"} }'
login "$admin"
#create_user "$userC"
#read_users
#read_user 1
#read_infrastructure_components
create_user "$newUserW"
#read_users
read_user 4
#login "$newUserW"
update_user 4 "$updUserW"
#login "$admin"
read_user 4
#login "$admin"
#read_user 4
#login "$updUserW"
#delete_user 2