diff options
-rw-r--r-- | Cargo.lock | 253 | ||||
-rw-r--r-- | Cargo.toml | 25 | ||||
-rw-r--r-- | docker-compose.yml | 8 | ||||
-rw-r--r-- | src/config.rs | 30 | ||||
-rw-r--r-- | src/error.rs | 10 | ||||
-rw-r--r-- | src/main.rs | 84 | ||||
-rw-r--r-- | src/requests.rs (renamed from src/requests/mod.rs) | 0 | ||||
-rw-r--r-- | src/requests/device.rs | 62 | ||||
-rw-r--r-- | src/requests/start.rs | 103 |
9 files changed, 358 insertions, 217 deletions
@@ -18,21 +18,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
18 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" | 18 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" |
19 | 19 | ||
20 | [[package]] | 20 | [[package]] |
21 | name = "ahash" | ||
22 | version = "0.7.7" | ||
23 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
24 | checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" | ||
25 | dependencies = [ | ||
26 | "getrandom", | ||
27 | "once_cell", | ||
28 | "version_check", | ||
29 | ] | ||
30 | |||
31 | [[package]] | ||
32 | name = "anstream" | 21 | name = "anstream" |
33 | version = "0.6.4" | 22 | version = "0.6.12" |
34 | source = "registry+https://github.com/rust-lang/crates.io-index" | 23 | source = "registry+https://github.com/rust-lang/crates.io-index" |
35 | checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" | 24 | checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540" |
36 | dependencies = [ | 25 | dependencies = [ |
37 | "anstyle", | 26 | "anstyle", |
38 | "anstyle-parse", | 27 | "anstyle-parse", |
@@ -110,12 +99,6 @@ dependencies = [ | |||
110 | 99 | ||
111 | [[package]] | 100 | [[package]] |
112 | name = "base64" | 101 | name = "base64" |
113 | version = "0.13.1" | ||
114 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
115 | checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" | ||
116 | |||
117 | [[package]] | ||
118 | name = "base64" | ||
119 | version = "0.21.5" | 102 | version = "0.21.5" |
120 | source = "registry+https://github.com/rust-lang/crates.io-index" | 103 | source = "registry+https://github.com/rust-lang/crates.io-index" |
121 | checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" | 104 | checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" |
@@ -131,6 +114,9 @@ name = "bitflags" | |||
131 | version = "2.4.1" | 114 | version = "2.4.1" |
132 | source = "registry+https://github.com/rust-lang/crates.io-index" | 115 | source = "registry+https://github.com/rust-lang/crates.io-index" |
133 | checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" | 116 | checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" |
117 | dependencies = [ | ||
118 | "serde", | ||
119 | ] | ||
134 | 120 | ||
135 | [[package]] | 121 | [[package]] |
136 | name = "block-buffer" | 122 | name = "block-buffer" |
@@ -176,9 +162,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | |||
176 | 162 | ||
177 | [[package]] | 163 | [[package]] |
178 | name = "clap" | 164 | name = "clap" |
179 | version = "4.4.8" | 165 | version = "4.5.1" |
180 | source = "registry+https://github.com/rust-lang/crates.io-index" | 166 | source = "registry+https://github.com/rust-lang/crates.io-index" |
181 | checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" | 167 | checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" |
182 | dependencies = [ | 168 | dependencies = [ |
183 | "clap_builder", | 169 | "clap_builder", |
184 | "clap_derive", | 170 | "clap_derive", |
@@ -186,9 +172,9 @@ dependencies = [ | |||
186 | 172 | ||
187 | [[package]] | 173 | [[package]] |
188 | name = "clap_builder" | 174 | name = "clap_builder" |
189 | version = "4.4.8" | 175 | version = "4.5.1" |
190 | source = "registry+https://github.com/rust-lang/crates.io-index" | 176 | source = "registry+https://github.com/rust-lang/crates.io-index" |
191 | checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" | 177 | checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" |
192 | dependencies = [ | 178 | dependencies = [ |
193 | "anstream", | 179 | "anstream", |
194 | "anstyle", | 180 | "anstyle", |
@@ -198,18 +184,18 @@ dependencies = [ | |||
198 | 184 | ||
199 | [[package]] | 185 | [[package]] |
200 | name = "clap_complete" | 186 | name = "clap_complete" |
201 | version = "4.4.4" | 187 | version = "4.5.1" |
202 | source = "registry+https://github.com/rust-lang/crates.io-index" | 188 | source = "registry+https://github.com/rust-lang/crates.io-index" |
203 | checksum = "bffe91f06a11b4b9420f62103854e90867812cd5d01557f853c5ee8e791b12ae" | 189 | checksum = "885e4d7d5af40bfb99ae6f9433e292feac98d452dcb3ec3d25dfe7552b77da8c" |
204 | dependencies = [ | 190 | dependencies = [ |
205 | "clap", | 191 | "clap", |
206 | ] | 192 | ] |
207 | 193 | ||
208 | [[package]] | 194 | [[package]] |
209 | name = "clap_derive" | 195 | name = "clap_derive" |
210 | version = "4.4.7" | 196 | version = "4.5.0" |
211 | source = "registry+https://github.com/rust-lang/crates.io-index" | 197 | source = "registry+https://github.com/rust-lang/crates.io-index" |
212 | checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" | 198 | checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" |
213 | dependencies = [ | 199 | dependencies = [ |
214 | "heck", | 200 | "heck", |
215 | "proc-macro2", | 201 | "proc-macro2", |
@@ -219,9 +205,9 @@ dependencies = [ | |||
219 | 205 | ||
220 | [[package]] | 206 | [[package]] |
221 | name = "clap_lex" | 207 | name = "clap_lex" |
222 | version = "0.6.0" | 208 | version = "0.7.0" |
223 | source = "registry+https://github.com/rust-lang/crates.io-index" | 209 | source = "registry+https://github.com/rust-lang/crates.io-index" |
224 | checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" | 210 | checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" |
225 | 211 | ||
226 | [[package]] | 212 | [[package]] |
227 | name = "colorchoice" | 213 | name = "colorchoice" |
@@ -231,11 +217,12 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" | |||
231 | 217 | ||
232 | [[package]] | 218 | [[package]] |
233 | name = "config" | 219 | name = "config" |
234 | version = "0.13.3" | 220 | version = "0.14.0" |
235 | source = "registry+https://github.com/rust-lang/crates.io-index" | 221 | source = "registry+https://github.com/rust-lang/crates.io-index" |
236 | checksum = "d379af7f68bfc21714c6c7dea883544201741d2ce8274bb12fa54f89507f52a7" | 222 | checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be" |
237 | dependencies = [ | 223 | dependencies = [ |
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]] |
252 | name = "const-random" | ||
253 | version = "0.1.17" | ||
254 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
255 | checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a" | ||
256 | dependencies = [ | ||
257 | "const-random-macro", | ||
258 | ] | ||
259 | |||
260 | [[package]] | ||
261 | name = "const-random-macro" | ||
262 | version = "0.1.16" | ||
263 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
264 | checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" | ||
265 | dependencies = [ | ||
266 | "getrandom", | ||
267 | "once_cell", | ||
268 | "tiny-keccak", | ||
269 | ] | ||
270 | |||
271 | [[package]] | ||
272 | name = "convert_case" | ||
273 | version = "0.6.0" | ||
274 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
275 | checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" | ||
276 | dependencies = [ | ||
277 | "unicode-segmentation", | ||
278 | ] | ||
279 | |||
280 | [[package]] | ||
265 | name = "core-foundation" | 281 | name = "core-foundation" |
266 | version = "0.9.3" | 282 | version = "0.9.3" |
267 | source = "registry+https://github.com/rust-lang/crates.io-index" | 283 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -287,6 +303,12 @@ dependencies = [ | |||
287 | ] | 303 | ] |
288 | 304 | ||
289 | [[package]] | 305 | [[package]] |
306 | name = "crunchy" | ||
307 | version = "0.2.2" | ||
308 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
309 | checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" | ||
310 | |||
311 | [[package]] | ||
290 | name = "crypto-common" | 312 | name = "crypto-common" |
291 | version = "0.1.6" | 313 | version = "0.1.6" |
292 | source = "registry+https://github.com/rust-lang/crates.io-index" | 314 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -335,9 +357,12 @@ dependencies = [ | |||
335 | 357 | ||
336 | [[package]] | 358 | [[package]] |
337 | name = "dlv-list" | 359 | name = "dlv-list" |
338 | version = "0.3.0" | 360 | version = "0.5.2" |
339 | source = "registry+https://github.com/rust-lang/crates.io-index" | 361 | source = "registry+https://github.com/rust-lang/crates.io-index" |
340 | checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" | 362 | checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" |
363 | dependencies = [ | ||
364 | "const-random", | ||
365 | ] | ||
341 | 366 | ||
342 | [[package]] | 367 | [[package]] |
343 | name = "encode_unicode" | 368 | name = "encode_unicode" |
@@ -355,6 +380,12 @@ dependencies = [ | |||
355 | ] | 380 | ] |
356 | 381 | ||
357 | [[package]] | 382 | [[package]] |
383 | name = "equivalent" | ||
384 | version = "1.0.1" | ||
385 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
386 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" | ||
387 | |||
388 | [[package]] | ||
358 | name = "errno" | 389 | name = "errno" |
359 | version = "0.3.6" | 390 | version = "0.3.6" |
360 | source = "registry+https://github.com/rust-lang/crates.io-index" | 391 | source = "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" | |||
512 | version = "0.12.3" | 543 | version = "0.12.3" |
513 | source = "registry+https://github.com/rust-lang/crates.io-index" | 544 | source = "registry+https://github.com/rust-lang/crates.io-index" |
514 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" | 545 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" |
515 | dependencies = [ | 546 | |
516 | "ahash", | 547 | [[package]] |
517 | ] | 548 | name = "hashbrown" |
549 | version = "0.13.2" | ||
550 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
551 | checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" | ||
552 | |||
553 | [[package]] | ||
554 | name = "hashbrown" | ||
555 | version = "0.14.3" | ||
556 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
557 | checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" | ||
518 | 558 | ||
519 | [[package]] | 559 | [[package]] |
520 | name = "heck" | 560 | name = "heck" |
@@ -540,13 +580,24 @@ dependencies = [ | |||
540 | ] | 580 | ] |
541 | 581 | ||
542 | [[package]] | 582 | [[package]] |
583 | name = "http" | ||
584 | version = "1.0.0" | ||
585 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
586 | checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" | ||
587 | dependencies = [ | ||
588 | "bytes", | ||
589 | "fnv", | ||
590 | "itoa", | ||
591 | ] | ||
592 | |||
593 | [[package]] | ||
543 | name = "http-body" | 594 | name = "http-body" |
544 | version = "0.4.5" | 595 | version = "0.4.5" |
545 | source = "registry+https://github.com/rust-lang/crates.io-index" | 596 | source = "registry+https://github.com/rust-lang/crates.io-index" |
546 | checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" | 597 | checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" |
547 | dependencies = [ | 598 | dependencies = [ |
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" | |||
616 | checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" | 667 | checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" |
617 | dependencies = [ | 668 | dependencies = [ |
618 | "autocfg", | 669 | "autocfg", |
619 | "hashbrown", | 670 | "hashbrown 0.12.3", |
671 | ] | ||
672 | |||
673 | [[package]] | ||
674 | name = "indexmap" | ||
675 | version = "2.2.3" | ||
676 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
677 | checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" | ||
678 | dependencies = [ | ||
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]] |
809 | name = "once_cell" | 870 | name = "once_cell" |
810 | version = "1.18.0" | 871 | version = "1.19.0" |
811 | source = "registry+https://github.com/rust-lang/crates.io-index" | 872 | source = "registry+https://github.com/rust-lang/crates.io-index" |
812 | checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" | 873 | checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" |
813 | 874 | ||
814 | [[package]] | 875 | [[package]] |
815 | name = "openssl" | 876 | name = "openssl" |
@@ -863,12 +924,12 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" | |||
863 | 924 | ||
864 | [[package]] | 925 | [[package]] |
865 | name = "ordered-multimap" | 926 | name = "ordered-multimap" |
866 | version = "0.4.3" | 927 | version = "0.6.0" |
867 | source = "registry+https://github.com/rust-lang/crates.io-index" | 928 | source = "registry+https://github.com/rust-lang/crates.io-index" |
868 | checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a" | 929 | checksum = "4ed8acf08e98e744e5384c8bc63ceb0364e68a6854187221c18df61c4797690e" |
869 | dependencies = [ | 930 | dependencies = [ |
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" | |||
1032 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1093 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1033 | checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" | 1094 | checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" |
1034 | dependencies = [ | 1095 | dependencies = [ |
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]] |
1068 | name = "ron" | 1129 | name = "ron" |
1069 | version = "0.7.1" | 1130 | version = "0.8.1" |
1070 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1131 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1071 | checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" | 1132 | checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94" |
1072 | dependencies = [ | 1133 | dependencies = [ |
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]] |
1079 | name = "rust-ini" | 1141 | name = "rust-ini" |
1080 | version = "0.18.0" | 1142 | version = "0.19.0" |
1081 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1143 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1082 | checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df" | 1144 | checksum = "7e2a3bcec1f113553ef1c88aae6c020a369d03d55b58de9869a0908930385091" |
1083 | dependencies = [ | 1145 | dependencies = [ |
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]] |
1239 | name = "serde_spanned" | ||
1240 | version = "0.6.5" | ||
1241 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1242 | checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" | ||
1243 | dependencies = [ | ||
1244 | "serde", | ||
1245 | ] | ||
1246 | |||
1247 | [[package]] | ||
1177 | name = "serde_urlencoded" | 1248 | name = "serde_urlencoded" |
1178 | version = "0.7.1" | 1249 | version = "0.7.1" |
1179 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1250 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1238,9 +1309,9 @@ dependencies = [ | |||
1238 | 1309 | ||
1239 | [[package]] | 1310 | [[package]] |
1240 | name = "strsim" | 1311 | name = "strsim" |
1241 | version = "0.10.0" | 1312 | version = "0.11.0" |
1242 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1313 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1243 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" | 1314 | checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" |
1244 | 1315 | ||
1245 | [[package]] | 1316 | [[package]] |
1246 | name = "syn" | 1317 | name = "syn" |
@@ -1308,6 +1379,15 @@ dependencies = [ | |||
1308 | ] | 1379 | ] |
1309 | 1380 | ||
1310 | [[package]] | 1381 | [[package]] |
1382 | name = "tiny-keccak" | ||
1383 | version = "2.0.2" | ||
1384 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1385 | checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" | ||
1386 | dependencies = [ | ||
1387 | "crunchy", | ||
1388 | ] | ||
1389 | |||
1390 | [[package]] | ||
1311 | name = "tinyvec" | 1391 | name = "tinyvec" |
1312 | version = "1.6.0" | 1392 | version = "1.6.0" |
1313 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1393 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1324,9 +1404,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" | |||
1324 | 1404 | ||
1325 | [[package]] | 1405 | [[package]] |
1326 | name = "tokio" | 1406 | name = "tokio" |
1327 | version = "1.34.0" | 1407 | version = "1.36.0" |
1328 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1408 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1329 | checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" | 1409 | checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" |
1330 | dependencies = [ | 1410 | dependencies = [ |
1331 | "backtrace", | 1411 | "backtrace", |
1332 | "bytes", | 1412 | "bytes", |
@@ -1362,9 +1442,9 @@ dependencies = [ | |||
1362 | 1442 | ||
1363 | [[package]] | 1443 | [[package]] |
1364 | name = "tokio-tungstenite" | 1444 | name = "tokio-tungstenite" |
1365 | version = "0.20.1" | 1445 | version = "0.21.0" |
1366 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1446 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1367 | checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" | 1447 | checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" |
1368 | dependencies = [ | 1448 | dependencies = [ |
1369 | "futures-util", | 1449 | "futures-util", |
1370 | "log", | 1450 | "log", |
@@ -1388,11 +1468,36 @@ dependencies = [ | |||
1388 | 1468 | ||
1389 | [[package]] | 1469 | [[package]] |
1390 | name = "toml" | 1470 | name = "toml" |
1391 | version = "0.5.11" | 1471 | version = "0.8.10" |
1472 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1473 | checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290" | ||
1474 | dependencies = [ | ||
1475 | "serde", | ||
1476 | "serde_spanned", | ||
1477 | "toml_datetime", | ||
1478 | "toml_edit", | ||
1479 | ] | ||
1480 | |||
1481 | [[package]] | ||
1482 | name = "toml_datetime" | ||
1483 | version = "0.6.5" | ||
1484 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1485 | checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" | ||
1486 | dependencies = [ | ||
1487 | "serde", | ||
1488 | ] | ||
1489 | |||
1490 | [[package]] | ||
1491 | name = "toml_edit" | ||
1492 | version = "0.22.6" | ||
1392 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1493 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1393 | checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" | 1494 | checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6" |
1394 | dependencies = [ | 1495 | dependencies = [ |
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]] |
1430 | name = "tungstenite" | 1535 | name = "tungstenite" |
1431 | version = "0.20.1" | 1536 | version = "0.21.0" |
1432 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1537 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1433 | checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" | 1538 | checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" |
1434 | dependencies = [ | 1539 | dependencies = [ |
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]] |
1587 | name = "unicode-segmentation" | ||
1588 | version = "1.11.0" | ||
1589 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1590 | checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" | ||
1591 | |||
1592 | [[package]] | ||
1482 | name = "unicode-width" | 1593 | name = "unicode-width" |
1483 | version = "0.1.11" | 1594 | version = "0.1.11" |
1484 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1595 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1612,7 +1723,7 @@ dependencies = [ | |||
1612 | 1723 | ||
1613 | [[package]] | 1724 | [[package]] |
1614 | name = "webol-cli" | 1725 | name = "webol-cli" |
1615 | version = "0.1.0" | 1726 | version = "0.2.0" |
1616 | dependencies = [ | 1727 | dependencies = [ |
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" | |||
1783 | checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" | 1893 | checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" |
1784 | 1894 | ||
1785 | [[package]] | 1895 | [[package]] |
1896 | name = "winnow" | ||
1897 | version = "0.6.2" | ||
1898 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
1899 | checksum = "7a4191c47f15cc3ec71fcb4913cb83d58def65dd3787610213c649283b5ce178" | ||
1900 | dependencies = [ | ||
1901 | "memchr", | ||
1902 | ] | ||
1903 | |||
1904 | [[package]] | ||
1786 | name = "winreg" | 1905 | name = "winreg" |
1787 | version = "0.50.0" | 1906 | version = "0.50.0" |
1788 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1907 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1,6 +1,6 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "webol-cli" | 2 | name = "webol-cli" |
3 | version = "0.1.0" | 3 | version = "0.2.0" |
4 | edition = "2021" | 4 | edition = "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" | |||
10 | path = "src/main.rs" | 10 | path = "src/main.rs" |
11 | 11 | ||
12 | [dependencies] | 12 | [dependencies] |
13 | clap = { version = "4.4.6", features = ["derive"] } | 13 | clap = { version = "4.5", features = ["derive"] } |
14 | clap_complete = "4.4.4" | 14 | clap_complete = "4.5" |
15 | config = "0.13.3" | 15 | config = "0.14" |
16 | dirs = "5.0.1" | 16 | dirs = "5.0" |
17 | futures-util = "0.3.29" | 17 | futures-util = "0.3" |
18 | indicatif = "0.17.7" | 18 | indicatif = "0.17" |
19 | once_cell = "1.18.0" | 19 | reqwest = { version = "0.11", features = ["blocking"] } |
20 | reqwest = { version = "0.11.22", features = ["blocking"] } | 20 | serde = "1.0" |
21 | serde = "1.0.189" | 21 | serde_json = "1.0" |
22 | serde_json = "1.0.107" | 22 | tokio = { version = "1.36", features = ["macros", "rt-multi-thread", "io-std"] } |
23 | tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread", "io-std"] } | 23 | tokio-tungstenite = "0.21" |
24 | tokio-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 @@ | |||
1 | services: | 1 | services: |
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 @@ | |||
1 | use config::Config; | 1 | use serde::Deserialize; |
2 | use once_cell::sync::Lazy; | ||
3 | 2 | ||
4 | pub static SETTINGS: Lazy<Config> = Lazy::new(setup); | 3 | #[derive(Deserialize)] |
5 | 4 | pub struct Config { | |
6 | fn 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)] | 9 | impl 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 { | |||
11 | impl Debug for CliError { | 11 | impl 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 @@ | |||
1 | use std::{fmt::Display, time::Duration}; | 1 | use std::{fmt::Display, time::Duration}; |
2 | 2 | ||
3 | use clap::{Parser, Command, CommandFactory, Subcommand}; | 3 | use crate::config::Config; |
4 | use clap_complete::{generate, Shell, Generator}; | 4 | use clap::{Command, CommandFactory, Parser, Subcommand}; |
5 | use config::SETTINGS; | 5 | use clap_complete::{generate, Generator, Shell}; |
6 | use error::CliError; | 6 | use error::CliError; |
7 | use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; | 7 | use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; |
8 | use requests::{start::start, device}; | 8 | use requests::{device, start::start}; |
9 | use reqwest::header::{HeaderMap, HeaderValue}; | 9 | use reqwest::header::{HeaderMap, HeaderValue}; |
10 | use serde::Deserialize; | 10 | use 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] |
69 | async fn main() -> Result<(), CliError> { | 69 | async 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 | ||
103 | fn default_headers() -> Result<HeaderMap, CliError> { | 113 | fn 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 | ||
119 | fn format_url(path: &str, protocol: Protocols) -> Result<String, CliError> { | 131 | fn 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 | ||
128 | fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar { | 135 | fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar { |
@@ -137,7 +144,6 @@ fn add_pb(mp: &MultiProgress, template: &str, message: String) -> ProgressBar { | |||
137 | fn finish_pb(pb: ProgressBar, message: String, template: &str) { | 144 | fn 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 | ||
143 | enum Protocols { | 149 | enum 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)] |
158 | struct ErrorResponse { | 164 | struct 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 @@ | |||
1 | use crate::{error::CliError, default_headers, format_url, Protocols}; | 1 | use crate::{config::Config, default_headers, error::CliError, format_url, Protocols}; |
2 | 2 | ||
3 | pub async fn put(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { | 3 | pub 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 | ||
28 | pub async fn get(id: String) -> Result<(), CliError> { | 29 | pub 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 | ||
45 | pub async fn post(id: String, mac: String, broadcast_addr: String, ip: String) -> Result<(), CliError> { | 44 | pub 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 @@ | |||
1 | use futures_util::{StreamExt, SinkExt}; | 1 | use futures_util::{SinkExt, StreamExt}; |
2 | use indicatif::{MultiProgress, ProgressBar}; | 2 | use indicatif::{MultiProgress, ProgressBar}; |
3 | use reqwest::StatusCode; | 3 | use reqwest::StatusCode; |
4 | use serde::Deserialize; | 4 | use serde::Deserialize; |
5 | use tokio_tungstenite::{connect_async, tungstenite::Message}; | 5 | use tokio_tungstenite::{connect_async, tungstenite::Message}; |
6 | 6 | ||
7 | use 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}; | 7 | use crate::{ |
8 | 8 | add_pb, config::Config, default_headers, error::CliError, finish_pb, format_url, ErrorResponse, | |
9 | pub 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 | ||
13 | pub 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 | ||
62 | async fn status_socket(uuid: String, pb: &MultiProgress, overview: &ProgressBar, id: String) -> Result<bool, CliError> { | 71 | async 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 | ||
109 | fn get_eta(msg: String, uuid: String) -> Result<u64, CliError> { | 122 | fn 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 | ||
132 | enum Verified { | 149 | enum Verified { |
133 | ResponseType(ResponseType), | 150 | ResponseType(ResponseType), |
134 | WrongUuid | 151 | WrongUuid, |
135 | } | 152 | } |
136 | 153 | ||
137 | enum ResponseType { | 154 | enum ResponseType { |