summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock144
-rw-r--r--docker-compose.yml3
-rw-r--r--migrations/20231009123228_devices.sql4
-rw-r--r--src/auth.rs3
-rw-r--r--src/db.rs26
-rw-r--r--src/error.rs1
-rw-r--r--src/main.rs25
7 files changed, 116 insertions, 90 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7f5521b..09f5744 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -42,9 +42,9 @@ dependencies = [
42 42
43[[package]] 43[[package]]
44name = "aho-corasick" 44name = "aho-corasick"
45version = "1.1.1" 45version = "1.1.2"
46source = "registry+https://github.com/rust-lang/crates.io-index" 46source = "registry+https://github.com/rust-lang/crates.io-index"
47checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" 47checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
48dependencies = [ 48dependencies = [
49 "memchr", 49 "memchr",
50] 50]
@@ -57,9 +57,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
57 57
58[[package]] 58[[package]]
59name = "async-trait" 59name = "async-trait"
60version = "0.1.73" 60version = "0.1.74"
61source = "registry+https://github.com/rust-lang/crates.io-index" 61source = "registry+https://github.com/rust-lang/crates.io-index"
62checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" 62checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9"
63dependencies = [ 63dependencies = [
64 "proc-macro2", 64 "proc-macro2",
65 "quote", 65 "quote",
@@ -172,9 +172,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
172 172
173[[package]] 173[[package]]
174name = "bitflags" 174name = "bitflags"
175version = "2.4.0" 175version = "2.4.1"
176source = "registry+https://github.com/rust-lang/crates.io-index" 176source = "registry+https://github.com/rust-lang/crates.io-index"
177checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" 177checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
178dependencies = [ 178dependencies = [
179 "serde", 179 "serde",
180] 180]
@@ -242,9 +242,9 @@ checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f"
242 242
243[[package]] 243[[package]]
244name = "cpufeatures" 244name = "cpufeatures"
245version = "0.2.9" 245version = "0.2.10"
246source = "registry+https://github.com/rust-lang/crates.io-index" 246source = "registry+https://github.com/rust-lang/crates.io-index"
247checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" 247checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4"
248dependencies = [ 248dependencies = [
249 "libc", 249 "libc",
250] 250]
@@ -306,9 +306,12 @@ dependencies = [
306 306
307[[package]] 307[[package]]
308name = "deranged" 308name = "deranged"
309version = "0.3.8" 309version = "0.3.9"
310source = "registry+https://github.com/rust-lang/crates.io-index" 310source = "registry+https://github.com/rust-lang/crates.io-index"
311checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" 311checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3"
312dependencies = [
313 "powerfmt",
314]
312 315
313[[package]] 316[[package]]
314name = "digest" 317name = "digest"
@@ -524,9 +527,9 @@ dependencies = [
524 527
525[[package]] 528[[package]]
526name = "hashbrown" 529name = "hashbrown"
527version = "0.14.1" 530version = "0.14.2"
528source = "registry+https://github.com/rust-lang/crates.io-index" 531source = "registry+https://github.com/rust-lang/crates.io-index"
529checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" 532checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
530dependencies = [ 533dependencies = [
531 "ahash 0.8.3", 534 "ahash 0.8.3",
532 "allocator-api2", 535 "allocator-api2",
@@ -538,7 +541,7 @@ version = "0.8.4"
538source = "registry+https://github.com/rust-lang/crates.io-index" 541source = "registry+https://github.com/rust-lang/crates.io-index"
539checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" 542checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7"
540dependencies = [ 543dependencies = [
541 "hashbrown 0.14.1", 544 "hashbrown 0.14.2",
542] 545]
543 546
544[[package]] 547[[package]]
@@ -663,7 +666,7 @@ dependencies = [
663 "httpdate", 666 "httpdate",
664 "itoa", 667 "itoa",
665 "pin-project-lite", 668 "pin-project-lite",
666 "socket2 0.4.9", 669 "socket2 0.4.10",
667 "tokio", 670 "tokio",
668 "tower-service", 671 "tower-service",
669 "tracing", 672 "tracing",
@@ -687,7 +690,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
687checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" 690checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897"
688dependencies = [ 691dependencies = [
689 "equivalent", 692 "equivalent",
690 "hashbrown 0.14.1", 693 "hashbrown 0.14.2",
691] 694]
692 695
693[[package]] 696[[package]]
@@ -762,9 +765,9 @@ checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f"
762 765
763[[package]] 766[[package]]
764name = "lock_api" 767name = "lock_api"
765version = "0.4.10" 768version = "0.4.11"
766source = "registry+https://github.com/rust-lang/crates.io-index" 769source = "registry+https://github.com/rust-lang/crates.io-index"
767checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" 770checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
768dependencies = [ 771dependencies = [
769 "autocfg", 772 "autocfg",
770 "scopeguard", 773 "scopeguard",
@@ -969,13 +972,13 @@ dependencies = [
969 972
970[[package]] 973[[package]]
971name = "parking_lot_core" 974name = "parking_lot_core"
972version = "0.9.8" 975version = "0.9.9"
973source = "registry+https://github.com/rust-lang/crates.io-index" 976source = "registry+https://github.com/rust-lang/crates.io-index"
974checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" 977checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
975dependencies = [ 978dependencies = [
976 "cfg-if", 979 "cfg-if",
977 "libc", 980 "libc",
978 "redox_syscall", 981 "redox_syscall 0.4.1",
979 "smallvec", 982 "smallvec",
980 "windows-targets", 983 "windows-targets",
981] 984]
@@ -1112,6 +1115,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1112checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" 1115checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
1113 1116
1114[[package]] 1117[[package]]
1118name = "powerfmt"
1119version = "0.2.0"
1120source = "registry+https://github.com/rust-lang/crates.io-index"
1121checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
1122
1123[[package]]
1115name = "ppv-lite86" 1124name = "ppv-lite86"
1116version = "0.2.17" 1125version = "0.2.17"
1117source = "registry+https://github.com/rust-lang/crates.io-index" 1126source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1119,9 +1128,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
1119 1128
1120[[package]] 1129[[package]]
1121name = "proc-macro2" 1130name = "proc-macro2"
1122version = "1.0.68" 1131version = "1.0.69"
1123source = "registry+https://github.com/rust-lang/crates.io-index" 1132source = "registry+https://github.com/rust-lang/crates.io-index"
1124checksum = "5b1106fec09662ec6dd98ccac0f81cef56984d0b49f75c92d8cbad76e20c005c" 1133checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
1125dependencies = [ 1134dependencies = [
1126 "unicode-ident", 1135 "unicode-ident",
1127] 1136]
@@ -1175,15 +1184,24 @@ dependencies = [
1175] 1184]
1176 1185
1177[[package]] 1186[[package]]
1187name = "redox_syscall"
1188version = "0.4.1"
1189source = "registry+https://github.com/rust-lang/crates.io-index"
1190checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
1191dependencies = [
1192 "bitflags 1.3.2",
1193]
1194
1195[[package]]
1178name = "regex" 1196name = "regex"
1179version = "1.9.6" 1197version = "1.10.2"
1180source = "registry+https://github.com/rust-lang/crates.io-index" 1198source = "registry+https://github.com/rust-lang/crates.io-index"
1181checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" 1199checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
1182dependencies = [ 1200dependencies = [
1183 "aho-corasick", 1201 "aho-corasick",
1184 "memchr", 1202 "memchr",
1185 "regex-automata 0.3.9", 1203 "regex-automata 0.4.3",
1186 "regex-syntax 0.7.5", 1204 "regex-syntax 0.8.2",
1187] 1205]
1188 1206
1189[[package]] 1207[[package]]
@@ -1197,13 +1215,13 @@ dependencies = [
1197 1215
1198[[package]] 1216[[package]]
1199name = "regex-automata" 1217name = "regex-automata"
1200version = "0.3.9" 1218version = "0.4.3"
1201source = "registry+https://github.com/rust-lang/crates.io-index" 1219source = "registry+https://github.com/rust-lang/crates.io-index"
1202checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" 1220checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
1203dependencies = [ 1221dependencies = [
1204 "aho-corasick", 1222 "aho-corasick",
1205 "memchr", 1223 "memchr",
1206 "regex-syntax 0.7.5", 1224 "regex-syntax 0.8.2",
1207] 1225]
1208 1226
1209[[package]] 1227[[package]]
@@ -1214,9 +1232,9 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
1214 1232
1215[[package]] 1233[[package]]
1216name = "regex-syntax" 1234name = "regex-syntax"
1217version = "0.7.5" 1235version = "0.8.2"
1218source = "registry+https://github.com/rust-lang/crates.io-index" 1236source = "registry+https://github.com/rust-lang/crates.io-index"
1219checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" 1237checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
1220 1238
1221[[package]] 1239[[package]]
1222name = "ron" 1240name = "ron"
@@ -1269,11 +1287,11 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
1269 1287
1270[[package]] 1288[[package]]
1271name = "rustix" 1289name = "rustix"
1272version = "0.38.18" 1290version = "0.38.20"
1273source = "registry+https://github.com/rust-lang/crates.io-index" 1291source = "registry+https://github.com/rust-lang/crates.io-index"
1274checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c" 1292checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0"
1275dependencies = [ 1293dependencies = [
1276 "bitflags 2.4.0", 1294 "bitflags 2.4.1",
1277 "errno", 1295 "errno",
1278 "libc", 1296 "libc",
1279 "linux-raw-sys", 1297 "linux-raw-sys",
@@ -1300,18 +1318,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
1300 1318
1301[[package]] 1319[[package]]
1302name = "serde" 1320name = "serde"
1303version = "1.0.188" 1321version = "1.0.189"
1304source = "registry+https://github.com/rust-lang/crates.io-index" 1322source = "registry+https://github.com/rust-lang/crates.io-index"
1305checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" 1323checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537"
1306dependencies = [ 1324dependencies = [
1307 "serde_derive", 1325 "serde_derive",
1308] 1326]
1309 1327
1310[[package]] 1328[[package]]
1311name = "serde_derive" 1329name = "serde_derive"
1312version = "1.0.188" 1330version = "1.0.189"
1313source = "registry+https://github.com/rust-lang/crates.io-index" 1331source = "registry+https://github.com/rust-lang/crates.io-index"
1314checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" 1332checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5"
1315dependencies = [ 1333dependencies = [
1316 "proc-macro2", 1334 "proc-macro2",
1317 "quote", 1335 "quote",
@@ -1353,9 +1371,9 @@ dependencies = [
1353 1371
1354[[package]] 1372[[package]]
1355name = "sha1" 1373name = "sha1"
1356version = "0.10.5" 1374version = "0.10.6"
1357source = "registry+https://github.com/rust-lang/crates.io-index" 1375source = "registry+https://github.com/rust-lang/crates.io-index"
1358checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" 1376checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
1359dependencies = [ 1377dependencies = [
1360 "cfg-if", 1378 "cfg-if",
1361 "cpufeatures", 1379 "cpufeatures",
@@ -1409,9 +1427,9 @@ checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
1409 1427
1410[[package]] 1428[[package]]
1411name = "socket2" 1429name = "socket2"
1412version = "0.4.9" 1430version = "0.4.10"
1413source = "registry+https://github.com/rust-lang/crates.io-index" 1431source = "registry+https://github.com/rust-lang/crates.io-index"
1414checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" 1432checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d"
1415dependencies = [ 1433dependencies = [
1416 "libc", 1434 "libc",
1417 "winapi", 1435 "winapi",
@@ -1419,9 +1437,9 @@ dependencies = [
1419 1437
1420[[package]] 1438[[package]]
1421name = "socket2" 1439name = "socket2"
1422version = "0.5.4" 1440version = "0.5.5"
1423source = "registry+https://github.com/rust-lang/crates.io-index" 1441source = "registry+https://github.com/rust-lang/crates.io-index"
1424checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" 1442checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9"
1425dependencies = [ 1443dependencies = [
1426 "libc", 1444 "libc",
1427 "windows-sys", 1445 "windows-sys",
@@ -1563,7 +1581,7 @@ checksum = "864b869fdf56263f4c95c45483191ea0af340f9f3e3e7b4d57a61c7c87a970db"
1563dependencies = [ 1581dependencies = [
1564 "atoi", 1582 "atoi",
1565 "base64 0.21.4", 1583 "base64 0.21.4",
1566 "bitflags 2.4.0", 1584 "bitflags 2.4.1",
1567 "byteorder", 1585 "byteorder",
1568 "bytes", 1586 "bytes",
1569 "crc", 1587 "crc",
@@ -1605,7 +1623,7 @@ checksum = "eb7ae0e6a97fb3ba33b23ac2671a5ce6e3cabe003f451abd5a56e7951d975624"
1605dependencies = [ 1623dependencies = [
1606 "atoi", 1624 "atoi",
1607 "base64 0.21.4", 1625 "base64 0.21.4",
1608 "bitflags 2.4.0", 1626 "bitflags 2.4.1",
1609 "byteorder", 1627 "byteorder",
1610 "crc", 1628 "crc",
1611 "dotenvy", 1629 "dotenvy",
@@ -1711,25 +1729,25 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
1711dependencies = [ 1729dependencies = [
1712 "cfg-if", 1730 "cfg-if",
1713 "fastrand", 1731 "fastrand",
1714 "redox_syscall", 1732 "redox_syscall 0.3.5",
1715 "rustix", 1733 "rustix",
1716 "windows-sys", 1734 "windows-sys",
1717] 1735]
1718 1736
1719[[package]] 1737[[package]]
1720name = "thiserror" 1738name = "thiserror"
1721version = "1.0.49" 1739version = "1.0.50"
1722source = "registry+https://github.com/rust-lang/crates.io-index" 1740source = "registry+https://github.com/rust-lang/crates.io-index"
1723checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" 1741checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
1724dependencies = [ 1742dependencies = [
1725 "thiserror-impl", 1743 "thiserror-impl",
1726] 1744]
1727 1745
1728[[package]] 1746[[package]]
1729name = "thiserror-impl" 1747name = "thiserror-impl"
1730version = "1.0.49" 1748version = "1.0.50"
1731source = "registry+https://github.com/rust-lang/crates.io-index" 1749source = "registry+https://github.com/rust-lang/crates.io-index"
1732checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" 1750checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
1733dependencies = [ 1751dependencies = [
1734 "proc-macro2", 1752 "proc-macro2",
1735 "quote", 1753 "quote",
@@ -1748,14 +1766,15 @@ dependencies = [
1748 1766
1749[[package]] 1767[[package]]
1750name = "time" 1768name = "time"
1751version = "0.3.29" 1769version = "0.3.30"
1752source = "registry+https://github.com/rust-lang/crates.io-index" 1770source = "registry+https://github.com/rust-lang/crates.io-index"
1753checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" 1771checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
1754dependencies = [ 1772dependencies = [
1755 "deranged", 1773 "deranged",
1756 "itoa", 1774 "itoa",
1757 "libc", 1775 "libc",
1758 "num_threads", 1776 "num_threads",
1777 "powerfmt",
1759 "serde", 1778 "serde",
1760 "time-core", 1779 "time-core",
1761 "time-macros", 1780 "time-macros",
@@ -1793,9 +1812,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
1793 1812
1794[[package]] 1813[[package]]
1795name = "tokio" 1814name = "tokio"
1796version = "1.32.0" 1815version = "1.33.0"
1797source = "registry+https://github.com/rust-lang/crates.io-index" 1816source = "registry+https://github.com/rust-lang/crates.io-index"
1798checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" 1817checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653"
1799dependencies = [ 1818dependencies = [
1800 "backtrace", 1819 "backtrace",
1801 "bytes", 1820 "bytes",
@@ -1803,7 +1822,7 @@ dependencies = [
1803 "mio", 1822 "mio",
1804 "num_cpus", 1823 "num_cpus",
1805 "pin-project-lite", 1824 "pin-project-lite",
1806 "socket2 0.5.4", 1825 "socket2 0.5.5",
1807 "tokio-macros", 1826 "tokio-macros",
1808 "windows-sys", 1827 "windows-sys",
1809] 1828]
@@ -1869,11 +1888,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
1869 1888
1870[[package]] 1889[[package]]
1871name = "tracing" 1890name = "tracing"
1872version = "0.1.37" 1891version = "0.1.40"
1873source = "registry+https://github.com/rust-lang/crates.io-index" 1892source = "registry+https://github.com/rust-lang/crates.io-index"
1874checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" 1893checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
1875dependencies = [ 1894dependencies = [
1876 "cfg-if",
1877 "log", 1895 "log",
1878 "pin-project-lite", 1896 "pin-project-lite",
1879 "tracing-attributes", 1897 "tracing-attributes",
@@ -1882,9 +1900,9 @@ dependencies = [
1882 1900
1883[[package]] 1901[[package]]
1884name = "tracing-attributes" 1902name = "tracing-attributes"
1885version = "0.1.26" 1903version = "0.1.27"
1886source = "registry+https://github.com/rust-lang/crates.io-index" 1904source = "registry+https://github.com/rust-lang/crates.io-index"
1887checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" 1905checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
1888dependencies = [ 1906dependencies = [
1889 "proc-macro2", 1907 "proc-macro2",
1890 "quote", 1908 "quote",
@@ -1893,9 +1911,9 @@ dependencies = [
1893 1911
1894[[package]] 1912[[package]]
1895name = "tracing-core" 1913name = "tracing-core"
1896version = "0.1.31" 1914version = "0.1.32"
1897source = "registry+https://github.com/rust-lang/crates.io-index" 1915source = "registry+https://github.com/rust-lang/crates.io-index"
1898checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" 1916checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
1899dependencies = [ 1917dependencies = [
1900 "once_cell", 1918 "once_cell",
1901 "valuable", 1919 "valuable",
diff --git a/docker-compose.yml b/docker-compose.yml
index 9d73e9b..abac64e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -6,7 +6,8 @@ services:
6 container_name: webol_dev_postgres 6 container_name: webol_dev_postgres
7 restart: no 7 restart: no
8 environment: 8 environment:
9 POSTGRES_PASSWORD: postgres 9 - POSTGRES_PASSWORD=postgres
10 - POSTGRES_DB=webol
10 11
11 ports: 12 ports:
12 - "5432:5432" 13 - "5432:5432"
diff --git a/migrations/20231009123228_devices.sql b/migrations/20231009123228_devices.sql
index 5856c3a..9d0c7ca 100644
--- a/migrations/20231009123228_devices.sql
+++ b/migrations/20231009123228_devices.sql
@@ -1,7 +1,7 @@
1-- Add migration script here 1-- Add migration script here
2CREATE TABLE "devices" 2CREATE TABLE IF NOT EXISTS "devices"
3( 3(
4 "id" TEXT PRIMARY KEY NOT NULL, 4 "id" TEXT PRIMARY KEY NOT NULL,
5 "mac" TEXT NOT NULL, 5 "mac" TEXT NOT NULL,
6 "broadcast_addr" TEXT NOT NULL 6 "broadcast_addr" TEXT NOT NULL
7) \ No newline at end of file 7)
diff --git a/src/auth.rs b/src/auth.rs
index 81e798f..0fffa60 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -25,6 +25,7 @@ pub fn auth(secret: Option<&HeaderValue>) -> Result<bool, AuthError> {
25 } 25 }
26} 26}
27 27
28#[derive(Debug)]
28pub enum AuthError { 29pub enum AuthError {
29 WrongSecret, 30 WrongSecret,
30 MissingSecret, 31 MissingSecret,
@@ -42,4 +43,4 @@ impl AuthError {
42 }, 43 },
43 } 44 }
44 } 45 }
45} \ No newline at end of file 46}
diff --git a/src/db.rs b/src/db.rs
index 87943ca..295780e 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -1,8 +1,32 @@
1use std::env;
2
1use serde::Serialize; 3use serde::Serialize;
4use sqlx::{PgPool, postgres::PgPoolOptions};
5use tracing::{debug, info};
2 6
3#[derive(Serialize)] 7#[derive(Serialize)]
4pub struct Device { 8pub struct Device {
5 pub id: String, 9 pub id: String,
6 pub mac: String, 10 pub mac: String,
7 pub broadcast_addr: String 11 pub broadcast_addr: String
8} \ No newline at end of file 12}
13
14pub async fn init_db_pool() -> PgPool {
15 #[cfg(not(debug_assertions))]
16 let db_url = SETTINGS.get_string("database.url").unwrap();
17
18 #[cfg(debug_assertions)]
19 let db_url = env::var("DATABASE_URL").unwrap();
20
21 debug!("attempt to connect dbPool to '{}'", db_url);
22
23 let pool = PgPoolOptions::new()
24 .max_connections(5)
25 .connect(&db_url)
26 .await
27 .unwrap();
28
29 info!("dbPool successfully connected to '{}'", db_url);
30
31 pool
32}
diff --git a/src/error.rs b/src/error.rs
index afed111..db2fc86 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -6,6 +6,7 @@ use serde_json::json;
6use tracing::error; 6use tracing::error;
7use crate::auth::AuthError; 7use crate::auth::AuthError;
8 8
9#[derive(Debug)]
9pub enum WebolError { 10pub enum WebolError {
10 Auth(AuthError), 11 Auth(AuthError),
11 Generic, 12 Generic,
diff --git a/src/main.rs b/src/main.rs
index b7306ea..ce12cf6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,11 +3,11 @@ use std::sync::Arc;
3use axum::{Router, routing::post}; 3use axum::{Router, routing::post};
4use axum::routing::{get, put}; 4use axum::routing::{get, put};
5use sqlx::PgPool; 5use sqlx::PgPool;
6use sqlx::postgres::PgPoolOptions;
7use time::util::local_offset; 6use time::util::local_offset;
8use tracing::{debug, info, level_filters::LevelFilter}; 7use tracing::{info, level_filters::LevelFilter};
9use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; 8use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*};
10use crate::config::SETTINGS; 9use crate::config::SETTINGS;
10use crate::db::init_db_pool;
11use crate::routes::device::{get_device, post_device, put_device}; 11use crate::routes::device::{get_device, post_device, put_device};
12use crate::routes::start::start; 12use crate::routes::start::start;
13 13
@@ -41,6 +41,7 @@ async fn main() {
41 info!("start webol v{}", version); 41 info!("start webol v{}", version);
42 42
43 let db = init_db_pool().await; 43 let db = init_db_pool().await;
44 sqlx::migrate!().run(&db).await.unwrap();
44 45
45 let shared_state = Arc::new(AppState { db }); 46 let shared_state = Arc::new(AppState { db });
46 47
@@ -62,23 +63,3 @@ async fn main() {
62pub struct AppState { 63pub struct AppState {
63 db: PgPool 64 db: PgPool
64} 65}
65
66async fn init_db_pool() -> PgPool {
67 #[cfg(not(debug_assertions))]
68 let db_url = SETTINGS.get_string("database.url").unwrap();
69
70 #[cfg(debug_assertions)]
71 let db_url = env::var("DATABASE_URL").unwrap();
72
73 debug!("attempt to connect dbPool to '{}'", db_url);
74
75 let pool = PgPoolOptions::new()
76 .max_connections(5)
77 .connect(&db_url)
78 .await
79 .unwrap();
80
81 info!("dbPool successfully connected to '{}'", db_url);
82
83 pool
84}