summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.sqlx/query-566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8.json49
-rw-r--r--Cargo.lock341
-rw-r--r--Cargo.toml8
-rw-r--r--src/db.rs11
-rw-r--r--src/error.rs3
-rw-r--r--src/main.rs89
-rw-r--r--src/routes.rs2
-rw-r--r--src/routes/device.rs91
-rw-r--r--src/routes/start.rs16
9 files changed, 495 insertions, 115 deletions
diff --git a/.sqlx/query-566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8.json b/.sqlx/query-566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8.json
new file mode 100644
index 0000000..735c3bb
--- /dev/null
+++ b/.sqlx/query-566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8.json
@@ -0,0 +1,49 @@
1{
2 "db_name": "PostgreSQL",
3 "query": "\n INSERT INTO devices (id, mac, broadcast_addr, ip)\n VALUES ($1, $2, $3, $4)\n RETURNING id, mac, broadcast_addr, ip, times;\n ",
4 "describe": {
5 "columns": [
6 {
7 "ordinal": 0,
8 "name": "id",
9 "type_info": "Varchar"
10 },
11 {
12 "ordinal": 1,
13 "name": "mac",
14 "type_info": "Macaddr"
15 },
16 {
17 "ordinal": 2,
18 "name": "broadcast_addr",
19 "type_info": "Varchar"
20 },
21 {
22 "ordinal": 3,
23 "name": "ip",
24 "type_info": "Inet"
25 },
26 {
27 "ordinal": 4,
28 "name": "times",
29 "type_info": "Int8Array"
30 }
31 ],
32 "parameters": {
33 "Left": [
34 "Varchar",
35 "Macaddr",
36 "Varchar",
37 "Inet"
38 ]
39 },
40 "nullable": [
41 false,
42 false,
43 false,
44 false,
45 true
46 ]
47 },
48 "hash": "566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8"
49}
diff --git a/Cargo.lock b/Cargo.lock
index 4faf4b8..189fae3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
19 19
20[[package]] 20[[package]]
21name = "ahash" 21name = "ahash"
22version = "0.8.10" 22version = "0.8.11"
23source = "registry+https://github.com/rust-lang/crates.io-index" 23source = "registry+https://github.com/rust-lang/crates.io-index"
24checksum = "8b79b82693f705137f8fb9b37871d99e4f9a7df12b917eed79c3d3954830a60b" 24checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011"
25dependencies = [ 25dependencies = [
26 "cfg-if", 26 "cfg-if",
27 "getrandom", 27 "getrandom",
@@ -53,7 +53,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9"
53dependencies = [ 53dependencies = [
54 "proc-macro2", 54 "proc-macro2",
55 "quote", 55 "quote",
56 "syn 2.0.51", 56 "syn 2.0.52",
57] 57]
58 58
59[[package]] 59[[package]]
@@ -67,11 +67,11 @@ dependencies = [
67 67
68[[package]] 68[[package]]
69name = "atomic-write-file" 69name = "atomic-write-file"
70version = "0.1.2" 70version = "0.1.3"
71source = "registry+https://github.com/rust-lang/crates.io-index" 71source = "registry+https://github.com/rust-lang/crates.io-index"
72checksum = "edcdbedc2236483ab103a53415653d6b4442ea6141baf1ffa85df29635e88436" 72checksum = "a8204db279bf648d64fe845bd8840f78b39c8132ed4d6a4194c3b10d4b4cfb0b"
73dependencies = [ 73dependencies = [
74 "nix 0.27.1", 74 "nix 0.28.0",
75 "rand", 75 "rand",
76] 76]
77 77
@@ -148,7 +148,7 @@ dependencies = [
148 "heck", 148 "heck",
149 "proc-macro2", 149 "proc-macro2",
150 "quote", 150 "quote",
151 "syn 2.0.51", 151 "syn 2.0.52",
152] 152]
153 153
154[[package]] 154[[package]]
@@ -216,9 +216,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
216 216
217[[package]] 217[[package]]
218name = "cc" 218name = "cc"
219version = "1.0.88" 219version = "1.0.89"
220source = "registry+https://github.com/rust-lang/crates.io-index" 220source = "registry+https://github.com/rust-lang/crates.io-index"
221checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc" 221checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723"
222 222
223[[package]] 223[[package]]
224name = "cfg-if" 224name = "cfg-if"
@@ -227,6 +227,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
227checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 227checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
228 228
229[[package]] 229[[package]]
230name = "cfg_aliases"
231version = "0.1.1"
232source = "registry+https://github.com/rust-lang/crates.io-index"
233checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
234
235[[package]]
230name = "color-eyre" 236name = "color-eyre"
231version = "0.6.2" 237version = "0.6.2"
232source = "registry+https://github.com/rust-lang/crates.io-index" 238source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -281,9 +287,9 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
281 287
282[[package]] 288[[package]]
283name = "const-random" 289name = "const-random"
284version = "0.1.17" 290version = "0.1.18"
285source = "registry+https://github.com/rust-lang/crates.io-index" 291source = "registry+https://github.com/rust-lang/crates.io-index"
286checksum = "5aaf16c9c2c612020bcfd042e170f6e32de9b9d75adb5277cdbbd2e2c8c8299a" 292checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359"
287dependencies = [ 293dependencies = [
288 "const-random-macro", 294 "const-random-macro",
289] 295]
@@ -333,6 +339,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
333checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" 339checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
334 340
335[[package]] 341[[package]]
342name = "crc32fast"
343version = "1.4.0"
344source = "registry+https://github.com/rust-lang/crates.io-index"
345checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa"
346dependencies = [
347 "cfg-if",
348]
349
350[[package]]
336name = "crossbeam-channel" 351name = "crossbeam-channel"
337version = "0.5.12" 352version = "0.5.12"
338source = "registry+https://github.com/rust-lang/crates.io-index" 353source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -503,6 +518,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
503checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" 518checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6"
504 519
505[[package]] 520[[package]]
521name = "flate2"
522version = "1.0.28"
523source = "registry+https://github.com/rust-lang/crates.io-index"
524checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e"
525dependencies = [
526 "crc32fast",
527 "miniz_oxide",
528]
529
530[[package]]
506name = "flume" 531name = "flume"
507version = "0.11.0" 532version = "0.11.0"
508source = "registry+https://github.com/rust-lang/crates.io-index" 533source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -688,9 +713,9 @@ dependencies = [
688 713
689[[package]] 714[[package]]
690name = "hermit-abi" 715name = "hermit-abi"
691version = "0.3.8" 716version = "0.3.9"
692source = "registry+https://github.com/rust-lang/crates.io-index" 717source = "registry+https://github.com/rust-lang/crates.io-index"
693checksum = "379dada1584ad501b383485dd706b8afb7a70fcbc7f4da7d780638a5a6124a60" 718checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
694 719
695[[package]] 720[[package]]
696name = "hex" 721name = "hex"
@@ -727,9 +752,9 @@ dependencies = [
727 752
728[[package]] 753[[package]]
729name = "http" 754name = "http"
730version = "1.0.0" 755version = "1.1.0"
731source = "registry+https://github.com/rust-lang/crates.io-index" 756source = "registry+https://github.com/rust-lang/crates.io-index"
732checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" 757checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258"
733dependencies = [ 758dependencies = [
734 "bytes", 759 "bytes",
735 "fnv", 760 "fnv",
@@ -825,12 +850,13 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
825 850
826[[package]] 851[[package]]
827name = "indexmap" 852name = "indexmap"
828version = "2.2.3" 853version = "2.2.5"
829source = "registry+https://github.com/rust-lang/crates.io-index" 854source = "registry+https://github.com/rust-lang/crates.io-index"
830checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" 855checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4"
831dependencies = [ 856dependencies = [
832 "equivalent", 857 "equivalent",
833 "hashbrown 0.14.3", 858 "hashbrown 0.14.3",
859 "serde",
834] 860]
835 861
836[[package]] 862[[package]]
@@ -924,9 +950,9 @@ dependencies = [
924 950
925[[package]] 951[[package]]
926name = "log" 952name = "log"
927version = "0.4.20" 953version = "0.4.21"
928source = "registry+https://github.com/rust-lang/crates.io-index" 954source = "registry+https://github.com/rust-lang/crates.io-index"
929checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" 955checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
930 956
931[[package]] 957[[package]]
932name = "mac_address" 958name = "mac_address"
@@ -986,6 +1012,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
986checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" 1012checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
987 1013
988[[package]] 1014[[package]]
1015name = "mime_guess"
1016version = "2.0.4"
1017source = "registry+https://github.com/rust-lang/crates.io-index"
1018checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
1019dependencies = [
1020 "mime",
1021 "unicase",
1022]
1023
1024[[package]]
989name = "minimal-lexical" 1025name = "minimal-lexical"
990version = "0.2.1" 1026version = "0.2.1"
991source = "registry+https://github.com/rust-lang/crates.io-index" 1027source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1002,9 +1038,9 @@ dependencies = [
1002 1038
1003[[package]] 1039[[package]]
1004name = "mio" 1040name = "mio"
1005version = "0.8.10" 1041version = "0.8.11"
1006source = "registry+https://github.com/rust-lang/crates.io-index" 1042source = "registry+https://github.com/rust-lang/crates.io-index"
1007checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" 1043checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
1008dependencies = [ 1044dependencies = [
1009 "libc", 1045 "libc",
1010 "wasi", 1046 "wasi",
@@ -1026,12 +1062,13 @@ dependencies = [
1026 1062
1027[[package]] 1063[[package]]
1028name = "nix" 1064name = "nix"
1029version = "0.27.1" 1065version = "0.28.0"
1030source = "registry+https://github.com/rust-lang/crates.io-index" 1066source = "registry+https://github.com/rust-lang/crates.io-index"
1031checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" 1067checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4"
1032dependencies = [ 1068dependencies = [
1033 "bitflags 2.4.2", 1069 "bitflags 2.4.2",
1034 "cfg-if", 1070 "cfg-if",
1071 "cfg_aliases",
1035 "libc", 1072 "libc",
1036] 1073]
1037 1074
@@ -1222,9 +1259,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
1222 1259
1223[[package]] 1260[[package]]
1224name = "pest" 1261name = "pest"
1225version = "2.7.7" 1262version = "2.7.8"
1226source = "registry+https://github.com/rust-lang/crates.io-index" 1263source = "registry+https://github.com/rust-lang/crates.io-index"
1227checksum = "219c0dcc30b6a27553f9cc242972b67f75b60eb0db71f0b5462f38b058c41546" 1264checksum = "56f8023d0fb78c8e03784ea1c7f3fa36e68a723138990b8d5a47d916b651e7a8"
1228dependencies = [ 1265dependencies = [
1229 "memchr", 1266 "memchr",
1230 "thiserror", 1267 "thiserror",
@@ -1233,9 +1270,9 @@ dependencies = [
1233 1270
1234[[package]] 1271[[package]]
1235name = "pest_derive" 1272name = "pest_derive"
1236version = "2.7.7" 1273version = "2.7.8"
1237source = "registry+https://github.com/rust-lang/crates.io-index" 1274source = "registry+https://github.com/rust-lang/crates.io-index"
1238checksum = "22e1288dbd7786462961e69bfd4df7848c1e37e8b74303dbdab82c3a9cdd2809" 1275checksum = "b0d24f72393fd16ab6ac5738bc33cdb6a9aa73f8b902e8fe29cf4e67d7dd1026"
1239dependencies = [ 1276dependencies = [
1240 "pest", 1277 "pest",
1241 "pest_generator", 1278 "pest_generator",
@@ -1243,22 +1280,22 @@ dependencies = [
1243 1280
1244[[package]] 1281[[package]]
1245name = "pest_generator" 1282name = "pest_generator"
1246version = "2.7.7" 1283version = "2.7.8"
1247source = "registry+https://github.com/rust-lang/crates.io-index" 1284source = "registry+https://github.com/rust-lang/crates.io-index"
1248checksum = "1381c29a877c6d34b8c176e734f35d7f7f5b3adaefe940cb4d1bb7af94678e2e" 1285checksum = "fdc17e2a6c7d0a492f0158d7a4bd66cc17280308bbaff78d5bef566dca35ab80"
1249dependencies = [ 1286dependencies = [
1250 "pest", 1287 "pest",
1251 "pest_meta", 1288 "pest_meta",
1252 "proc-macro2", 1289 "proc-macro2",
1253 "quote", 1290 "quote",
1254 "syn 2.0.51", 1291 "syn 2.0.52",
1255] 1292]
1256 1293
1257[[package]] 1294[[package]]
1258name = "pest_meta" 1295name = "pest_meta"
1259version = "2.7.7" 1296version = "2.7.8"
1260source = "registry+https://github.com/rust-lang/crates.io-index" 1297source = "registry+https://github.com/rust-lang/crates.io-index"
1261checksum = "d0934d6907f148c22a3acbda520c7eed243ad7487a30f51f6ce52b58b7077a8a" 1298checksum = "934cd7631c050f4674352a6e835d5f6711ffbfb9345c2fc0107155ac495ae293"
1262dependencies = [ 1299dependencies = [
1263 "once_cell", 1300 "once_cell",
1264 "pest", 1301 "pest",
@@ -1282,7 +1319,7 @@ checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690"
1282dependencies = [ 1319dependencies = [
1283 "proc-macro2", 1320 "proc-macro2",
1284 "quote", 1321 "quote",
1285 "syn 2.0.51", 1322 "syn 2.0.52",
1286] 1323]
1287 1324
1288[[package]] 1325[[package]]
@@ -1379,6 +1416,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1379checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" 1416checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
1380 1417
1381[[package]] 1418[[package]]
1419name = "proc-macro-error"
1420version = "1.0.4"
1421source = "registry+https://github.com/rust-lang/crates.io-index"
1422checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
1423dependencies = [
1424 "proc-macro-error-attr",
1425 "proc-macro2",
1426 "quote",
1427 "syn 1.0.109",
1428 "version_check",
1429]
1430
1431[[package]]
1432name = "proc-macro-error-attr"
1433version = "1.0.4"
1434source = "registry+https://github.com/rust-lang/crates.io-index"
1435checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
1436dependencies = [
1437 "proc-macro2",
1438 "quote",
1439 "version_check",
1440]
1441
1442[[package]]
1382name = "proc-macro2" 1443name = "proc-macro2"
1383version = "1.0.78" 1444version = "1.0.78"
1384source = "registry+https://github.com/rust-lang/crates.io-index" 1445source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1443,7 +1504,7 @@ checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
1443dependencies = [ 1504dependencies = [
1444 "aho-corasick", 1505 "aho-corasick",
1445 "memchr", 1506 "memchr",
1446 "regex-automata 0.4.5", 1507 "regex-automata 0.4.6",
1447 "regex-syntax 0.8.2", 1508 "regex-syntax 0.8.2",
1448] 1509]
1449 1510
@@ -1458,9 +1519,9 @@ dependencies = [
1458 1519
1459[[package]] 1520[[package]]
1460name = "regex-automata" 1521name = "regex-automata"
1461version = "0.4.5" 1522version = "0.4.6"
1462source = "registry+https://github.com/rust-lang/crates.io-index" 1523source = "registry+https://github.com/rust-lang/crates.io-index"
1463checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" 1524checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
1464dependencies = [ 1525dependencies = [
1465 "aho-corasick", 1526 "aho-corasick",
1466 "memchr", 1527 "memchr",
@@ -1512,6 +1573,40 @@ dependencies = [
1512] 1573]
1513 1574
1514[[package]] 1575[[package]]
1576name = "rust-embed"
1577version = "8.3.0"
1578source = "registry+https://github.com/rust-lang/crates.io-index"
1579checksum = "fb78f46d0066053d16d4ca7b898e9343bc3530f71c61d5ad84cd404ada068745"
1580dependencies = [
1581 "rust-embed-impl",
1582 "rust-embed-utils",
1583 "walkdir",
1584]
1585
1586[[package]]
1587name = "rust-embed-impl"
1588version = "8.3.0"
1589source = "registry+https://github.com/rust-lang/crates.io-index"
1590checksum = "b91ac2a3c6c0520a3fb3dd89321177c3c692937c4eb21893378219da10c44fc8"
1591dependencies = [
1592 "proc-macro2",
1593 "quote",
1594 "rust-embed-utils",
1595 "syn 2.0.52",
1596 "walkdir",
1597]
1598
1599[[package]]
1600name = "rust-embed-utils"
1601version = "8.3.0"
1602source = "registry+https://github.com/rust-lang/crates.io-index"
1603checksum = "86f69089032567ffff4eada41c573fc43ff466c7db7c5688b2e7969584345581"
1604dependencies = [
1605 "sha2",
1606 "walkdir",
1607]
1608
1609[[package]]
1515name = "rust-ini" 1610name = "rust-ini"
1516version = "0.19.0" 1611version = "0.19.0"
1517source = "registry+https://github.com/rust-lang/crates.io-index" 1612source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1553,6 +1648,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1553checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" 1648checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
1554 1649
1555[[package]] 1650[[package]]
1651name = "same-file"
1652version = "1.0.6"
1653source = "registry+https://github.com/rust-lang/crates.io-index"
1654checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
1655dependencies = [
1656 "winapi-util",
1657]
1658
1659[[package]]
1556name = "scopeguard" 1660name = "scopeguard"
1557version = "1.2.0" 1661version = "1.2.0"
1558source = "registry+https://github.com/rust-lang/crates.io-index" 1662source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1575,7 +1679,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
1575dependencies = [ 1679dependencies = [
1576 "proc-macro2", 1680 "proc-macro2",
1577 "quote", 1681 "quote",
1578 "syn 2.0.51", 1682 "syn 2.0.52",
1579] 1683]
1580 1684
1581[[package]] 1685[[package]]
@@ -1969,9 +2073,9 @@ dependencies = [
1969 2073
1970[[package]] 2074[[package]]
1971name = "syn" 2075name = "syn"
1972version = "2.0.51" 2076version = "2.0.52"
1973source = "registry+https://github.com/rust-lang/crates.io-index" 2077source = "registry+https://github.com/rust-lang/crates.io-index"
1974checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c" 2078checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07"
1975dependencies = [ 2079dependencies = [
1976 "proc-macro2", 2080 "proc-macro2",
1977 "quote", 2081 "quote",
@@ -2013,7 +2117,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
2013dependencies = [ 2117dependencies = [
2014 "proc-macro2", 2118 "proc-macro2",
2015 "quote", 2119 "quote",
2016 "syn 2.0.51", 2120 "syn 2.0.52",
2017] 2121]
2018 2122
2019[[package]] 2123[[package]]
@@ -2108,7 +2212,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
2108dependencies = [ 2212dependencies = [
2109 "proc-macro2", 2213 "proc-macro2",
2110 "quote", 2214 "quote",
2111 "syn 2.0.51", 2215 "syn 2.0.52",
2112] 2216]
2113 2217
2114[[package]] 2218[[package]]
@@ -2242,7 +2346,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
2242dependencies = [ 2346dependencies = [
2243 "proc-macro2", 2347 "proc-macro2",
2244 "quote", 2348 "quote",
2245 "syn 2.0.51", 2349 "syn 2.0.52",
2246] 2350]
2247 2351
2248[[package]] 2352[[package]]
@@ -2327,6 +2431,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2327checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" 2431checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
2328 2432
2329[[package]] 2433[[package]]
2434name = "unicase"
2435version = "2.7.0"
2436source = "registry+https://github.com/rust-lang/crates.io-index"
2437checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89"
2438dependencies = [
2439 "version_check",
2440]
2441
2442[[package]]
2330name = "unicode-bidi" 2443name = "unicode-bidi"
2331version = "0.3.15" 2444version = "0.3.15"
2332source = "registry+https://github.com/rust-lang/crates.io-index" 2445source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2383,6 +2496,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2383checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" 2496checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
2384 2497
2385[[package]] 2498[[package]]
2499name = "utoipa"
2500version = "4.2.0"
2501source = "registry+https://github.com/rust-lang/crates.io-index"
2502checksum = "272ebdfbc99111033031d2f10e018836056e4d2c8e2acda76450ec7974269fa7"
2503dependencies = [
2504 "indexmap",
2505 "serde",
2506 "serde_json",
2507 "utoipa-gen",
2508]
2509
2510[[package]]
2511name = "utoipa-gen"
2512version = "4.2.0"
2513source = "registry+https://github.com/rust-lang/crates.io-index"
2514checksum = "d3c9f4d08338c1bfa70dde39412a040a884c6f318b3d09aaaf3437a1e52027fc"
2515dependencies = [
2516 "proc-macro-error",
2517 "proc-macro2",
2518 "quote",
2519 "regex",
2520 "syn 2.0.52",
2521]
2522
2523[[package]]
2524name = "utoipa-swagger-ui"
2525version = "6.0.0"
2526source = "registry+https://github.com/rust-lang/crates.io-index"
2527checksum = "0b39868d43c011961e04b41623e050aedf2cc93652562ff7935ce0f819aaf2da"
2528dependencies = [
2529 "axum",
2530 "mime_guess",
2531 "regex",
2532 "rust-embed",
2533 "serde",
2534 "serde_json",
2535 "utoipa",
2536 "zip",
2537]
2538
2539[[package]]
2386name = "uuid" 2540name = "uuid"
2387version = "1.7.0" 2541version = "1.7.0"
2388source = "registry+https://github.com/rust-lang/crates.io-index" 2542source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2411,14 +2565,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2411checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 2565checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
2412 2566
2413[[package]] 2567[[package]]
2568name = "walkdir"
2569version = "2.5.0"
2570source = "registry+https://github.com/rust-lang/crates.io-index"
2571checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
2572dependencies = [
2573 "same-file",
2574 "winapi-util",
2575]
2576
2577[[package]]
2414name = "wasi" 2578name = "wasi"
2415version = "0.11.0+wasi-snapshot-preview1" 2579version = "0.11.0+wasi-snapshot-preview1"
2416source = "registry+https://github.com/rust-lang/crates.io-index" 2580source = "registry+https://github.com/rust-lang/crates.io-index"
2417checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 2581checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
2418 2582
2419[[package]] 2583[[package]]
2584name = "wasite"
2585version = "0.1.0"
2586source = "registry+https://github.com/rust-lang/crates.io-index"
2587checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"
2588
2589[[package]]
2420name = "webol" 2590name = "webol"
2421version = "0.3.2" 2591version = "0.3.3"
2422dependencies = [ 2592dependencies = [
2423 "axum", 2593 "axum",
2424 "axum-macros", 2594 "axum-macros",
@@ -2437,14 +2607,20 @@ dependencies = [
2437 "tracing", 2607 "tracing",
2438 "tracing-appender", 2608 "tracing-appender",
2439 "tracing-subscriber", 2609 "tracing-subscriber",
2610 "utoipa",
2611 "utoipa-swagger-ui",
2440 "uuid", 2612 "uuid",
2441] 2613]
2442 2614
2443[[package]] 2615[[package]]
2444name = "whoami" 2616name = "whoami"
2445version = "1.4.1" 2617version = "1.5.0"
2446source = "registry+https://github.com/rust-lang/crates.io-index" 2618source = "registry+https://github.com/rust-lang/crates.io-index"
2447checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" 2619checksum = "0fec781d48b41f8163426ed18e8fc2864c12937df9ce54c88ede7bd47270893e"
2620dependencies = [
2621 "redox_syscall",
2622 "wasite",
2623]
2448 2624
2449[[package]] 2625[[package]]
2450name = "winapi" 2626name = "winapi"
@@ -2463,6 +2639,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2463checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 2639checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
2464 2640
2465[[package]] 2641[[package]]
2642name = "winapi-util"
2643version = "0.1.6"
2644source = "registry+https://github.com/rust-lang/crates.io-index"
2645checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
2646dependencies = [
2647 "winapi",
2648]
2649
2650[[package]]
2466name = "winapi-x86_64-pc-windows-gnu" 2651name = "winapi-x86_64-pc-windows-gnu"
2467version = "0.4.0" 2652version = "0.4.0"
2468source = "registry+https://github.com/rust-lang/crates.io-index" 2653source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2483,7 +2668,7 @@ version = "0.52.0"
2483source = "registry+https://github.com/rust-lang/crates.io-index" 2668source = "registry+https://github.com/rust-lang/crates.io-index"
2484checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 2669checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
2485dependencies = [ 2670dependencies = [
2486 "windows-targets 0.52.3", 2671 "windows-targets 0.52.4",
2487] 2672]
2488 2673
2489[[package]] 2674[[package]]
@@ -2503,17 +2688,17 @@ dependencies = [
2503 2688
2504[[package]] 2689[[package]]
2505name = "windows-targets" 2690name = "windows-targets"
2506version = "0.52.3" 2691version = "0.52.4"
2507source = "registry+https://github.com/rust-lang/crates.io-index" 2692source = "registry+https://github.com/rust-lang/crates.io-index"
2508checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f" 2693checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b"
2509dependencies = [ 2694dependencies = [
2510 "windows_aarch64_gnullvm 0.52.3", 2695 "windows_aarch64_gnullvm 0.52.4",
2511 "windows_aarch64_msvc 0.52.3", 2696 "windows_aarch64_msvc 0.52.4",
2512 "windows_i686_gnu 0.52.3", 2697 "windows_i686_gnu 0.52.4",
2513 "windows_i686_msvc 0.52.3", 2698 "windows_i686_msvc 0.52.4",
2514 "windows_x86_64_gnu 0.52.3", 2699 "windows_x86_64_gnu 0.52.4",
2515 "windows_x86_64_gnullvm 0.52.3", 2700 "windows_x86_64_gnullvm 0.52.4",
2516 "windows_x86_64_msvc 0.52.3", 2701 "windows_x86_64_msvc 0.52.4",
2517] 2702]
2518 2703
2519[[package]] 2704[[package]]
@@ -2524,9 +2709,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
2524 2709
2525[[package]] 2710[[package]]
2526name = "windows_aarch64_gnullvm" 2711name = "windows_aarch64_gnullvm"
2527version = "0.52.3" 2712version = "0.52.4"
2528source = "registry+https://github.com/rust-lang/crates.io-index" 2713source = "registry+https://github.com/rust-lang/crates.io-index"
2529checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6" 2714checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9"
2530 2715
2531[[package]] 2716[[package]]
2532name = "windows_aarch64_msvc" 2717name = "windows_aarch64_msvc"
@@ -2536,9 +2721,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
2536 2721
2537[[package]] 2722[[package]]
2538name = "windows_aarch64_msvc" 2723name = "windows_aarch64_msvc"
2539version = "0.52.3" 2724version = "0.52.4"
2540source = "registry+https://github.com/rust-lang/crates.io-index" 2725source = "registry+https://github.com/rust-lang/crates.io-index"
2541checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f" 2726checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675"
2542 2727
2543[[package]] 2728[[package]]
2544name = "windows_i686_gnu" 2729name = "windows_i686_gnu"
@@ -2548,9 +2733,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
2548 2733
2549[[package]] 2734[[package]]
2550name = "windows_i686_gnu" 2735name = "windows_i686_gnu"
2551version = "0.52.3" 2736version = "0.52.4"
2552source = "registry+https://github.com/rust-lang/crates.io-index" 2737source = "registry+https://github.com/rust-lang/crates.io-index"
2553checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb" 2738checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3"
2554 2739
2555[[package]] 2740[[package]]
2556name = "windows_i686_msvc" 2741name = "windows_i686_msvc"
@@ -2560,9 +2745,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
2560 2745
2561[[package]] 2746[[package]]
2562name = "windows_i686_msvc" 2747name = "windows_i686_msvc"
2563version = "0.52.3" 2748version = "0.52.4"
2564source = "registry+https://github.com/rust-lang/crates.io-index" 2749source = "registry+https://github.com/rust-lang/crates.io-index"
2565checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58" 2750checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02"
2566 2751
2567[[package]] 2752[[package]]
2568name = "windows_x86_64_gnu" 2753name = "windows_x86_64_gnu"
@@ -2572,9 +2757,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
2572 2757
2573[[package]] 2758[[package]]
2574name = "windows_x86_64_gnu" 2759name = "windows_x86_64_gnu"
2575version = "0.52.3" 2760version = "0.52.4"
2576source = "registry+https://github.com/rust-lang/crates.io-index" 2761source = "registry+https://github.com/rust-lang/crates.io-index"
2577checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614" 2762checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03"
2578 2763
2579[[package]] 2764[[package]]
2580name = "windows_x86_64_gnullvm" 2765name = "windows_x86_64_gnullvm"
@@ -2584,9 +2769,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
2584 2769
2585[[package]] 2770[[package]]
2586name = "windows_x86_64_gnullvm" 2771name = "windows_x86_64_gnullvm"
2587version = "0.52.3" 2772version = "0.52.4"
2588source = "registry+https://github.com/rust-lang/crates.io-index" 2773source = "registry+https://github.com/rust-lang/crates.io-index"
2589checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c" 2774checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177"
2590 2775
2591[[package]] 2776[[package]]
2592name = "windows_x86_64_msvc" 2777name = "windows_x86_64_msvc"
@@ -2596,15 +2781,15 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
2596 2781
2597[[package]] 2782[[package]]
2598name = "windows_x86_64_msvc" 2783name = "windows_x86_64_msvc"
2599version = "0.52.3" 2784version = "0.52.4"
2600source = "registry+https://github.com/rust-lang/crates.io-index" 2785source = "registry+https://github.com/rust-lang/crates.io-index"
2601checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6" 2786checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
2602 2787
2603[[package]] 2788[[package]]
2604name = "winnow" 2789name = "winnow"
2605version = "0.6.3" 2790version = "0.6.5"
2606source = "registry+https://github.com/rust-lang/crates.io-index" 2791source = "registry+https://github.com/rust-lang/crates.io-index"
2607checksum = "44e19b97e00a4d3db3cdb9b53c8c5f87151b5689b82cc86c2848cbdcccb2689b" 2792checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8"
2608dependencies = [ 2793dependencies = [
2609 "memchr", 2794 "memchr",
2610] 2795]
@@ -2635,7 +2820,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
2635dependencies = [ 2820dependencies = [
2636 "proc-macro2", 2821 "proc-macro2",
2637 "quote", 2822 "quote",
2638 "syn 2.0.51", 2823 "syn 2.0.52",
2639] 2824]
2640 2825
2641[[package]] 2826[[package]]
@@ -2643,3 +2828,15 @@ name = "zeroize"
2643version = "1.7.0" 2828version = "1.7.0"
2644source = "registry+https://github.com/rust-lang/crates.io-index" 2829source = "registry+https://github.com/rust-lang/crates.io-index"
2645checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" 2830checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"
2831
2832[[package]]
2833name = "zip"
2834version = "0.6.6"
2835source = "registry+https://github.com/rust-lang/crates.io-index"
2836checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261"
2837dependencies = [
2838 "byteorder",
2839 "crc32fast",
2840 "crossbeam-utils",
2841 "flate2",
2842]
diff --git a/Cargo.toml b/Cargo.toml
index 8a86115..b0a8cd2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "webol" 2name = "webol"
3version = "0.3.2" 3version = "0.3.3"
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
@@ -21,6 +21,8 @@ uuid = { version = "1.6", features = ["v4", "fast-rng"] }
21dashmap = "5.5" 21dashmap = "5.5"
22color-eyre = "0.6" 22color-eyre = "0.6"
23thiserror = "1.0" 23thiserror = "1.0"
24ipnetwork = "0.20.0" 24ipnetwork = "0.20"
25mac_address = { version = "1.1.5", features = ["serde"] } 25mac_address = { version = "1.1", features = ["serde"] }
26tracing-appender = "0.2.3" 26tracing-appender = "0.2.3"
27utoipa = { version = "4.2", features = ["axum_extras"] }
28utoipa-swagger-ui = { version = "6.0", features = ["axum"] }
diff --git a/src/db.rs b/src/db.rs
index 47e907d..a2b2009 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -1,6 +1,7 @@
1use serde::Serialize; 1use serde::Serialize;
2use sqlx::{PgPool, postgres::PgPoolOptions, types::{ipnetwork::IpNetwork, mac_address::MacAddress}}; 2use sqlx::{PgPool, postgres::PgPoolOptions, types::{ipnetwork::IpNetwork, mac_address::MacAddress}};
3use tracing::{debug, info}; 3use tracing::{debug, info};
4use utoipa::ToSchema;
4 5
5#[derive(Serialize, Debug)] 6#[derive(Serialize, Debug)]
6pub struct Device { 7pub struct Device {
@@ -11,6 +12,16 @@ pub struct Device {
11 pub times: Option<Vec<i64>> 12 pub times: Option<Vec<i64>>
12} 13}
13 14
15#[derive(ToSchema)]
16#[schema(as = Device)]
17pub struct DeviceSchema {
18 pub id: String,
19 pub mac: String,
20 pub broadcast_addr: String,
21 pub ip: String,
22 pub times: Option<Vec<i64>>
23}
24
14pub async fn init_db_pool(db_url: &str) -> PgPool { 25pub async fn init_db_pool(db_url: &str) -> PgPool {
15 debug!("attempt to connect dbPool to '{}'", db_url); 26 debug!("attempt to connect dbPool to '{}'", db_url);
16 27
diff --git a/src/error.rs b/src/error.rs
index 513b51b..006fcdb 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -5,10 +5,11 @@ use axum::response::{IntoResponse, Response};
5use axum::Json; 5use axum::Json;
6use mac_address::MacParseError; 6use mac_address::MacParseError;
7use serde_json::json; 7use serde_json::json;
8use utoipa::ToSchema;
8use std::io; 9use std::io;
9use tracing::error; 10use tracing::error;
10 11
11#[derive(Debug, thiserror::Error)] 12#[derive(Debug, thiserror::Error, ToSchema)]
12pub enum Error { 13pub enum Error {
13 #[error("db: {source}")] 14 #[error("db: {source}")]
14 Db { 15 Db {
diff --git a/src/main.rs b/src/main.rs
index d17984f..8978e58 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,21 +1,29 @@
1use crate::config::Config; 1use crate::{
2use crate::db::init_db_pool; 2 config::Config,
3use crate::routes::device; 3 db::init_db_pool,
4use crate::routes::start::start; 4 routes::{device, start, status},
5use crate::routes::status::status; 5 services::ping::{BroadcastCommand, StatusMap},
6use crate::services::ping::StatusMap; 6};
7use axum::middleware::from_fn_with_state; 7use axum::{
8use axum::routing::{get, put}; 8 middleware::from_fn_with_state,
9use axum::{routing::post, Router}; 9 routing::{get, post},
10 Router,
11};
10use dashmap::DashMap; 12use dashmap::DashMap;
11use services::ping::BroadcastCommand;
12use sqlx::PgPool; 13use sqlx::PgPool;
13use std::env; 14use std::{env, sync::Arc};
14use std::sync::Arc;
15use tokio::sync::broadcast::{channel, Sender}; 15use tokio::sync::broadcast::{channel, Sender};
16use tracing::{info, level_filters::LevelFilter}; 16use tracing::{info, level_filters::LevelFilter};
17use tracing_subscriber::fmt::time::UtcTime; 17use tracing_subscriber::{
18use tracing_subscriber::{fmt, prelude::*, EnvFilter}; 18 fmt::{self, time::UtcTime},
19 prelude::*,
20 EnvFilter,
21};
22use utoipa::{
23 openapi::security::{ApiKey, ApiKeyValue, SecurityScheme},
24 Modify, OpenApi,
25};
26use utoipa_swagger_ui::SwaggerUi;
19 27
20mod config; 28mod config;
21mod db; 29mod db;
@@ -25,7 +33,47 @@ mod routes;
25mod services; 33mod services;
26mod wol; 34mod wol;
27 35
36#[derive(OpenApi)]
37#[openapi(
38 paths(
39 start::start,
40 device::get,
41 device::get_path,
42 device::post,
43 device::put,
44 ),
45 components(
46 schemas(
47 start::Payload,
48 start::Response,
49 device::PutDevicePayload,
50 device::GetDevicePayload,
51 device::PostDevicePayload,
52 db::DeviceSchema,
53 )
54 ),
55 modifiers(&SecurityAddon),
56 tags(
57 (name = "Webol", description = "Webol API")
58 )
59)]
60struct ApiDoc;
61
62struct SecurityAddon;
63
64impl Modify for SecurityAddon {
65 fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) {
66 if let Some(components) = openapi.components.as_mut() {
67 components.add_security_scheme(
68 "api_key",
69 SecurityScheme::ApiKey(ApiKey::Header(ApiKeyValue::new("Authorization"))),
70 );
71 }
72 }
73}
74
28#[tokio::main] 75#[tokio::main]
76#[allow(deprecated)]
29async fn main() -> color_eyre::eyre::Result<()> { 77async fn main() -> color_eyre::eyre::Result<()> {
30 color_eyre::install()?; 78 color_eyre::install()?;
31 79
@@ -67,12 +115,15 @@ async fn main() -> color_eyre::eyre::Result<()> {
67 }; 115 };
68 116
69 let app = Router::new() 117 let app = Router::new()
70 .route("/start", post(start)) 118 .route("/start", post(start::start))
71 .route("/device", get(device::get)) 119 .route(
72 .route("/device", put(device::put)) 120 "/device",
73 .route("/device", post(device::post)) 121 post(device::post).get(device::get).put(device::put),
74 .route("/status", get(status)) 122 )
123 .route("/device/:id", get(device::get_path))
124 .route("/status", get(status::status))
75 .route_layer(from_fn_with_state(shared_state.clone(), extractors::auth)) 125 .route_layer(from_fn_with_state(shared_state.clone(), extractors::auth))
126 .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi()))
76 .with_state(Arc::new(shared_state)); 127 .with_state(Arc::new(shared_state));
77 128
78 let addr = config.serveraddr; 129 let addr = config.serveraddr;
diff --git a/src/routes.rs b/src/routes.rs
index d5ab0d6..a72f27b 100644
--- a/src/routes.rs
+++ b/src/routes.rs
@@ -1,3 +1,3 @@
1pub mod start; 1pub mod start;
2pub mod device; 2pub mod device;
3pub mod status; \ No newline at end of file 3pub mod status;
diff --git a/src/routes/device.rs b/src/routes/device.rs
index d39d98e..d01d9f0 100644
--- a/src/routes/device.rs
+++ b/src/routes/device.rs
@@ -1,14 +1,25 @@
1use crate::db::Device; 1use crate::db::Device;
2use crate::error::Error; 2use crate::error::Error;
3use axum::extract::State; 3use axum::extract::{Path, State};
4use axum::Json; 4use axum::Json;
5use mac_address::MacAddress; 5use mac_address::MacAddress;
6use serde::{Deserialize, Serialize}; 6use serde::Deserialize;
7use serde_json::{json, Value}; 7use serde_json::{json, Value};
8use sqlx::types::ipnetwork::IpNetwork; 8use sqlx::types::ipnetwork::IpNetwork;
9use std::{sync::Arc, str::FromStr}; 9use std::{str::FromStr, sync::Arc};
10use tracing::{debug, info}; 10use tracing::{debug, info};
11use utoipa::ToSchema;
11 12
13#[utoipa::path(
14 get,
15 path = "/device",
16 request_body = GetDevicePayload,
17 responses(
18 (status = 200, description = "Get `Device` information", body = [Device])
19 ),
20 security(("api_key" = []))
21)]
22#[deprecated]
12pub async fn get( 23pub async fn get(
13 State(state): State<Arc<crate::AppState>>, 24 State(state): State<Arc<crate::AppState>>,
14 Json(payload): Json<GetDevicePayload>, 25 Json(payload): Json<GetDevicePayload>,
@@ -31,11 +42,53 @@ pub async fn get(
31 Ok(Json(json!(device))) 42 Ok(Json(json!(device)))
32} 43}
33 44
34#[derive(Deserialize)] 45#[utoipa::path(
46 get,
47 path = "/device/{id}",
48 responses(
49 (status = 200, description = "Get `Device` information", body = [Device])
50 ),
51 params(
52 ("id" = String, Path, description = "Device id")
53 ),
54 security(("api_key" = []))
55)]
56pub async fn get_path(
57 State(state): State<Arc<crate::AppState>>,
58 Path(path): Path<String>,
59) -> Result<Json<Value>, Error> {
60 info!("get device from path {}", path);
61 let device = sqlx::query_as!(
62 Device,
63 r#"
64 SELECT id, mac, broadcast_addr, ip, times
65 FROM devices
66 WHERE id = $1;
67 "#,
68 path
69 )
70 .fetch_one(&state.db)
71 .await?;
72
73 debug!("got device {:?}", device);
74
75 Ok(Json(json!(device)))
76}
77
78#[derive(Deserialize, ToSchema)]
35pub struct GetDevicePayload { 79pub struct GetDevicePayload {
36 id: String, 80 id: String,
37} 81}
38 82
83#[utoipa::path(
84 put,
85 path = "/device",
86 request_body = PutDevicePayload,
87 responses(
88 (status = 200, description = "List matching todos by query", body = [DeviceSchema])
89 ),
90 security(("api_key" = []))
91)]
39pub async fn put( 92pub async fn put(
40 State(state): State<Arc<crate::AppState>>, 93 State(state): State<Arc<crate::AppState>>,
41 Json(payload): Json<PutDevicePayload>, 94 Json(payload): Json<PutDevicePayload>,
@@ -44,26 +97,28 @@ pub async fn put(
44 "add device {} ({}, {}, {})", 97 "add device {} ({}, {}, {})",
45 payload.id, payload.mac, payload.broadcast_addr, payload.ip 98 payload.id, payload.mac, payload.broadcast_addr, payload.ip
46 ); 99 );
47 100
48 let ip = IpNetwork::from_str(&payload.ip)?; 101 let ip = IpNetwork::from_str(&payload.ip)?;
49 let mac = MacAddress::from_str(&payload.mac)?; 102 let mac = MacAddress::from_str(&payload.mac)?;
50 sqlx::query!( 103 let device = sqlx::query_as!(
104 Device,
51 r#" 105 r#"
52 INSERT INTO devices (id, mac, broadcast_addr, ip) 106 INSERT INTO devices (id, mac, broadcast_addr, ip)
53 VALUES ($1, $2, $3, $4); 107 VALUES ($1, $2, $3, $4)
108 RETURNING id, mac, broadcast_addr, ip, times;
54 "#, 109 "#,
55 payload.id, 110 payload.id,
56 mac, 111 mac,
57 payload.broadcast_addr, 112 payload.broadcast_addr,
58 ip 113 ip
59 ) 114 )
60 .execute(&state.db) 115 .fetch_one(&state.db)
61 .await?; 116 .await?;
62 117
63 Ok(Json(json!(PutDeviceResponse { success: true }))) 118 Ok(Json(json!(device)))
64} 119}
65 120
66#[derive(Deserialize)] 121#[derive(Deserialize, ToSchema)]
67pub struct PutDevicePayload { 122pub struct PutDevicePayload {
68 id: String, 123 id: String,
69 mac: String, 124 mac: String,
@@ -71,11 +126,15 @@ pub struct PutDevicePayload {
71 ip: String, 126 ip: String,
72} 127}
73 128
74#[derive(Serialize)] 129#[utoipa::path(
75pub struct PutDeviceResponse { 130 post,
76 success: bool, 131 path = "/device",
77} 132 request_body = PostDevicePayload,
78 133 responses(
134 (status = 200, description = "List matching todos by query", body = [DeviceSchema])
135 ),
136 security(("api_key" = []))
137)]
79pub async fn post( 138pub async fn post(
80 State(state): State<Arc<crate::AppState>>, 139 State(state): State<Arc<crate::AppState>>,
81 Json(payload): Json<PostDevicePayload>, 140 Json(payload): Json<PostDevicePayload>,
@@ -104,7 +163,7 @@ pub async fn post(
104 Ok(Json(json!(device))) 163 Ok(Json(json!(device)))
105} 164}
106 165
107#[derive(Deserialize)] 166#[derive(Deserialize, ToSchema)]
108pub struct PostDevicePayload { 167pub struct PostDevicePayload {
109 id: String, 168 id: String,
110 mac: String, 169 mac: String,
diff --git a/src/routes/start.rs b/src/routes/start.rs
index d4c0802..ef6e8f2 100644
--- a/src/routes/start.rs
+++ b/src/routes/start.rs
@@ -6,10 +6,20 @@ use axum::extract::State;
6use axum::Json; 6use axum::Json;
7use serde::{Deserialize, Serialize}; 7use serde::{Deserialize, Serialize};
8use serde_json::{json, Value}; 8use serde_json::{json, Value};
9use utoipa::ToSchema;
9use std::sync::Arc; 10use std::sync::Arc;
10use tracing::{debug, info}; 11use tracing::{debug, info};
11use uuid::Uuid; 12use uuid::Uuid;
12 13
14#[utoipa::path(
15 post,
16 path = "/start",
17 request_body = Payload,
18 responses(
19 (status = 200, description = "List matching todos by query", body = [Response])
20 ),
21 security(("api_key" = []))
22)]
13pub async fn start( 23pub async fn start(
14 State(state): State<Arc<crate::AppState>>, 24 State(state): State<Arc<crate::AppState>>,
15 Json(payload): Json<Payload>, 25 Json(payload): Json<Payload>,
@@ -88,14 +98,14 @@ fn setup_ping(state: Arc<crate::AppState>, device: Device) -> String {
88 uuid_ret 98 uuid_ret
89} 99}
90 100
91#[derive(Deserialize)] 101#[derive(Deserialize, ToSchema)]
92pub struct Payload { 102pub struct Payload {
93 id: String, 103 id: String,
94 ping: Option<bool>, 104 ping: Option<bool>,
95} 105}
96 106
97#[derive(Serialize)] 107#[derive(Serialize, ToSchema)]
98struct Response { 108pub struct Response {
99 id: String, 109 id: String,
100 boot: bool, 110 boot: bool,
101 uuid: Option<String>, 111 uuid: Option<String>,