File: http-api

package info (click to toggle)
siridb-server 2.0.53-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,612 kB
  • sloc: ansic: 47,501; python: 6,263; sh: 254; makefile: 149
file content (205 lines) | stat: -rw-r--r-- 6,480 bytes parent folder | download | duplicates (2)
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/sh
set -e

RES=0

echo '* fixing /etc/siridb/siridb.conf'
sed --in-place 's/http_api_port = 0/http_api_port = 9020/' /etc/siridb/siridb.conf

echo '* restarting siridb-server'
service siridb-server restart

echo '* touch res.txt'
touch res.txt

echo '* sleep to let the server start up properly'
sleep 5

echo '* run queries'
echo '  get-version'
curl --silent --show-error --location --output res.txt \
     --retry 10 \
     --request GET 'http://localhost:9020/get-version' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ==' || RES=1
cat res.txt
echo

echo '  new-database'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/new-database' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ==' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
	"dbname": "sampledb",
	"time_precision": "s",
	"buffer_size": 8192,
	"duration_num": "1w",
	"duration_log": "3d"
}' || RES=1
cat res.txt
echo
expect='"OK"'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  new-account'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/new-account' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ==' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
        "account": "bob",
	"password": "passwd4bob"
}' || RES=1
cat res.txt
echo
expect='"OK"'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  change-password'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/change-password' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ==' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
        "account": "bob",
	"password": "pass"
}' || RES=1
cat res.txt
echo
expect='"OK"'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  drop-account'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/drop-account' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ==' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
       "account": "bob"
}' || RES=1
cat res.txt
echo
expect='"OK"'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  drop-database'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/drop-database' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ==' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
	"database": "sampledb",
	"ignore_offline": false
}' || RES=1
cat res.txt
echo
expect='"OK"'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  drop-database again'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/drop-database' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ==' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
	"database": "sampledb",
	"ignore_offline": false
}' || RES=1
cat res.txt
echo
expect='{"error_msg":"cannot find database '"'"'sampledb'"'"'"}'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  get-accounts'
curl --silent --show-error --location --output res.txt \
     --request GET 'http://localhost:9020/get-accounts' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ=='
cat res.txt
echo
expect='["sa"]'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  new-database for queries'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/new-database' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ==' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
	"dbname": "sampledb",
	"time_precision": "s",
	"buffer_size": 8192,
	"duration_num": "1w",
	"duration_log": "3d"
}' || RES=1
cat res.txt
echo
expect='"OK"'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  get-databases'
curl --silent --show-error --location --output res.txt \
     --request GET 'http://localhost:9020/get-databases' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic c2E6c2lyaQ=='
cat res.txt
echo
expect='["sampledb"]'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  query data (nothing there)'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/query/sampledb' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic aXJpczpzaXJp' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
	"q": "select count() from '\''aggr'\''",
	"t": "ms"
}' || RES=1
cat res.txt
echo
expect='{}'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  insert data'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/insert/sampledb' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic aXJpczpzaXJp' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
    "aggr": [
        [1578933215, 42],
        [1578933223, 123]
    ]
}' || RES=1
cat res.txt
echo
expect='{"success_msg":"Successfully inserted 2 point(s)."}'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

echo '  query data'
curl --silent --show-error --location --output res.txt \
     --request POST 'http://localhost:9020/query/sampledb' \
     --header 'Content-Type: application/json' \
     --header 'Authorization: Basic aXJpczpzaXJp' \
     --header 'Content-Type: text/plain' \
     --data-raw '{
	"q": "select count() from '\''aggr'\''",
	"t": "ms"
}' || RES=1
cat res.txt
echo
expect='{"aggr":[[1578933223000,2]]}'
if [ "$(cat res.txt)" != "$expect" ] ; then RES=1 ; echo "FAILED: expected $expect" ; fi

exit $RES