summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock253
-rw-r--r--Cargo.toml25
-rw-r--r--docker-compose.yml8
-rw-r--r--src/config.rs30
-rw-r--r--src/error.rs10
-rw-r--r--src/main.rs84
-rw-r--r--src/requests.rs (renamed from src/requests/mod.rs)0
-rw-r--r--src/requests/device.rs62
-rw-r--r--src/requests/start.rs103
9 files changed, 358 insertions, 217 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5620d60..ad227e6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -18,21 +18,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
18checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 18checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
19 19
20[[package]] 20[[package]]
21name = "ahash"
22version = "0.7.7"
23source = "registry+https://github.com/rust-lang/crates.io-index"
24checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd"
25dependencies = [
26 "getrandom",
27 "once_cell",
28 "version_check",
29]
30
31[[package]]
32name = "anstream" 21name = "anstream"
33version = "0.6.4" 22version = "0.6.12"
34source = "registry+https://github.com/rust-lang/crates.io-index" 23source = "registry+https://github.com/rust-lang/crates.io-index"
35checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" 24checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540"
36dependencies = [ 25dependencies = [
37 "anstyle", 26 "anstyle",
38 "anstyle-parse", 27 "anstyle-parse",
@@ -110,12 +99,6 @@ dependencies = [
110 99
111[[package]] 100[[package]]
112name = "base64" 101name = "base64"
113version = "0.13.1"
114source = "registry+https://github.com/rust-lang/crates.io-index"
115checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
116
117[[package]]
118name = "base64"
119version = "0.21.5" 102version = "0.21.5"
120source = "registry+https://github.com/rust-lang/crates.io-index" 103source = "registry+https://github.com/rust-lang/crates.io-index"
121checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" 104checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9"
@@ -131,6 +114,9 @@ name = "bitflags"
131version = "2.4.1" 114version = "2.4.1"
132source = "registry+https://github.com/rust-lang/crates.io-index" 115source = "registry+https://github.com/rust-lang/crates.io-index"
133checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" 116checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
117dependencies = [
118 "serde",
119]
134 120
135[[package]] 121[[package]]
136name = "block-buffer" 122name = "block-buffer"
@@ -176,9 +162,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
176 162
177[[package]] 163[[package]]
178name = "clap" 164name = "clap"
179version = "4.4.8" 165version = "4.5.1"
180source = "registry+https://github.com/rust-lang/crates.io-index" 166source = "registry+https://github.com/rust-lang/crates.io-index"
181checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" 167checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da"
182dependencies = [ 168dependencies = [
183 "clap_builder", 169 "clap_builder",
184 "clap_derive", 170 "clap_derive",
@@ -186,9 +172,9 @@ dependencies = [
186 172
187[[package]] 173[[package]]
188name = "clap_builder" 174name = "clap_builder"
189version = "4.4.8" 175version = "4.5.1"
190source = "registry+https://github.com/rust-lang/crates.io-index" 176source = "registry+https://github.com/rust-lang/crates.io-index"
191checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" 177checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb"
192dependencies = [ 178dependencies = [
193 "anstream", 179 "anstream",
194 "anstyle", 180 "anstyle",
@@ -198,18 +184,18 @@ dependencies = [
198 184
199[[package]] 185[[package]]
200name = "clap_complete" 186name = "clap_complete"
201version = "4.4.4" 187version = "4.5.1"
202source = "registry+https://github.com/rust-lang/crates.io-index" 188source = "registry+https://github.com/rust-lang/crates.io-index"
203checksum = "bffe91f06a11b4b9420f62103854e90867812cd5d01557f853c5ee8e791b12ae" 189checksum = "885e4d7d5af40bfb99ae6f9433e292feac98d452dcb3ec3d25dfe7552b77da8c"
204dependencies = [ 190dependencies = [
205 "clap", 191 "clap",
206] 192]
207 193
208[[package]] 194[[package]]
209name = "clap_derive" 195name = "clap_derive"
210version = "4.4.7" 196version = "4.5.0"
211source = "registry+https://github.com/rust-lang/crates.io-index" 197source = "registry+https://github.com/rust-lang/crates.io-index"
212checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" 198checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47"
213dependencies = [ 199dependencies = [
214 "heck", 200 "heck",
215 "proc-macro2", 201 "proc-macro2",
@@ -219,9 +205,9 @@ dependencies = [
219 205
220[[package]] 206[[package]]
221name = "clap_lex" 207name = "clap_lex"
222version = "0.6.0" 208version = "0.7.0"
223source = "registry+https://github.com/rust-lang/crates.io-index" 209source = "registry+https://github.com/rust-lang/crates.io-index"
224checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" 210checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
225 211
226[[package]] 212[[package]]
227name = "colorchoice" 213name = "colorchoice"
@@ -231,11 +217,12 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
231 217
232[[package]] 218[[package]]
233name = "config" 219name = "config"
234version = "0.13.3" 220version = "0.14.0"
235source = "registry+https://github.com/rust-lang/crates.io-index" 221source = "registry+https://github.com/rust-lang/crates.io-index"
236checksum = "d379af7f68bfc21714c6c7dea883544201741d2ce8274bb12fa54f89507f52a7" 222checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be"
237dependencies = [ 223dependencies = [
238 "async-trait", 224 "async-trait",
225 "convert_case",
239 "json5", 226 "json5",
240 "lazy_static", 227 "lazy_static",
241 "nom", 228 "nom",
@@ -262,6 +249,35 @@ dependencies = [
262] 249]
263 250
264[[package]] 251[[package]]
252name = "const-random"
253version = "0.1.17"
254source = "registry+https://github.com/rust-lang/crates.io-index"
255checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a"
256dependencies = [
257 "const-random-macro",
258]
259
260[[package]]
261name = "const-random-macro"
262version = "0.1.16"
263source = "registry+https://github.com/rust-lang/crates.io-index"
264checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e"
265dependencies = [
266 "getrandom",
267 "once_cell",
268 "tiny-keccak",
269]
270
271[[package]]
272name = "convert_case"
273version = "0.6.0"
274source = "registry+https://github.com/rust-lang/crates.io-index"
275checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
276dependencies = [
277 "unicode-segmentation",
278]
279
280[[package]]
265name = "core-foundation" 281name = "core-foundation"
266version = "0.9.3" 282version = "0.9.3"
267source = "registry+https://github.com/rust-lang/crates.io-index" 283source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -287,6 +303,12 @@ dependencies = [
287] 303]
288 304
289[[package]] 305[[package]]
306name = "crunchy"
307version = "0.2.2"
308source = "registry+https://github.com/rust-lang/crates.io-index"
309checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
310
311[[package]]
290name = "crypto-common" 312name = "crypto-common"
291version = "0.1.6" 313version = "0.1.6"
292source = "registry+https://github.com/rust-lang/crates.io-index" 314source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -335,9 +357,12 @@ dependencies = [
335 357
336[[package]] 358[[package]]
337name = "dlv-list" 359name = "dlv-list"
338version = "0.3.0" 360version = "0.5.2"
339source = "registry+https://github.com/rust-lang/crates.io-index" 361source = "registry+https://github.com/rust-lang/crates.io-index"
340checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" 362checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f"
363dependencies = [
364 "const-random",
365]
341 366
342[[package]] 367[[package]]
343name = "encode_unicode" 368name = "encode_unicode"
@@ -355,6 +380,12 @@ dependencies = [
355] 380]
356 381
357[[package]] 382[[package]]
383name = "equivalent"
384version = "1.0.1"
385source = "registry+https://github.com/rust-lang/crates.io-index"
386checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
387
388[[package]]
358name = "errno" 389name = "errno"
359version = "0.3.6" 390version = "0.3.6"
360source = "registry+https://github.com/rust-lang/crates.io-index" 391source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -499,8 +530,8 @@ dependencies = [
499 "futures-core", 530 "futures-core",
500 "futures-sink", 531 "futures-sink",
501 "futures-util", 532 "futures-util",
502 "http", 533 "http 0.2.10",
503 "indexmap", 534 "indexmap 1.9.3",
504 "slab", 535 "slab",
505 "tokio", 536 "tokio",
506 "tokio-util", 537 "tokio-util",
@@ -512,9 +543,18 @@ name = "hashbrown"
512version = "0.12.3" 543version = "0.12.3"
513source = "registry+https://github.com/rust-lang/crates.io-index" 544source = "registry+https://github.com/rust-lang/crates.io-index"
514checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 545checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
515dependencies = [ 546
516 "ahash", 547[[package]]
517] 548name = "hashbrown"
549version = "0.13.2"
550source = "registry+https://github.com/rust-lang/crates.io-index"
551checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
552
553[[package]]
554name = "hashbrown"
555version = "0.14.3"
556source = "registry+https://github.com/rust-lang/crates.io-index"
557checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
518 558
519[[package]] 559[[package]]
520name = "heck" 560name = "heck"
@@ -540,13 +580,24 @@ dependencies = [
540] 580]
541 581
542[[package]] 582[[package]]
583name = "http"
584version = "1.0.0"
585source = "registry+https://github.com/rust-lang/crates.io-index"
586checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea"
587dependencies = [
588 "bytes",
589 "fnv",
590 "itoa",
591]
592
593[[package]]
543name = "http-body" 594name = "http-body"
544version = "0.4.5" 595version = "0.4.5"
545source = "registry+https://github.com/rust-lang/crates.io-index" 596source = "registry+https://github.com/rust-lang/crates.io-index"
546checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" 597checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
547dependencies = [ 598dependencies = [
548 "bytes", 599 "bytes",
549 "http", 600 "http 0.2.10",
550 "pin-project-lite", 601 "pin-project-lite",
551] 602]
552 603
@@ -573,7 +624,7 @@ dependencies = [
573 "futures-core", 624 "futures-core",
574 "futures-util", 625 "futures-util",
575 "h2", 626 "h2",
576 "http", 627 "http 0.2.10",
577 "http-body", 628 "http-body",
578 "httparse", 629 "httparse",
579 "httpdate", 630 "httpdate",
@@ -616,7 +667,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
616checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" 667checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
617dependencies = [ 668dependencies = [
618 "autocfg", 669 "autocfg",
619 "hashbrown", 670 "hashbrown 0.12.3",
671]
672
673[[package]]
674name = "indexmap"
675version = "2.2.3"
676source = "registry+https://github.com/rust-lang/crates.io-index"
677checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177"
678dependencies = [
679 "equivalent",
680 "hashbrown 0.14.3",
620] 681]
621 682
622[[package]] 683[[package]]
@@ -807,9 +868,9 @@ dependencies = [
807 868
808[[package]] 869[[package]]
809name = "once_cell" 870name = "once_cell"
810version = "1.18.0" 871version = "1.19.0"
811source = "registry+https://github.com/rust-lang/crates.io-index" 872source = "registry+https://github.com/rust-lang/crates.io-index"
812checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" 873checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
813 874
814[[package]] 875[[package]]
815name = "openssl" 876name = "openssl"
@@ -863,12 +924,12 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
863 924
864[[package]] 925[[package]]
865name = "ordered-multimap" 926name = "ordered-multimap"
866version = "0.4.3" 927version = "0.6.0"
867source = "registry+https://github.com/rust-lang/crates.io-index" 928source = "registry+https://github.com/rust-lang/crates.io-index"
868checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" 929checksum = "4ed8acf08e98e744e5384c8bc63ceb0364e68a6854187221c18df61c4797690e"
869dependencies = [ 930dependencies = [
870 "dlv-list", 931 "dlv-list",
871 "hashbrown", 932 "hashbrown 0.13.2",
872] 933]
873 934
874[[package]] 935[[package]]
@@ -1032,13 +1093,13 @@ version = "0.11.22"
1032source = "registry+https://github.com/rust-lang/crates.io-index" 1093source = "registry+https://github.com/rust-lang/crates.io-index"
1033checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" 1094checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b"
1034dependencies = [ 1095dependencies = [
1035 "base64 0.21.5", 1096 "base64",
1036 "bytes", 1097 "bytes",
1037 "encoding_rs", 1098 "encoding_rs",
1038 "futures-core", 1099 "futures-core",
1039 "futures-util", 1100 "futures-util",
1040 "h2", 1101 "h2",
1041 "http", 1102 "http 0.2.10",
1042 "http-body", 1103 "http-body",
1043 "hyper", 1104 "hyper",
1044 "hyper-tls", 1105 "hyper-tls",
@@ -1066,20 +1127,21 @@ dependencies = [
1066 1127
1067[[package]] 1128[[package]]
1068name = "ron" 1129name = "ron"
1069version = "0.7.1" 1130version = "0.8.1"
1070source = "registry+https://github.com/rust-lang/crates.io-index" 1131source = "registry+https://github.com/rust-lang/crates.io-index"
1071checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" 1132checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
1072dependencies = [ 1133dependencies = [
1073 "base64 0.13.1", 1134 "base64",
1074 "bitflags 1.3.2", 1135 "bitflags 2.4.1",
1075 "serde", 1136 "serde",
1137 "serde_derive",
1076] 1138]
1077 1139
1078[[package]] 1140[[package]]
1079name = "rust-ini" 1141name = "rust-ini"
1080version = "0.18.0" 1142version = "0.19.0"
1081source = "registry+https://github.com/rust-lang/crates.io-index" 1143source = "registry+https://github.com/rust-lang/crates.io-index"
1082checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" 1144checksum = "7e2a3bcec1f113553ef1c88aae6c020a369d03d55b58de9869a0908930385091"
1083dependencies = [ 1145dependencies = [
1084 "cfg-if", 1146 "cfg-if",
1085 "ordered-multimap", 1147 "ordered-multimap",
@@ -1174,6 +1236,15 @@ dependencies = [
1174] 1236]
1175 1237
1176[[package]] 1238[[package]]
1239name = "serde_spanned"
1240version = "0.6.5"
1241source = "registry+https://github.com/rust-lang/crates.io-index"
1242checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
1243dependencies = [
1244 "serde",
1245]
1246
1247[[package]]
1177name = "serde_urlencoded" 1248name = "serde_urlencoded"
1178version = "0.7.1" 1249version = "0.7.1"
1179source = "registry+https://github.com/rust-lang/crates.io-index" 1250source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1238,9 +1309,9 @@ dependencies = [
1238 1309
1239[[package]] 1310[[package]]
1240name = "strsim" 1311name = "strsim"
1241version = "0.10.0" 1312version = "0.11.0"
1242source = "registry+https://github.com/rust-lang/crates.io-index" 1313source = "registry+https://github.com/rust-lang/crates.io-index"
1243checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 1314checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
1244 1315
1245[[package]] 1316[[package]]
1246name = "syn" 1317name = "syn"
@@ -1308,6 +1379,15 @@ dependencies = [
1308] 1379]
1309 1380
1310[[package]] 1381[[package]]
1382name = "tiny-keccak"
1383version = "2.0.2"
1384source = "registry+https://github.com/rust-lang/crates.io-index"
1385checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
1386dependencies = [
1387 "crunchy",
1388]
1389
1390[[package]]
1311name = "tinyvec" 1391name = "tinyvec"
1312version = "1.6.0" 1392version = "1.6.0"
1313source = "registry+https://github.com/rust-lang/crates.io-index" 1393source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1324,9 +1404,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
1324 1404
1325[[package]] 1405[[package]]
1326name = "tokio" 1406name = "tokio"
1327version = "1.34.0" 1407version = "1.36.0"
1328source = "registry+https://github.com/rust-lang/crates.io-index" 1408source = "registry+https://github.com/rust-lang/crates.io-index"
1329checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" 1409checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931"
1330dependencies = [ 1410dependencies = [
1331 "backtrace", 1411 "backtrace",
1332 "bytes", 1412 "bytes",
@@ -1362,9 +1442,9 @@ dependencies = [
1362 1442
1363[[package]] 1443[[package]]
1364name = "tokio-tungstenite" 1444name = "tokio-tungstenite"
1365version = "0.20.1" 1445version = "0.21.0"
1366source = "registry+https://github.com/rust-lang/crates.io-index" 1446source = "registry+https://github.com/rust-lang/crates.io-index"
1367checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" 1447checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38"
1368dependencies = [ 1448dependencies = [
1369 "futures-util", 1449 "futures-util",
1370 "log", 1450 "log",
@@ -1388,11 +1468,36 @@ dependencies = [
1388 1468
1389[[package]] 1469[[package]]
1390name = "toml" 1470name = "toml"
1391version = "0.5.11" 1471version = "0.8.10"
1472source = "registry+https://github.com/rust-lang/crates.io-index"
1473checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290"
1474dependencies = [
1475 "serde",
1476 "serde_spanned",
1477 "toml_datetime",
1478 "toml_edit",
1479]
1480
1481[[package]]
1482name = "toml_datetime"
1483version = "0.6.5"
1484source = "registry+https://github.com/rust-lang/crates.io-index"
1485checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
1486dependencies = [
1487 "serde",
1488]
1489
1490[[package]]
1491name = "toml_edit"
1492version = "0.22.6"
1392source = "registry+https://github.com/rust-lang/crates.io-index" 1493source = "registry+https://github.com/rust-lang/crates.io-index"
1393checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" 1494checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6"
1394dependencies = [ 1495dependencies = [
1496 "indexmap 2.2.3",
1395 "serde", 1497 "serde",
1498 "serde_spanned",
1499 "toml_datetime",
1500 "winnow",
1396] 1501]
1397 1502
1398[[package]] 1503[[package]]
@@ -1428,14 +1533,14 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
1428 1533
1429[[package]] 1534[[package]]
1430name = "tungstenite" 1535name = "tungstenite"
1431version = "0.20.1" 1536version = "0.21.0"
1432source = "registry+https://github.com/rust-lang/crates.io-index" 1537source = "registry+https://github.com/rust-lang/crates.io-index"
1433checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" 1538checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1"
1434dependencies = [ 1539dependencies = [
1435 "byteorder", 1540 "byteorder",
1436 "bytes", 1541 "bytes",
1437 "data-encoding", 1542 "data-encoding",
1438 "http", 1543 "http 1.0.0",
1439 "httparse", 1544 "httparse",
1440 "log", 1545 "log",
1441 "rand", 1546 "rand",
@@ -1479,6 +1584,12 @@ dependencies = [
1479] 1584]
1480 1585
1481[[package]] 1586[[package]]
1587name = "unicode-segmentation"
1588version = "1.11.0"
1589source = "registry+https://github.com/rust-lang/crates.io-index"
1590checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
1591
1592[[package]]
1482name = "unicode-width" 1593name = "unicode-width"
1483version = "0.1.11" 1594version = "0.1.11"
1484source = "registry+https://github.com/rust-lang/crates.io-index" 1595source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1612,7 +1723,7 @@ dependencies = [
1612 1723
1613[[package]] 1724[[package]]
1614name = "webol-cli" 1725name = "webol-cli"
1615version = "0.1.0" 1726version = "0.2.0"
1616dependencies = [ 1727dependencies = [
1617 "clap", 1728 "clap",
1618 "clap_complete", 1729 "clap_complete",
@@ -1620,7 +1731,6 @@ dependencies = [
1620 "dirs", 1731 "dirs",
1621 "futures-util", 1732 "futures-util",
1622 "indicatif", 1733 "indicatif",
1623 "once_cell",
1624 "reqwest", 1734 "reqwest",
1625 "serde", 1735 "serde",
1626 "serde_json", 1736 "serde_json",
@@ -1783,6 +1893,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1783checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" 1893checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
1784 1894
1785[[package]] 1895[[package]]
1896name = "winnow"
1897version = "0.6.2"
1898source = "registry+https://github.com/rust-lang/crates.io-index"
1899checksum = "7a4191c47f15cc3ec71fcb4913cb83d58def65dd3787610213c649283b5ce178"
1900dependencies = [
1901 "memchr",
1902]
1903
1904[[package]]
1786name = "winreg" 1905name = "winreg"
1787version = "0.50.0" 1906version = "0.50.0"
1788source = "registry+https://github.com/rust-lang/crates.io-index" 1907source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index ca76349..461b0bf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "webol-cli" 2name = "webol-cli"
3version = "0.1.0" 3version = "0.2.0"
4edition = "2021" 4edition = "2021"
5 5
6# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 6# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -10,15 +10,14 @@ name = "webol"
10path = "src/main.rs" 10path = "src/main.rs"
11 11
12[dependencies] 12[dependencies]
13clap = { version = "4.4.6", features = ["derive"] } 13clap = { version = "4.5", features = ["derive"] }
14clap_complete = "4.4.4" 14clap_complete = "4.5"
15config = "0.13.3" 15config = "0.14"
16dirs = "5.0.1" 16dirs = "5.0"
17futures-util = "0.3.29" 17futures-util = "0.3"
18indicatif = "0.17.7" 18indicatif = "0.17"
19once_cell = "1.18.0" 19reqwest = { version = "0.11", features = ["blocking"] }
20reqwest = { version = "0.11.22", features = ["blocking"] } 20serde = "1.0"
21serde = "1.0.189" 21serde_json = "1.0"
22serde_json = "1.0.107" 22tokio = { version = "1.36", features = ["macros", "rt-multi-thread", "io-std"] }
23tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread", "io-std"] } 23tokio-tungstenite = "0.21"
24tokio-tungstenite = "0.20.1"
diff --git a/docker-compose.yml b/docker-compose.yml
index 3a0ade5..f41f4c9 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,20 +1,20 @@
1services: 1services:
2 webol: 2 webol:
3 image: ghcr.io/fxqnlr/webol:dev-6 3 image: ghcr.io/fxqnlr/webol:dev-9
4 container_name: webol 4 container_name: webol-cli-server
5 restart: no 5 restart: no
6 depends_on: 6 depends_on:
7 - db 7 - db
8 environment: 8 environment:
9 - RUST_LOG=info,webol=trace 9 - RUST_LOG=info,webol=trace
10 - WEBOL_DATABASE_URL=postgres://postgres:postgres@localhost:5432/webol 10 - WEBOL_DATABASE_URL=postgres://postgres:postgres@localhost:5432/webol
11 - WEBOL_APIKEY=aaa 11 - WEBOL_APIKEY=dev
12 - WEBOL_SERVERADDR=127.0.0.1:7229 12 - WEBOL_SERVERADDR=127.0.0.1:7229
13 network_mode: host 13 network_mode: host
14 14
15 db: 15 db:
16 image: postgres 16 image: postgres
17 container_name: webol-db 17 container_name: webol-cli-db
18 restart: no 18 restart: no
19 environment: 19 environment:
20 POSTGRES_PASSWORD: postgres 20 POSTGRES_PASSWORD: postgres
diff --git a/src/config.rs b/src/config.rs
index 9a9e44b..78795a3 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,19 +1,19 @@
1use config::Config; 1use serde::Deserialize;
2use once_cell::sync::Lazy;
3 2
4pub static SETTINGS: Lazy<Config> = Lazy::new(setup); 3#[derive(Deserialize)]
5 4pub struct Config {
6fn setup() -> Config { 5 pub apikey: String,
7 #[cfg(not(debug_assertions))] 6 pub server: String,
8 let builder = Config::builder().add_source(config::File::with_name( 7}
9 format!("{}/webol-cli.toml", dirs::config_dir().unwrap().to_string_lossy()).as_str(),
10 ));
11 8
12 #[cfg(debug_assertions)] 9impl Config {
13 let builder = Config::builder().add_source(config::File::with_name("webol-cli.toml")); 10 pub fn load() -> Result<Config, config::ConfigError> {
11 let builder = config::Config::builder()
12 .add_source(config::File::with_name("~/.config/webol-cli.toml"))
13 .add_source(config::File::with_name("webol-cli.toml"))
14 .add_source(config::Environment::with_prefix("WEBOL_CLI_").separator("_"))
15 .build()?;
14 16
15 builder 17 builder.try_deserialize()
16 .add_source(config::Environment::with_prefix("WEBOL_CLI_").separator("_")) 18 }
17 .build()
18 .unwrap()
19} 19}
diff --git a/src/error.rs b/src/error.rs
index f15c60a..531528f 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -11,11 +11,11 @@ pub enum CliError {
11impl Debug for CliError { 11impl Debug for CliError {
12 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 12 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13 match self { 13 match self {
14 Self::Reqwest(err) => { err.fmt(f) }, 14 Self::Reqwest(err) => err.fmt(f),
15 Self::Config(err) => { err.fmt(f) }, 15 Self::Config(err) => err.fmt(f),
16 Self::Serde(err) => { err.fmt(f) }, 16 Self::Serde(err) => err.fmt(f),
17 Self::Parse(err) => { err.fmt(f) }, 17 Self::Parse(err) => err.fmt(f),
18 Self::WsResponse => { f.write_str("Error in Response") }, 18 Self::WsResponse => f.write_str("Error in Response"),
19 } 19 }
20 } 20 }
21} 21}
diff --git a/src/main.rs b/src/main.rs
index afe6fac..0393183 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,11 +1,11 @@
1use std::{fmt::Display, time::Duration}; 1use std::{fmt::Display, time::Duration};
2 2
3use clap::{Parser, Command, CommandFactory, Subcommand}; 3use crate::config::Config;
4use clap_complete::{generate, Shell, Generator}; 4use clap::{Command, CommandFactory, Parser, Subcommand};
5use config::SETTINGS; 5use clap_complete::{generate, Generator, Shell};
6use error::CliError; 6use error::CliError;
7use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; 7use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
8use requests::{start::start, device}; 8use requests::{device, start::start};
9use reqwest::header::{HeaderMap, HeaderValue}; 9use reqwest::header::{HeaderMap, HeaderValue};
10use serde::Deserialize; 10use serde::Deserialize;
11 11
@@ -35,7 +35,7 @@ enum Commands {
35 /// id of the device 35 /// id of the device
36 id: String, 36 id: String,
37 #[arg(short, long)] 37 #[arg(short, long)]
38 ping: Option<bool> 38 ping: Option<bool>,
39 }, 39 },
40 Device { 40 Device {
41 #[command(subcommand)] 41 #[command(subcommand)]
@@ -52,7 +52,7 @@ enum DeviceCmd {
52 id: String, 52 id: String,
53 mac: String, 53 mac: String,
54 broadcast_addr: String, 54 broadcast_addr: String,
55 ip: String 55 ip: String,
56 }, 56 },
57 Get { 57 Get {
58 id: String, 58 id: String,
@@ -61,29 +61,39 @@ enum DeviceCmd {
61 id: String, 61 id: String,
62 mac: String, 62 mac: String,
63 broadcast_addr: String, 63 broadcast_addr: String,
64 ip: String 64 ip: String,
65 }, 65 },
66} 66}
67 67
68#[tokio::main] 68#[tokio::main]
69async fn main() -> Result<(), CliError> { 69async fn main() -> Result<(), CliError> {
70 let config = Config::load().map_err(CliError::Config)?;
71
70 let cli = Args::parse(); 72 let cli = Args::parse();
71 73
72 match cli.commands { 74 match cli.commands {
73 Commands::Start { id, ping } => { 75 Commands::Start { id, ping } => {
74 start(id, ping.unwrap_or(true)).await?; 76 start(&config, id, ping.unwrap_or(true)).await?;
75 }, 77 }
76 Commands::Device { devicecmd } => { 78 Commands::Device { devicecmd } => match devicecmd {
77 match devicecmd { 79 DeviceCmd::Add {
78 DeviceCmd::Add { id, mac, broadcast_addr, ip } => { 80 id,
79 device::put(id, mac, broadcast_addr, ip).await?; 81 mac,
80 }, 82 broadcast_addr,
81 DeviceCmd::Get { id } => { 83 ip,
82 device::get(id).await?; 84 } => {
83 }, 85 device::put(&config, id, mac, broadcast_addr, ip).await?;
84 DeviceCmd::Edit { id, mac, broadcast_addr, ip } => { 86 }
85 device::post(id, mac, broadcast_addr, ip).await?; 87 DeviceCmd::Get { id } => {
86 }, 88 device::get(&config, id).await?;
89 }
90 DeviceCmd::Edit {
91 id,
92 mac,
93 broadcast_addr,
94 ip,
95 } => {
96 device::post(&config, id, mac, broadcast_addr, ip).await?;
87 } 97 }
88 }, 98 },
89 Commands::CliGen { id } => { 99 Commands::CliGen { id } => {
@@ -100,29 +110,26 @@ fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
100 generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout()); 110 generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout());
101} 111}
102 112
103fn default_headers() -> Result<HeaderMap, CliError> { 113fn default_headers(config: &Config) -> Result<HeaderMap, CliError> {
104 let mut map = HeaderMap::new(); 114 let mut map = HeaderMap::new();
105 map.append("Accept-Content", HeaderValue::from_str("application/json").unwrap()); 115 map.append(
106 map.append("Content-Type", HeaderValue::from_str("application/json").unwrap()); 116 "Accept-Content",
117 HeaderValue::from_str("application/json").unwrap(),
118 );
119 map.append(
120 "Content-Type",
121 HeaderValue::from_str("application/json").unwrap(),
122 );
107 map.append( 123 map.append(
108 "Authorization", 124 "Authorization",
109 HeaderValue::from_str( 125 HeaderValue::from_str(&config.apikey).unwrap(),
110 SETTINGS.get_string("key")
111 .map_err(CliError::Config)?
112 .as_str()
113 ).unwrap()
114 ); 126 );
115 127
116 Ok(map) 128 Ok(map)
117} 129}
118 130
119fn format_url(path: &str, protocol: Protocols) -> Result<String, CliError> { 131fn format_url(config: &Config, path: &str, protocol: Protocols) -> Result<String, CliError> {
120 Ok(format!( 132 Ok(format!("{}://{}/{}", protocol, config.server, path))
121 "{}://{}/{}",
122 protocol,
123 SETTINGS.get_string("server").map_err(CliError::Config)?,
124 path
125 ))
126} 133}
127 134
128fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar { 135fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar {
@@ -137,7 +144,6 @@ fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar {
137fn finish_pb(pb: ProgressBar, message: String, template: &str) { 144fn finish_pb(pb: ProgressBar, message: String, template: &str) {
138 pb.set_style(ProgressStyle::with_template(template).unwrap()); 145 pb.set_style(ProgressStyle::with_template(template).unwrap());
139 pb.finish_with_message(message); 146 pb.finish_with_message(message);
140
141} 147}
142 148
143enum Protocols { 149enum Protocols {
@@ -149,12 +155,12 @@ impl Display for Protocols {
149 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 155 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
150 match self { 156 match self {
151 Self::Http => f.write_str("http"), 157 Self::Http => f.write_str("http"),
152 Self::Websocket => f.write_str("ws") 158 Self::Websocket => f.write_str("ws"),
153 } 159 }
154 } 160 }
155} 161}
156 162
157#[derive(Debug, Deserialize)] 163#[derive(Debug, Deserialize)]
158struct ErrorResponse { 164struct ErrorResponse {
159 error: String 165 error: String,
160} 166}
diff --git a/src/requests/mod.rs b/src/requests.rs
index 6855db1..6855db1 100644
--- a/src/requests/mod.rs
+++ b/src/requests.rs
diff --git a/src/requests/device.rs b/src/requests/device.rs
index cbc838e..5003c4a 100644
--- a/src/requests/device.rs
+++ b/src/requests/device.rs
@@ -1,20 +1,21 @@
1use crate::{error::CliError, default_headers, format_url, Protocols}; 1use crate::{config::Config, default_headers, error::CliError, format_url, Protocols};
2 2
3pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { 3pub async fn put(
4 let url = format_url("device", Protocols::Http)?; 4 config: &Config,
5 id: String,
6 mac: String,
7 broadcast_addr: String,
8 ip: String,
9) -> Result<(), CliError> {
10 let url = format_url(config, "device", Protocols::Http)?;
5 println!("{}", url); 11 println!("{}", url);
6 let res = reqwest::Client::new() 12 let res = reqwest::Client::new()
7 .put(url) 13 .put(url)
8 .headers(default_headers()?) 14 .headers(default_headers(config)?)
9 .body( 15 .body(format!(
10 format!( 16 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#,
11 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, 17 id, mac, broadcast_addr, ip
12 id, 18 ))
13 mac,
14 broadcast_addr,
15 ip
16 )
17 )
18 .send() 19 .send()
19 .await 20 .await
20 .map_err(CliError::Reqwest)? 21 .map_err(CliError::Reqwest)?
@@ -25,13 +26,11 @@ pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) ->
25 Ok(()) 26 Ok(())
26} 27}
27 28
28pub async fn get(id: String) -> Result<(), CliError> { 29pub async fn get(config: &Config, id: String) -> Result<(), CliError> {
29 let res = reqwest::Client::new() 30 let res = reqwest::Client::new()
30 .get(format_url("device", Protocols::Http)?) 31 .get(format_url(config, "device", Protocols::Http)?)
31 .headers(default_headers()?) 32 .headers(default_headers(config)?)
32 .body( 33 .body(format!(r#"{{"id": "{}"}}"#, id))
33 format!(r#"{{"id": "{}"}}"#, id)
34 )
35 .send() 34 .send()
36 .await 35 .await
37 .map_err(CliError::Reqwest)? 36 .map_err(CliError::Reqwest)?
@@ -42,19 +41,20 @@ pub async fn get(id: String) -> Result<(), CliError> {
42 Ok(()) 41 Ok(())
43} 42}
44 43
45pub async fn post(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { 44pub async fn post(
45 config: &Config,
46 id: String,
47 mac: String,
48 broadcast_addr: String,
49 ip: String,
50) -> Result<(), CliError> {
46 let res = reqwest::Client::new() 51 let res = reqwest::Client::new()
47 .post(format_url("device", Protocols::Http)?) 52 .post(format_url(config, "device", Protocols::Http)?)
48 .headers(default_headers()?) 53 .headers(default_headers(config)?)
49 .body( 54 .body(format!(
50 format!( 55 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#,
51 r#"{{"id": "{}", "mac": "{}", "broadcast_addr": "{}", "ip": "{}"}}"#, 56 id, mac, broadcast_addr, ip
52 id, 57 ))
53 mac,
54 broadcast_addr,
55 ip
56 )
57 )
58 .send() 58 .send()
59 .await 59 .await
60 .map_err(CliError::Reqwest)? 60 .map_err(CliError::Reqwest)?
diff --git a/src/requests/start.rs b/src/requests/start.rs
index ca4ca44..bc63303 100644
--- a/src/requests/start.rs
+++ b/src/requests/start.rs
@@ -1,25 +1,26 @@
1use futures_util::{StreamExt, SinkExt}; 1use futures_util::{SinkExt, StreamExt};
2use indicatif::{MultiProgress, ProgressBar}; 2use indicatif::{MultiProgress, ProgressBar};
3use reqwest::StatusCode; 3use reqwest::StatusCode;
4use serde::Deserialize; 4use serde::Deserialize;
5use tokio_tungstenite::{connect_async, tungstenite::Message}; 5use tokio_tungstenite::{connect_async, tungstenite::Message};
6 6
7use crate::{error::CliError, default_headers, ErrorResponse, format_url, Protocols, OVERVIEW_STYLE, DEFAULT_STYLE, DONE_STYLE, finish_pb, ERROR_STYLE, OVERVIEW_ERROR, OVERVIEW_DONE, add_pb}; 7use crate::{
8 8 add_pb, config::Config, default_headers, error::CliError, finish_pb, format_url, ErrorResponse,
9pub async fn start(id: String, ping: bool) -> Result<(), CliError> { 9 Protocols, DEFAULT_STYLE, DONE_STYLE, ERROR_STYLE, OVERVIEW_DONE, OVERVIEW_ERROR,
10 OVERVIEW_STYLE,
11};
10 12
13pub async fn start(config: &Config, id: String, ping: bool) -> Result<(), CliError> {
11 let send_start = MultiProgress::new(); 14 let send_start = MultiProgress::new();
12 let overview = add_pb(&send_start, OVERVIEW_STYLE, format!(") start {}", id)); 15 let overview = add_pb(&send_start, OVERVIEW_STYLE, format!(") start {}", id));
13 16
14 // TODO: calculate average start-time on server 17 // TODO: calculate average start-time on server
15 let url = format_url("start", Protocols::Http)?; 18 let url = format_url(config, "start", Protocols::Http)?;
16 let connect = add_pb(&send_start, DEFAULT_STYLE, format!("connect to {}", url)); 19 let connect = add_pb(&send_start, DEFAULT_STYLE, format!("connect to {}", url));
17 let res = reqwest::Client::new() 20 let res = reqwest::Client::new()
18 .post(url) 21 .post(url)
19 .headers(default_headers()?) 22 .headers(default_headers(config)?)
20 .body( 23 .body(format!(r#"{{"id": "{}", "ping": {}}}"#, id, ping))
21 format!(r#"{{"id": "{}", "ping": {}}}"#, id, ping)
22 )
23 .send() 24 .send()
24 .await 25 .await
25 .map_err(CliError::Reqwest)?; 26 .map_err(CliError::Reqwest)?;
@@ -29,7 +30,7 @@ pub async fn start(id: String, ping: bool) -> Result<(), CliError> {
29 match res.status() { 30 match res.status() {
30 StatusCode::OK => { 31 StatusCode::OK => {
31 let body = serde_json::from_str::<StartResponse>( 32 let body = serde_json::from_str::<StartResponse>(
32 &res.text().await.map_err(CliError::Reqwest)? 33 &res.text().await.map_err(CliError::Reqwest)?,
33 ) 34 )
34 .map_err(CliError::Serde)?; 35 .map_err(CliError::Serde)?;
35 36
@@ -38,17 +39,25 @@ pub async fn start(id: String, ping: bool) -> Result<(), CliError> {
38 } 39 }
39 40
40 if ping { 41 if ping {
41 let status = status_socket(body.uuid, &send_start, &overview, id).await?; 42 let status = status_socket(config, body.uuid, &send_start, &overview, id).await?;
42 if status { 43 if status {
43 finish_pb(overview, format!("successfully started {}", body.id), OVERVIEW_DONE); 44 finish_pb(
45 overview,
46 format!("successfully started {}", body.id),
47 OVERVIEW_DONE,
48 );
44 } else { 49 } else {
45 finish_pb(overview, format!("error while starting {}", body.id), OVERVIEW_ERROR); 50 finish_pb(
51 overview,
52 format!("error while starting {}", body.id),
53 OVERVIEW_ERROR,
54 );
46 } 55 }
47 } 56 }
48 }, 57 }
49 _ => { 58 _ => {
50 let body = serde_json::from_str::<ErrorResponse>( 59 let body = serde_json::from_str::<ErrorResponse>(
51 &res.text().await.map_err(CliError::Reqwest)? 60 &res.text().await.map_err(CliError::Reqwest)?,
52 ) 61 )
53 .map_err(CliError::Serde)?; 62 .map_err(CliError::Serde)?;
54 63
@@ -59,16 +68,22 @@ pub async fn start(id: String, ping: bool) -> Result<(), CliError> {
59 Ok(()) 68 Ok(())
60} 69}
61 70
62async fn status_socket(uuid: String, pb: &MultiProgress, overview: &ProgressBar, id: String) -> Result<bool, CliError> { 71async fn status_socket(
63 // TODO: Remove unwraps 72 config: &Config,
73 uuid: String,
74 pb: &MultiProgress,
75 overview: &ProgressBar,
76 id: String,
77) -> Result<bool, CliError> {
64 let ws_pb = add_pb(pb, DEFAULT_STYLE, "connect to websocket".to_string()); 78 let ws_pb = add_pb(pb, DEFAULT_STYLE, "connect to websocket".to_string());
65 let (mut ws_stream, _response) = connect_async(format_url("status", Protocols::Websocket)?) 79 let (mut ws_stream, _response) =
66 .await 80 connect_async(format_url(config, "status", Protocols::Websocket)?)
67 .expect("Failed to connect"); 81 .await
82 .expect("Failed to connect");
68 finish_pb(ws_pb, "connected to websocket".to_string(), DONE_STYLE); 83 finish_pb(ws_pb, "connected to websocket".to_string(), DONE_STYLE);
69 84
70 ws_stream.send(Message::Text(uuid.clone())).await.unwrap(); 85 ws_stream.send(Message::Text(uuid.clone())).await.unwrap();
71 86
72 // Get ETA 87 // Get ETA
73 let eta_msg = ws_stream.next().await.unwrap().unwrap(); 88 let eta_msg = ws_stream.next().await.unwrap().unwrap();
74 let eta = get_eta(eta_msg.into_text().unwrap(), uuid.clone())? + overview.elapsed().as_secs(); 89 let eta = get_eta(eta_msg.into_text().unwrap(), uuid.clone())? + overview.elapsed().as_secs();
@@ -86,29 +101,29 @@ async fn status_socket(uuid: String, pb: &MultiProgress, overview: &ProgressBar,
86 Verified::WrongUuid => { 101 Verified::WrongUuid => {
87 finish_pb(v_pb, "returned wrong uuid".to_string(), ERROR_STYLE); 102 finish_pb(v_pb, "returned wrong uuid".to_string(), ERROR_STYLE);
88 Ok(false) 103 Ok(false)
89 },
90 Verified::ResponseType(res_type) => {
91 match res_type {
92 ResponseType::Start => {
93 finish_pb(v_pb, "device started".to_string(), DONE_STYLE);
94 Ok(true)
95 },
96 ResponseType::Timeout => {
97 finish_pb(v_pb, "ping timed out".to_string(), ERROR_STYLE);
98 Ok(false)
99 },
100 ResponseType::NotFound => {
101 finish_pb(v_pb, "unknown uuid".to_string(), ERROR_STYLE);
102 Ok(false)
103 },
104 }
105 } 104 }
105 Verified::ResponseType(res_type) => match res_type {
106 ResponseType::Start => {
107 finish_pb(v_pb, "device started".to_string(), DONE_STYLE);
108 Ok(true)
109 }
110 ResponseType::Timeout => {
111 finish_pb(v_pb, "ping timed out".to_string(), ERROR_STYLE);
112 Ok(false)
113 }
114 ResponseType::NotFound => {
115 finish_pb(v_pb, "unknown uuid".to_string(), ERROR_STYLE);
116 Ok(false)
117 }
118 },
106 } 119 }
107} 120}
108 121
109fn get_eta(msg: String, uuid: String) -> Result<u64, CliError> { 122fn get_eta(msg: String, uuid: String) -> Result<u64, CliError> {
110 let spl: Vec<&str> = msg.split('_').collect(); 123 let spl: Vec<&str> = msg.split('_').collect();
111 if (spl[0] != "eta") || (spl[2] != uuid) { return Err(CliError::WsResponse); }; 124 if (spl[0] != "eta") || (spl[2] != uuid) {
125 return Err(CliError::WsResponse);
126 };
112 Ok(u64::from_str_radix(spl[1], 10).map_err(CliError::Parse)?) 127 Ok(u64::from_str_radix(spl[1], 10).map_err(CliError::Parse)?)
113} 128}
114 129
@@ -116,9 +131,11 @@ fn verify_response(res: String, org_uuid: String) -> Result<Verified, CliError>
116 let spl: Vec<&str> = res.split('_').collect(); 131 let spl: Vec<&str> = res.split('_').collect();
117 let res_type = spl[0]; 132 let res_type = spl[0];
118 let uuid = spl[1]; 133 let uuid = spl[1];
119 134
120 if uuid != org_uuid { return Ok(Verified::WrongUuid) }; 135 if uuid != org_uuid {
121 136 return Ok(Verified::WrongUuid);
137 };
138
122 Ok(Verified::ResponseType(ResponseType::from(res_type)?)) 139 Ok(Verified::ResponseType(ResponseType::from(res_type)?))
123} 140}
124 141
@@ -131,7 +148,7 @@ struct StartResponse {
131 148
132enum Verified { 149enum Verified {
133 ResponseType(ResponseType), 150 ResponseType(ResponseType),
134 WrongUuid 151 WrongUuid,
135} 152}
136 153
137enum ResponseType { 154enum ResponseType {