diff --git a/Cargo.lock b/Cargo.lock index 8f85f7d..d5cbfbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.20.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -19,40 +19,30 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - -[[package]] -name = "ahash" -version = "0.8.3" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] name = "aho-corasick" -version = "1.0.4" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "android-tzdata" @@ -69,52 +59,128 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" + +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn", ] [[package]] name = "atoi" -version = "1.0.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" +checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" dependencies = [ "num-traits", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "axum" -version = "0.6.20" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" dependencies = [ "async-trait", "axum-core", - "bitflags 1.3.2", "bytes", "futures-util", "http", "http-body", - "hyper", + "http-body-util", "itoa", "matchit", "memchr", @@ -123,7 +189,7 @@ dependencies = [ "pin-project-lite", "rustversion", "serde", - "sync_wrapper", + "sync_wrapper 1.0.1", "tower", "tower-layer", "tower-service", @@ -131,26 +197,29 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.3.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" dependencies = [ "async-trait", "bytes", "futures-util", "http", "http-body", + "http-body-util", "mime", + "pin-project-lite", "rustversion", + "sync_wrapper 0.1.2", "tower-layer", "tower-service", ] [[package]] name = "backtrace" -version = "0.3.68" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -163,27 +232,30 @@ dependencies = [ [[package]] name = "base64" -version = "0.13.1" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64" -version = "0.21.2" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] -name = "bitflags" -version = "1.3.2" +name = "base64ct" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +dependencies = [ + "serde", +] [[package]] name = "block-buffer" @@ -196,29 +268,29 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.4.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cc" -version = "1.0.83" +version = "1.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "a93fe60e2fc87b6ba2c117f67ae14f66e3fc7d6a1e612a25adb238cc980eadb3" dependencies = [ - "libc", + "shlex", ] [[package]] @@ -229,24 +301,23 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.26" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", - "time 0.1.45", "wasm-bindgen", - "winapi", + "windows-targets 0.52.6", ] [[package]] name = "chrono-tz" -version = "0.8.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1369bc6b9e9a7dfdae2055f6ec151fe9c554a9d23d357c0237cee2e25eaabb7" +checksum = "93698b29de5e97ad0ae26447b344c482a7284c737d9ddc5f9e52b74a336671bb" dependencies = [ "chrono", "chrono-tz-build", @@ -255,63 +326,120 @@ dependencies = [ [[package]] name = "chrono-tz-build" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2f5ebdc942f57ed96d560a6d1a459bae5851102a25d5bf89dc04ae453e31ecf" +checksum = "0c088aee841df9c3041febbb73934cfc39708749bf96dc827e3359cd39ef11b1" dependencies = [ "parse-zoneinfo", "phf", "phf_codegen", ] +[[package]] +name = "clap" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] [[package]] name = "crc" -version = "3.0.1" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" dependencies = [ "crc-catalog", ] [[package]] name = "crc-catalog" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" [[package]] name = "crossbeam-queue" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cfb3ea8a53f37c40dea2c7bedcbd88bdfae54f5e2175d6ecaff1c988353add" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crypto-common" @@ -323,11 +451,25 @@ dependencies = [ "typenum", ] +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] [[package]] name = "digest" @@ -336,53 +478,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", "subtle", ] [[package]] -name = "dirs" -version = "4.0.0" +name = "dotenvy" +version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" -dependencies = [ - "dirs-sys", -] +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" [[package]] -name = "dirs-sys" -version = "0.3.7" +name = "either" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" dependencies = [ - "libc", - "redox_users", - "winapi", + "serde", ] [[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - -[[package]] -name = "either" -version = "1.9.0" +name = "env_filter" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] [[package]] name = "env_logger" -version = "0.10.0" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" dependencies = [ + "anstream", + "anstyle", + "env_filter", "humantime", - "is-terminal", "log", - "regex", - "termcolor", ] [[package]] @@ -393,36 +529,41 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.2" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ - "errno-dragonfly", "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] -name = "errno-dragonfly" -version = "0.1.2" +name = "etcetera" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" dependencies = [ - "cc", - "libc", + "cfg-if", + "home", + "windows-sys 0.48.0", ] [[package]] name = "event-listener" -version = "2.5.3" +version = "5.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] [[package]] name = "fastrand" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "fixedbitset" @@ -430,6 +571,17 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "flume" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +dependencies = [ + "futures-core", + "futures-sink", + "spin", +] + [[package]] name = "fnv" version = "1.0.7" @@ -438,33 +590,18 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "form_urlencoded" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -472,15 +609,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -489,9 +626,9 @@ dependencies = [ [[package]] name = "futures-intrusive" -version = "0.4.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a604f7a68fbf8103337523b1fadc8ade7361ee3f112f7c680ad179651616aed5" +checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" dependencies = [ "futures-core", "lock_api", @@ -500,43 +637,30 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.29", -] +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ - "futures-channel", "futures-core", "futures-io", - "futures-macro", "futures-sink", "futures-task", "memchr", @@ -547,22 +671,20 @@ dependencies = [ [[package]] name = "ganymede" -version = "2.0.0" +version = "3.0.0" dependencies = [ - "async-trait", "chrono", "chrono-tz", + "clap", "env_logger", - "futures", + "futures-core", "jsonwebtoken", "log", "prost", "prost-types", - "regex", "serde", "serde_json", "sqlx", - "time 0.3.26", "tokio", "toml", "tonic", @@ -583,34 +705,36 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", + "wasm-bindgen", ] [[package]] name = "gimli" -version = "0.27.3" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "h2" -version = "0.3.21" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" dependencies = [ + "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "futures-util", "http", - "indexmap 1.9.3", + "indexmap 2.5.0", "slab", "tokio", "tokio-util", @@ -625,37 +749,34 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "ahash 0.8.3", + "ahash", "allocator-api2", ] [[package]] name = "hashlink" -version = "0.8.3" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "312f66718a2d7789ffef4f4b7b213138ed9f1eb3aa1d0d82fc99f88fb3ffd26f" +checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" dependencies = [ - "hashbrown 0.14.0", + "hashbrown 0.14.5", ] [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -665,9 +786,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hkdf" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" dependencies = [ "hmac", ] @@ -681,11 +802,20 @@ dependencies = [ "digest", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" -version = "0.2.9" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes", "fnv", @@ -694,20 +824,32 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.5" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", + "futures-util", "http", + "http-body", "pin-project-lite", ] [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" @@ -723,13 +865,12 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.27" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ "bytes", "futures-channel", - "futures-core", "futures-util", "h2", "http", @@ -738,37 +879,56 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.9", + "smallvec", "tokio", - "tower-service", - "tracing", "want", ] [[package]] name = "hyper-timeout" -version = "0.4.1" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" +dependencies = [ + "hyper", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", "hyper", "pin-project-lite", + "socket2", "tokio", - "tokio-io-timeout", + "tower", + "tower-service", + "tracing", ] [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows", + "windows-core", ] [[package]] @@ -782,9 +942,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -802,65 +962,52 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", - "hashbrown 0.14.0", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", + "hashbrown 0.14.5", ] [[package]] -name = "is-terminal" -version = "0.4.9" +name = "is_terminal_polyfill" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi", - "rustix", - "windows-sys", -] +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itertools" -version = "0.10.5" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ "either", ] [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] [[package]] name = "jsonwebtoken" -version = "8.3.0" +version = "9.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" +checksum = "b9ae10193d25051e74945f1ea2d0b42e03cc3b890f7e4cc5faa44997d808193f" dependencies = [ - "base64 0.21.2", + "base64 0.21.7", + "js-sys", "pem", "ring", "serde", @@ -870,58 +1017,79 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] [[package]] name = "libc" -version = "0.2.147" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] -name = "linux-raw-sys" -version = "0.4.5" +name = "libm" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] -name = "lock_api" -version = "0.4.10" +name = "libsqlite3-sys" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" dependencies = [ - "autocfg", - "scopeguard", + "cc", + "pkg-config", + "vcpkg", ] [[package]] -name = "log" -version = "0.4.20" +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "matchit" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed1202b2a6f884ae56f04cff409ab315c5ce26b5e58d7412e484f01fd52f52ef" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "md-5" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" dependencies = [ + "cfg-if", "digest", ] [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -937,29 +1105,30 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] [[package]] name = "mio" -version = "0.8.8" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "wasi", + "windows-sys 0.52.0", ] [[package]] name = "multimap" -version = "0.8.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" [[package]] name = "nom" @@ -973,122 +1142,159 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.3" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", ] +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] -name = "num-traits" -version = "0.2.16" +name = "num-iter" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" dependencies = [ "autocfg", + "num-integer", + "num-traits", ] [[package]] -name = "num_cpus" -version = "1.16.0" +name = "num-traits" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ - "hermit-abi", - "libc", + "autocfg", + "libm", ] [[package]] name = "object" -version = "0.31.1" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "parking" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" [[package]] name = "parking_lot" -version = "0.11.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ - "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.8.6" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", - "instant", "libc", - "redox_syscall 0.2.16", + "redox_syscall", "smallvec", - "winapi", + "windows-targets 0.52.6", ] [[package]] name = "parse-zoneinfo" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41" +checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24" dependencies = [ "regex", ] [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pem" -version = "1.1.1" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae" +dependencies = [ + "base64 0.22.1", + "serde", +] + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" dependencies = [ - "base64 0.13.1", + "base64ct", ] [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "petgraph" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", - "indexmap 2.0.0", + "indexmap 2.5.0", ] [[package]] @@ -1131,29 +1337,29 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.3" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn", ] [[package]] name = "pin-project-lite" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -1161,36 +1367,72 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "prettyplease" -version = "0.1.25" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 1.0.109", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "prost" -version = "0.11.9" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" dependencies = [ "bytes", "prost-derive", @@ -1198,53 +1440,52 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.11.9" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" +checksum = "f8650aabb6c35b860610e9cff5dc1af886c9e25073b7b1712a68972af4281302" dependencies = [ "bytes", "heck", "itertools", - "lazy_static", "log", "multimap", + "once_cell", "petgraph", "prettyplease", "prost", "prost-types", "regex", - "syn 1.0.109", + "syn", "tempfile", - "which", ] [[package]] name = "prost-derive" -version = "0.11.9" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" dependencies = [ "anyhow", "itertools", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "prost-types" -version = "0.11.9" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" +checksum = "60caa6738c7369b940c3d49246a8d1749323674c65cb13010134f5c9bad5b519" dependencies = [ "prost", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1281,38 +1522,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_users" -version = "0.4.3" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "getrandom", - "redox_syscall 0.2.16", - "thiserror", + "bitflags", ] [[package]] name = "regex" -version = "1.9.3" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -1322,9 +1543,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -1333,76 +1554,116 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "ring" -version = "0.16.20" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", + "cfg-if", + "getrandom", "libc", - "once_cell", "spin", "untrusted", - "web-sys", - "winapi", + "windows-sys 0.52.0", +] + +[[package]] +name = "rsa" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "signature", + "spki", + "subtle", + "zeroize", ] [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustix" -version = "0.38.8" +version = "0.38.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" +checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" dependencies = [ - "bitflags 2.4.0", + "bitflags", "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] name = "rustls" -version = "0.20.8" +version = "0.23.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ - "log", + "once_cell", "ring", - "sct", - "webpki", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", ] [[package]] name = "rustls-pemfile" -version = "1.0.3" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64 0.22.1", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" +checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" dependencies = [ - "base64 0.21.2", + "ring", + "rustls-pki-types", + "untrusted", ] [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "scopeguard" @@ -1410,42 +1671,54 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "sct" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "serde" -version = "1.0.171" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.171" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn", ] [[package]] name = "serde_json" -version = "1.0.105" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", "itoa", "ryu", "serde", @@ -1453,9 +1726,9 @@ dependencies = [ [[package]] name = "sha1" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", "cpufeatures", @@ -1464,15 +1737,31 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", "digest", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + [[package]] name = "simple_asn1" version = "0.6.2" @@ -1482,14 +1771,14 @@ dependencies = [ "num-bigint", "num-traits", "thiserror", - "time 0.3.26", + "time", ] [[package]] name = "siphasher" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "slab" @@ -1502,174 +1791,285 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +dependencies = [ + "serde", +] [[package]] name = "socket2" -version = "0.4.9" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "winapi", + "windows-sys 0.52.0", ] [[package]] -name = "socket2" -version = "0.5.3" +name = "spin" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" dependencies = [ - "libc", - "windows-sys", + "lock_api", ] [[package]] -name = "spin" -version = "0.5.2" +name = "spki" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] [[package]] name = "sqlformat" -version = "0.2.1" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c12bc9199d1db8234678b7051747c07f517cdcf019262d1847b94ec8b1aee3e" +checksum = "7bba3a93db0cc4f7bdece8bb09e77e2e785c20bfebf79eb8340ed80708048790" dependencies = [ - "itertools", "nom", "unicode_categories", ] [[package]] name = "sqlx" -version = "0.6.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8de3b03a925878ed54a954f621e64bf55a3c1bd29652d0d1a17830405350188" +checksum = "93334716a037193fac19df402f8571269c84a00852f6a7066b5d2616dcd64d3e" dependencies = [ "sqlx-core", "sqlx-macros", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", ] [[package]] name = "sqlx-core" -version = "0.6.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa8241483a83a3f33aa5fff7e7d9def398ff9990b2752b6c6112b83c6d246029" +checksum = "d4d8060b456358185f7d50c55d9b5066ad956956fddec42ee2e8567134a8936e" dependencies = [ - "ahash 0.7.6", "atoi", - "base64 0.13.1", - "bitflags 1.3.2", "byteorder", "bytes", + "chrono", "crc", "crossbeam-queue", - "dirs", - "dotenvy", "either", "event-listener", "futures-channel", "futures-core", "futures-intrusive", + "futures-io", "futures-util", + "hashbrown 0.14.5", "hashlink", "hex", - "hkdf", - "hmac", - "indexmap 1.9.3", - "itoa", - "libc", + "indexmap 2.5.0", "log", - "md-5", "memchr", "once_cell", "paste", "percent-encoding", - "rand", "rustls", "rustls-pemfile", "serde", "serde_json", - "sha1", "sha2", "smallvec", "sqlformat", - "sqlx-rt", - "stringprep", "thiserror", + "tokio", "tokio-stream", + "tracing", "url", "uuid", "webpki-roots", - "whoami", ] [[package]] name = "sqlx-macros" -version = "0.6.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9966e64ae989e7e575b19d7265cb79d7fc3cbbdf179835cb0d716f294c2049c9" +checksum = "cac0692bcc9de3b073e8d747391827297e075c7710ff6276d9f7a1f3d58c6657" +dependencies = [ + "proc-macro2", + "quote", + "sqlx-core", + "sqlx-macros-core", + "syn", +] + +[[package]] +name = "sqlx-macros-core" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1804e8a7c7865599c9c79be146dc8a9fd8cc86935fa641d3ea58e5f0688abaa5" dependencies = [ "dotenvy", "either", "heck", + "hex", "once_cell", "proc-macro2", "quote", + "serde", "serde_json", "sha2", "sqlx-core", - "sqlx-rt", - "syn 1.0.109", + "sqlx-mysql", + "sqlx-postgres", + "sqlx-sqlite", + "syn", + "tempfile", + "tokio", "url", ] [[package]] -name = "sqlx-rt" -version = "0.6.3" +name = "sqlx-mysql" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "804d3f245f894e61b1e6263c84b23ca675d96753b5abfd5cc8597d86806e8024" +checksum = "64bb4714269afa44aef2755150a0fc19d756fb580a67db8885608cf02f47d06a" dependencies = [ + "atoi", + "base64 0.22.1", + "bitflags", + "byteorder", + "bytes", + "chrono", + "crc", + "digest", + "dotenvy", + "either", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "generic-array", + "hex", + "hkdf", + "hmac", + "itoa", + "log", + "md-5", + "memchr", "once_cell", - "tokio", - "tokio-rustls", + "percent-encoding", + "rand", + "rsa", + "serde", + "sha1", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-postgres" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fa91a732d854c5d7726349bb4bb879bb9478993ceb764247660aee25f67c2f8" +dependencies = [ + "atoi", + "base64 0.22.1", + "bitflags", + "byteorder", + "chrono", + "crc", + "dotenvy", + "etcetera", + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "hex", + "hkdf", + "hmac", + "home", + "itoa", + "log", + "md-5", + "memchr", + "once_cell", + "rand", + "serde", + "serde_json", + "sha2", + "smallvec", + "sqlx-core", + "stringprep", + "thiserror", + "tracing", + "uuid", + "whoami", +] + +[[package]] +name = "sqlx-sqlite" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5b2cf34a45953bfd3daaf3db0f7a7878ab9b7a6b91b422d24a7a9e4c857b680" +dependencies = [ + "atoi", + "chrono", + "flume", + "futures-channel", + "futures-core", + "futures-executor", + "futures-intrusive", + "futures-util", + "libsqlite3-sys", + "log", + "percent-encoding", + "serde", + "serde_urlencoded", + "sqlx-core", + "tracing", + "url", + "uuid", ] [[package]] name = "stringprep" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3737bde7edce97102e0e2b15365bf7a20bfdb5f60f4f9e8d7004258a51a8da" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" dependencies = [ "unicode-bidi", "unicode-normalization", + "unicode-properties", ] [[package]] -name = "subtle" -version = "2.5.0" +name = "strsim" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] -name = "syn" -version = "1.0.109" +name = "subtle" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.29" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -1682,67 +2082,55 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "tempfile" -version = "3.8.0" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", "fastrand", - "redox_syscall 0.3.5", + "once_cell", "rustix", - "windows-sys", -] - -[[package]] -name = "termcolor" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" -dependencies = [ - "winapi-util", + "windows-sys 0.59.0", ] [[package]] name = "thiserror" -version = "1.0.47" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.47" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn", ] [[package]] name = "time" -version = "0.1.45" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - -[[package]] -name = "time" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a79d09ac6b08c1ab3906a2f7cc2e81a0e27c7ae89c63812df75e52bef0751e07" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", + "num-conv", + "powerfmt", "serde", "time-core", "time-macros", @@ -1750,24 +2138,25 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.12" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75c65469ed6b3a4809d987a41eb1dc918e9bc1d92211cbad7ae82931846f7451" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -1780,58 +2169,36 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.32.0" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "pin-project-lite", - "socket2 0.5.3", + "socket2", "tokio-macros", - "windows-sys", -] - -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", -] - -[[package]] -name = "tokio-rustls" -version = "0.23.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c43ee83903113e03984cb9e5cebe6c04a5116269e900e3ddba8f068a62adda59" -dependencies = [ - "rustls", - "tokio", - "webpki", + "syn", ] [[package]] name = "tokio-stream" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ "futures-core", "pin-project-lite", @@ -1840,47 +2207,73 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] name = "toml" -version = "0.5.11" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ + "indexmap 2.5.0", "serde", + "serde_spanned", + "toml_datetime", + "winnow", ] [[package]] name = "tonic" -version = "0.9.2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3082666a3a6433f7f511c7192923fa1fe07c69332d3c6a2e6bb040b569199d5a" +checksum = "c6f6ba989e4b2c58ae83d862d3a3e27690b6e3ae630d0deb59f3697f32aa88ad" dependencies = [ + "async-stream", "async-trait", "axum", - "base64 0.21.2", + "base64 0.22.1", "bytes", - "futures-core", - "futures-util", "h2", "http", "http-body", + "http-body-util", "hyper", "hyper-timeout", + "hyper-util", "percent-encoding", "pin-project", "prost", + "socket2", "tokio", "tokio-stream", "tower", @@ -1891,22 +2284,22 @@ dependencies = [ [[package]] name = "tonic-build" -version = "0.9.2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6fdaae4c2c638bb70fe42803a26fbd6fc6ac8c72f5c59f67ecc2a2dcabf4b07" +checksum = "fe4ee8877250136bd7e3d2331632810a4df4ea5e004656990d8d66d2f5ee8a67" dependencies = [ "prettyplease", "proc-macro2", "prost-build", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "tonic-reflection" -version = "0.9.2" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0543d7092032041fbeac1f2c84304537553421a11a623c2301b12ef0264862c7" +checksum = "7b56b874eedb04f89907573b408eab1e87c1c1dce43aac6ad63742f57faa99ff" dependencies = [ "prost", "prost-types", @@ -1937,23 +2330,23 @@ dependencies = [ [[package]] name = "tower-layer" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" [[package]] name = "tower-service" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -1961,62 +2354,62 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", ] [[package]] name = "try-lock" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] [[package]] -name = "unicode-segmentation" -version = "1.10.1" +name = "unicode-properties" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +checksum = "52ea75f83c0137a9b98608359a5f1af8144876eb67bcb1ce837368e906a9f524" [[package]] name = "unicode_categories" @@ -2026,47 +2419,47 @@ checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" [[package]] name = "untrusted" -version = "0.7.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.4.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" -version = "1.4.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" +checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" dependencies = [ "getrandom", - "uuid-macro-internal", ] [[package]] -name = "uuid-macro-internal" -version = "1.4.1" +name = "vcpkg" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e1ba1f333bd65ce3c9f27de592fcbc256dafe3af2717f56d7c87761fbaccf4" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.29", -] +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "want" @@ -2079,46 +2472,47 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +name = "wasite" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.29", + "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2126,135 +2520,107 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.29", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" - -[[package]] -name = "web-sys" -version = "0.3.64" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "webpki" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" -dependencies = [ - "ring", - "untrusted", -] +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "webpki-roots" -version = "0.22.6" +version = "0.26.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c71e40d7d2c34a5106301fb632274ca37242cd0c9d3e64dbece371a40a2d87" +checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" dependencies = [ - "webpki", + "rustls-pki-types", ] [[package]] -name = "which" -version = "4.4.0" +name = "whoami" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "372d5b87f58ec45c384ba03563b03544dc5fadc3983e434b286913f5b4a9bb6d" dependencies = [ - "either", - "libc", - "once_cell", + "redox_syscall", + "wasite", ] [[package]] -name = "whoami" -version = "1.4.1" +name = "windows-core" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "wasm-bindgen", - "web-sys", + "windows-targets 0.52.6", ] [[package]] -name = "winapi" -version = "0.3.9" +name = "windows-sys" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows-targets 0.48.5", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "winapi", + "windows-targets 0.52.6", ] [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows" -version = "0.48.0" +name = "windows-sys" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] -name = "windows-sys" -version = "0.48.0" +name = "windows-targets" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows-targets", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -2263,38 +2629,122 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index d29880f..1f2e904 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,33 +1,31 @@ [package] name = "ganymede" -version = "2.0.0" -authors = ["David Bourgault "] +version = "3.0.0" +authors = ["David Bourgault Result<(), Box> { "#[derive(serde::Serialize, serde::Deserialize)] #[serde(rename_all = \"camelCase\")]", ) .compile( - &[ - "api/ganymede/v2/device.proto", - "api/ganymede/v2/measurements.proto", - ], + &["api/ganymede/v2/device.proto", "api/ganymede/v2/measurements.proto"], &["api/"], )?; Ok(()) diff --git a/docker-compose.yml b/docker-compose.yml index 36edfd4..8bf51fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ services: - ./Ganymede.toml:/app/Ganymede.toml postgres: - image: postgres:15.3 + image: timescale/timescaledb:latest-pg15 environment: POSTGRES_PASSWORD: postgres POSTGRES_DB: ganymede diff --git a/fixtures/config.sql b/fixtures/config.sql new file mode 100644 index 0000000..5792029 --- /dev/null +++ b/fixtures/config.sql @@ -0,0 +1,13 @@ +INSERT INTO config ( + config_id, + domain_id, + display_name, + poll_period, + light_config +) VALUES ( + '00000000-0000-0000-0000-000000000000'::UUID, + '00000000-0000-0000-0000-000000000000'::UUID, + 'Test Config', + '1H'::INTERVAL, + '{}'::JSONB +) \ No newline at end of file diff --git a/fixtures/device.sql b/fixtures/device.sql new file mode 100644 index 0000000..805a657 --- /dev/null +++ b/fixtures/device.sql @@ -0,0 +1,19 @@ +INSERT INTO device ( + device_id, + domain_id, + display_name, + mac, + config_id, + description, + timezone, + last_poll +) VALUES ( + '00000000-0000-0000-0000-000000000000'::UUID, + '00000000-0000-0000-0000-000000000000'::UUID, + 'Test Display', + '00:00:00:00:00:00', + '00000000-0000-0000-0000-000000000000'::UUID, + 'This describes a device', + 'America/Montreal', + NULL +) \ No newline at end of file diff --git a/fixtures/domain.sql b/fixtures/domain.sql new file mode 100644 index 0000000..1cff875 --- /dev/null +++ b/fixtures/domain.sql @@ -0,0 +1,9 @@ +INSERT INTO domain( + domain_id, + name, + display_name +) VALUES ( + '00000000-0000-0000-0000-000000000000'::UUID, + 'test-domain', + 'Test Domain' +) diff --git a/kubernetes/ganymede.yaml b/kubernetes/ganymede.yaml index 15f8f90..5f038f2 100755 --- a/kubernetes/ganymede.yaml +++ b/kubernetes/ganymede.yaml @@ -8,7 +8,7 @@ metadata: app.kubernetes.io/component: app data: Ganymede.toml: | - postgres_uri = "postgres://postgres:postgres@localhost:5432/ganymede" + postgres_uri = "postgresql://postgres:postgres@database:5432/ganymede" port = 3000 --- apiVersion: apps/v1 @@ -33,7 +33,8 @@ spec: spec: containers: - name: ganymede - image: ghcr.io/ngc7293/ganymede:latest + image: ghcr.io/ngc7293/ganymede:dev + imagePullPolicy: Always ports: - containerPort: 3000 resources: @@ -45,7 +46,8 @@ spec: memory: 512M volumeMounts: - name: config-volume - mountPath: /app + mountPath: /app/Ganymede.toml + subPath: Ganymede.toml volumes: - name: config-volume configMap: diff --git a/migrations/20230621005425_Initial_Schema.sql b/migrations/20230621005425_Initial_schema.sql similarity index 100% rename from migrations/20230621005425_Initial_Schema.sql rename to migrations/20230621005425_Initial_schema.sql diff --git a/migrations/20240411230607_Add_last_poll_tracking.sql b/migrations/20240411230607_Add_last_poll_tracking.sql new file mode 100644 index 0000000..c872ad5 --- /dev/null +++ b/migrations/20240411230607_Add_last_poll_tracking.sql @@ -0,0 +1 @@ +ALTER TABLE device ADD COLUMN last_poll TIMESTAMP WITH TIME ZONE; diff --git a/migrations/20240412183033_Initial_timescale_schema.sql b/migrations/20240412183033_Initial_timescale_schema.sql new file mode 100644 index 0000000..c84ae01 --- /dev/null +++ b/migrations/20240412183033_Initial_timescale_schema.sql @@ -0,0 +1,25 @@ +CREATE EXTENSION IF NOT EXISTS timescaledb; + +CREATE TABLE "atmosphere" ( + observed_on TIMESTAMP WITH TIME ZONE DEFAULT (NOW() AT TIME ZONE 'UTC') NOT NULL, + domain_id UUID NOT NULL, + device_id UUID NOT NULL, + temperature FLOAT, + relative_humidity FLOAT, + + FOREIGN KEY (domain_id) REFERENCES domain(domain_id) ON DELETE CASCADE, + FOREIGN KEY (device_id) REFERENCES device(device_id) ON DELETE CASCADE +); +SELECT create_hypertable('atmosphere', by_range('observed_on')); + +CREATE TABLE "soil" ( + observed_on TIMESTAMP WITH TIME ZONE DEFAULT (NOW() AT TIME ZONE 'UTC') NOT NULL, + domain_id UUID NOT NULL, + device_id UUID NOT NULL, + temperature FLOAT, + humidity FLOAT, + + FOREIGN KEY (domain_id) REFERENCES domain(domain_id) ON DELETE CASCADE, + FOREIGN KEY (device_id) REFERENCES device(device_id) ON DELETE CASCADE +); +SELECT create_hypertable('soil', by_range('observed_on')); \ No newline at end of file diff --git a/migrations/20240829001800_Add_poll_period_to_config.sql b/migrations/20240829001800_Add_poll_period_to_config.sql new file mode 100644 index 0000000..9c543b6 --- /dev/null +++ b/migrations/20240829001800_Add_poll_period_to_config.sql @@ -0,0 +1 @@ +ALTER TABLE config ADD COLUMN poll_period INTERVAL NOT NULL DEFAULT '1H'; \ No newline at end of file diff --git a/migrations/20240907005328_Rename_device_mac_unique_constraint.sql b/migrations/20240907005328_Rename_device_mac_unique_constraint.sql new file mode 100644 index 0000000..4b2be9c --- /dev/null +++ b/migrations/20240907005328_Rename_device_mac_unique_constraint.sql @@ -0,0 +1 @@ +ALTER TABLE device RENAME CONSTRAINT device_mac_key TO device_mac_unique; \ No newline at end of file diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..5a3cea5 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +max_width = 120 +chain_width = 120 diff --git a/schema.sql b/schema.sql deleted file mode 100644 index 5a87c3f..0000000 --- a/schema.sql +++ /dev/null @@ -1,29 +0,0 @@ -CREATE TABLE IF NOT EXISTS domain ( - domain_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - name VARCHAR(255) NOT NULL, - display_name VARCHAR(255) NOT NULL -); - -CREATE TABLE IF NOT EXISTS config ( - config_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - domain_id UUID NOT NULL, - display_name VARCHAR(255) NOT NULL, - - light_config JSONB NOT NULL, - - FOREIGN KEY (domain_id) REFERENCES domain(domain_id) ON DELETE CASCADE -); - -CREATE TABLE IF NOT EXISTS device ( - device_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), - domain_id UUID NOT NULL, - display_name VARCHAR(255) NOT NULL, - - mac VARCHAR(18) NOT NULL UNIQUE, - config_id UUID NOT NULL, - description TEXT, - timezone VARCHAR(64) NOT NULL, - - FOREIGN KEY (domain_id) REFERENCES domain(domain_id) ON DELETE CASCADE, - FOREIGN KEY (config_id) REFERENCES config(config_id) -); \ No newline at end of file diff --git a/src/database/database.rs b/src/database/database.rs new file mode 100644 index 0000000..264b569 --- /dev/null +++ b/src/database/database.rs @@ -0,0 +1,52 @@ +use std::sync::Arc; + +use crate::{Error, Result}; + +use super::transaction::DomainDatabaseTransaction; + +#[derive(Clone)] +pub struct Database { + connection_pool: Arc>, +} + +impl Database { + pub async fn try_from_uri(uri: &str) -> Result { + let pool = sqlx::postgres::PgPoolOptions::new().max_connections(5).connect(uri).await.map_err(|err| { + log::error!("Failed to connect to postgres: {err}"); + Error::DatabaseError(err.to_string()) + })?; + + Ok(Database::new(pool)) + } + + pub fn new(connection_pool: sqlx::Pool) -> Self { + Database { + connection_pool: Arc::new(connection_pool), + } + } + + pub fn for_domain(&self, domain_id: uuid::Uuid) -> DomainDatabase { + DomainDatabase::new(self.connection_pool.clone(), domain_id) + } +} + +pub struct DomainDatabase { + connection_pool: Arc>, + domain_id: uuid::Uuid, +} + +impl DomainDatabase { + pub fn new(connection_pool: Arc>, domain_id: uuid::Uuid) -> Self { + DomainDatabase { + connection_pool, + domain_id, + } + } + + pub async fn begin(&self) -> Result { + match self.connection_pool.begin().await { + Ok(tx) => Ok(DomainDatabaseTransaction::new(tx, self.domain_id.clone())), + Err(err) => Err(Error::DatabaseError(err.to_string())), + } + } +} diff --git a/src/database/mod.rs b/src/database/mod.rs new file mode 100644 index 0000000..a28be98 --- /dev/null +++ b/src/database/mod.rs @@ -0,0 +1,6 @@ +pub mod database; +pub mod models; +pub mod transaction; + +pub type Database = database::Database; +pub type DomainDatabaseTransaction = transaction::DomainDatabaseTransaction; diff --git a/src/device/device/mod.rs b/src/database/models/atmosphere_data/mod.rs similarity index 50% rename from src/device/device/mod.rs rename to src/database/models/atmosphere_data/mod.rs index 4c3714e..25a9c70 100644 --- a/src/device/device/mod.rs +++ b/src/database/models/atmosphere_data/mod.rs @@ -1,4 +1,3 @@ -pub mod errors; pub mod model; pub mod operations; -pub mod protobuf; +pub mod tonic; diff --git a/src/database/models/atmosphere_data/model.rs b/src/database/models/atmosphere_data/model.rs new file mode 100644 index 0000000..8bec2ff --- /dev/null +++ b/src/database/models/atmosphere_data/model.rs @@ -0,0 +1,19 @@ +use chrono::{DateTime, Utc}; +use sqlx::FromRow; + +use crate::types::{Celsius, RelativeHumidity}; + +#[derive(Debug, Clone, PartialEq, FromRow)] +pub struct AtmosphereDataModel { + // Timestamp for data measurement + pub observed_on: DateTime, + + // UUID of the device that produced the measurement + pub device_id: uuid::Uuid, + + // Air temperature + pub temperature: Celsius, + + // Air humidity (0-1) + pub relative_humidity: RelativeHumidity, +} diff --git a/src/database/models/atmosphere_data/operations.rs b/src/database/models/atmosphere_data/operations.rs new file mode 100644 index 0000000..283fe7f --- /dev/null +++ b/src/database/models/atmosphere_data/operations.rs @@ -0,0 +1,36 @@ +use crate::{Error, Result}; + +use crate::database::DomainDatabaseTransaction; + +use super::model::AtmosphereDataModel; + +impl DomainDatabaseTransaction { + pub async fn insert_many_atmosphere_data(&mut self, atmosphere_data: Vec) -> Result<()> { + let observed_on_list: Vec> = + atmosphere_data.iter().map(|a| a.observed_on).collect(); + let domain_id_list: Vec = atmosphere_data.iter().map(|_| self.domain_id()).collect(); + let device_id_list: Vec = atmosphere_data.iter().map(|a| a.device_id).collect(); + let temperature_list: Vec = atmosphere_data.iter().map(|a| a.temperature.into()).collect(); + let relative_humidity_list: Vec = atmosphere_data.iter().map(|a| a.relative_humidity.into()).collect(); + + let result = sqlx::query( + "INSERT INTO atmosphere ( + observed_on, domain_id, device_id, temperature, relative_humidity + ) SELECT * FROM UNNEST( + $1::timestamp[], $2::UUID[], $3::UUID[], $4::FLOAT[], $5::FLOAT[] + )", + ) + .bind(observed_on_list) + .bind(domain_id_list) + .bind(device_id_list) + .bind(temperature_list) + .bind(relative_humidity_list) + .execute(self.executor()) + .await; + + match result { + Ok(_) => Ok(()), + Err(err) => Err(Error::DatabaseError(err.to_string())), + } + } +} diff --git a/src/database/models/atmosphere_data/tonic.rs b/src/database/models/atmosphere_data/tonic.rs new file mode 100644 index 0000000..87bbe94 --- /dev/null +++ b/src/database/models/atmosphere_data/tonic.rs @@ -0,0 +1,35 @@ +use uuid::Uuid; + +use crate::ganymede; +use crate::{Error, Result}; + +use super::model::AtmosphereDataModel; + +impl TryFrom<&ganymede::v2::PushMeasurementsRequest> for Vec { + type Error = Error; + + fn try_from(value: &ganymede::v2::PushMeasurementsRequest) -> Result> { + let mut accumulator = Vec::new(); + + for measurement in value.measurements.iter() { + let device_id = Uuid::try_parse(&measurement.device_id)?; + let timestamp = measurement.timestamp.ok_or(Error::BadTimestamp)?; + let observed_on = chrono::DateTime::from_timestamp( + timestamp.seconds, + timestamp.nanos.try_into().map_err(|_| Error::BadTimestamp)?, + ).ok_or(Error::BadTimestamp)?; + + if let Some(data) = measurement.atmosphere { + let model = AtmosphereDataModel { + device_id, + observed_on, + temperature: data.temperature.try_into()?, + relative_humidity: data.relative_humidity.try_into()?, + }; + accumulator.push(model); + } + } + + Ok(accumulator) + } +} diff --git a/src/device/config/mod.rs b/src/database/models/config/mod.rs similarity index 50% rename from src/device/config/mod.rs rename to src/database/models/config/mod.rs index 4c3714e..25a9c70 100644 --- a/src/device/config/mod.rs +++ b/src/database/models/config/mod.rs @@ -1,4 +1,3 @@ -pub mod errors; pub mod model; pub mod operations; -pub mod protobuf; +pub mod tonic; diff --git a/src/database/models/config/model.rs b/src/database/models/config/model.rs new file mode 100644 index 0000000..5da12fb --- /dev/null +++ b/src/database/models/config/model.rs @@ -0,0 +1,37 @@ +use chrono::TimeDelta; +use sqlx::postgres::PgRow; +use sqlx::Row; +use uuid::Uuid; + +#[derive(Debug, Clone, PartialEq)] +pub struct ConfigModel { + // Unique identifier + pub config_id: Uuid, + + // Short display name + pub display_name: String, + + // How long the device should wait between polls + pub poll_period: TimeDelta, + + // Configuration for lights + pub light_config: serde_json::Value, +} + +impl<'r> sqlx::FromRow<'r, PgRow> for ConfigModel { + fn from_row(row: &'r PgRow) -> Result { + let config_id = row.try_get("config_id")?; + let display_name = row.try_get("display_name")?; + let light_config = row.try_get("light_config")?; + + let poll_period_pg: sqlx::postgres::types::PgInterval = row.try_get("poll_period")?; + let poll_period = chrono::TimeDelta::nanoseconds(poll_period_pg.microseconds * 1000); + + Ok(ConfigModel { + config_id, + display_name, + poll_period, + light_config, + }) + } +} diff --git a/src/database/models/config/operations.rs b/src/database/models/config/operations.rs new file mode 100644 index 0000000..f903371 --- /dev/null +++ b/src/database/models/config/operations.rs @@ -0,0 +1,255 @@ +use uuid::Uuid; + +use crate::database::DomainDatabaseTransaction; +use crate::{Error, Result}; + +use super::model::ConfigModel; + +pub enum ConfigFilter { + NameFilter(String), + None, +} + +impl DomainDatabaseTransaction { + pub async fn is_config_in_use(&mut self, config_id: &Uuid) -> Result { + let result = sqlx::query_as::<_, (bool,)>( + "SELECT EXISTS( + SELECT 1 + FROM device + WHERE config_id = $1 + )", + ) + .bind(config_id) + .fetch_one(self.executor()) + .await; + + match result { + Ok(row) => Ok(row.0), + Err(err) => Err(err.into()), + } + } + + pub async fn fetch_one_config(&mut self, config_id: &uuid::Uuid) -> Result { + let result = sqlx::query_as::<_, ConfigModel>( + "SELECT + config_id, domain_id, display_name, poll_period, light_config + FROM config + WHERE + domain_id = $1 + AND config_id = $2", + ) + .bind(self.domain_id()) + .bind(config_id) + .fetch_one(self.executor()) + .await; + + match result { + Ok(row) => Ok(row), + Err(err) => match err { + sqlx::Error::RowNotFound => Err(Error::NoSuchConfig), + _ => return Err(err.into()), + }, + } + } + + pub async fn fetch_many_config(&mut self, filter: ConfigFilter) -> Result> { + let mut query = sqlx::QueryBuilder::new( + "SELECT + config_id, domain_id, display_name, poll_period, light_config + FROM config + WHERE domain_id = ", + ); + query.push_bind(self.domain_id()); + + match filter { + ConfigFilter::NameFilter(name_filter) => { + query.push(" AND display_name LIKE ").push_bind(format!("%{name_filter}%")); + } + ConfigFilter::None => (), + } + + let result = query.build_query_as::().fetch_all(self.executor()).await; + + match result { + Ok(rows) => Ok(rows), + Err(err) => Err(err.into()), + } + } + + pub async fn insert_config(&mut self, config: ConfigModel) -> Result { + let result = sqlx::query_as::<_, (uuid::Uuid,)>( + "INSERT INTO config( + domain_id, display_name, poll_period, light_config + ) VALUES ( + $1, $2, $3, $4 + ) RETURNING config_id", + ) + .bind(self.domain_id()) + .bind(&config.display_name) + .bind(&config.poll_period) + .bind(&config.light_config) + .fetch_one(self.executor()) + .await; + + match result { + Ok(row) => Ok(row.0), + Err(err) => Err(err.into()), + } + } + + pub async fn update_config(&mut self, config: ConfigModel) -> Result { + let result = sqlx::query_as::<_, (uuid::Uuid,)>( + "UPDATE config + SET + display_name = $3, + poll_period = $4, + light_config = $5 + WHERE + domain_id = $1 + AND config_id = $2 + RETURNING config_id", + ) + .bind(self.domain_id()) + .bind(&config.config_id) + .bind(&config.display_name) + .bind(&config.poll_period) + .bind(&config.light_config) + .fetch_one(self.executor()) + .await; + + match result { + Ok(row) => Ok(row.0), + Err(sqlx::Error::RowNotFound) => Err(Error::NoSuchConfig), + Err(err) => Err(err.into()), + } + } + + pub async fn delete_config(&mut self, config_id: &uuid::Uuid) -> Result<()> { + if self.is_config_in_use(config_id).await? { + return Err(Error::ConfigInUse); + } + + let result = sqlx::query( + "DELETE FROM config + WHERE + domain_id = $1 + AND config_id = $2", + ) + .bind(self.domain_id()) + .bind(config_id) + .execute(self.executor()) + .await; + + match result { + Ok(row) => match row.rows_affected() { + 0 => Ok(()), + _ => Err(Error::NoSuchDevice), + }, + Err(err) => Err(err.into()), + } + } +} + +#[cfg(test)] +mod tests { + use chrono::TimeDelta; + use uuid::uuid; + + use crate::database::{Database, DomainDatabaseTransaction}; + + use super::*; + + type TestResult = Result<(), Box>; + + async fn start_transaction(pool: sqlx::PgPool) -> DomainDatabaseTransaction { + Database::new(pool).for_domain(Uuid::nil()).begin().await.expect("Failed to acquire transaction") + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain", "config")))] + async fn test_read_config(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + let result = transaction.fetch_one_config(&Uuid::nil()).await.unwrap(); + + assert_eq!(result.display_name, "Test Config"); + Ok(()) + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain")))] + async fn test_insert_config(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + let config = ConfigModel { + config_id: Uuid::nil(), + display_name: "config".to_string(), + poll_period: TimeDelta::hours(1), + light_config: serde_json::json!({"luminaires": []}), + }; + + let config_id = transaction.insert_config(config).await.unwrap(); + assert_ne!(config_id, Uuid::nil()); + Ok(()) + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain")))] + async fn test_read_many_config(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + let configs = vec![ + ConfigModel { + config_id: uuid!("00000000-0000-0000-0000-000000000001"), + display_name: "config-1".to_string(), + poll_period: TimeDelta::hours(1), + light_config: serde_json::json!({"luminaires": []}), + }, + ConfigModel { + config_id: uuid!("00000000-0000-0000-0000-000000000002"), + display_name: "config-2".to_string(), + poll_period: TimeDelta::hours(1), + light_config: serde_json::json!({"luminaires": []}), + }, + ]; + + for config in configs.iter() { + transaction.insert_config(config.clone()).await?; + } + + let result = transaction.fetch_many_config(ConfigFilter::None).await?; + assert_eq!(result.len(), 2); + + let result = transaction.fetch_many_config(ConfigFilter::NameFilter("config-1".into())).await?; + assert_eq!(result.len(), 1); + + let result = transaction.fetch_many_config(ConfigFilter::NameFilter("device-1".into())).await?; + assert_eq!(result.len(), 0); + + Ok(()) + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain", "config")))] + async fn test_update_config(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + let updated = ConfigModel { + config_id: Uuid::nil(), + display_name: "Different config".to_string(), + poll_period: chrono::TimeDelta::seconds(600), + light_config: serde_json::json!({"luminaires": []}), + }; + + transaction.update_config(updated.clone()).await.unwrap(); + let read = transaction.fetch_one_config(&Uuid::nil()).await.unwrap(); + + assert_eq!(updated, read); + Ok(()) + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain", "config", "device")))] + async fn test_can_remove_config_in_use(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + let err = transaction.delete_config(&Uuid::nil()).await.unwrap_err(); + assert_eq!(err, Error::ConfigInUse); + Ok(()) + } +} diff --git a/src/device/config/protobuf.rs b/src/database/models/config/tonic.rs similarity index 59% rename from src/device/config/protobuf.rs rename to src/database/models/config/tonic.rs index 268d4dc..e8a5e68 100644 --- a/src/device/config/protobuf.rs +++ b/src/database/models/config/tonic.rs @@ -1,29 +1,44 @@ use crate::ganymede; +use crate::{Error, Result}; -use super::{errors::ConfigError, model::ConfigModel}; +use super::model::ConfigModel; impl TryFrom for ConfigModel { - type Error = ConfigError; + type Error = Error; - fn try_from(value: ganymede::v2::Config) -> Result { + fn try_from(value: ganymede::v2::Config) -> Result { let config_id = match value.uid.as_str() { "" => uuid::Uuid::nil(), - _ => uuid::Uuid::try_parse(&value.uid).map_err(|_| ConfigError::InvalidConfigId)? + _ => uuid::Uuid::try_parse(&value.uid)?, + }; + + let parsed_poll_period = match value.poll_period { + Some(poll_period) => { + chrono::TimeDelta::seconds(poll_period.seconds) + + chrono::TimeDelta::nanoseconds(poll_period.nanos.into()) + } + None => return Err(Error::BadPollPeriod), + }; + + if parsed_poll_period < chrono::TimeDelta::minutes(10) { + return Err(Error::BadPollPeriod); + } + + let parsed_light_config = match value.light_config { + Some(light_config) => match serde_json::to_value(&light_config) { + Ok(json) => json, + Err(_) => { + return Err(Error::BadLightConfiguration); + } + }, + None => return Err(Error::BadLightConfiguration), }; let result = ConfigModel { config_id, - domain_id: uuid::Uuid::nil(), display_name: value.display_name, - light_config: match value.light_config { - Some(light_config) => match serde_json::to_value(&light_config) { - Ok(json) => json, - Err(_) => { - return Err(ConfigError::InvalidLightConfig); - } - }, - None => return Err(ConfigError::InvalidLightConfig), - }, + poll_period: parsed_poll_period, + light_config: parsed_light_config, }; Ok(result) @@ -31,18 +46,22 @@ impl TryFrom for ConfigModel { } impl TryFrom for ganymede::v2::Config { - type Error = ConfigError; + type Error = Error; - fn try_from(value: ConfigModel) -> Result { + fn try_from(value: ConfigModel) -> Result { let result = ganymede::v2::Config { uid: value.config_id.to_string(), display_name: value.display_name, + poll_period: Some(prost_types::Duration { + seconds: value.poll_period.num_seconds(), + nanos: value.poll_period.subsec_nanos(), + }), light_config: Some( match serde_json::from_value::(value.light_config) { Ok(config) => config, Err(err) => { log::error!("error parsing JSON from DB: {err}"); - return Err(ConfigError::InvalidLightConfig); + return Err(Error::BadLightConfiguration); } }, ), @@ -54,6 +73,8 @@ impl TryFrom for ganymede::v2::Config { #[cfg(test)] mod tests { + use uuid::uuid; + use super::*; #[test] @@ -61,18 +82,19 @@ mod tests { let config = ganymede::v2::Config { uid: uuid::uuid!("00000000-0000-0000-1234-000000000000").to_string(), display_name: "this is a config".to_string(), + poll_period: Some(prost_types::Duration { + seconds: 1800, + nanos: 0, + }), light_config: Some(ganymede::v2::LightConfig { luminaires: [].to_vec(), }), }; let model = ConfigModel::try_from(config).unwrap(); - assert_eq!( - model.config_id, - uuid::uuid!("00000000-0000-0000-1234-000000000000") - ); - assert_eq!(model.domain_id, uuid::Uuid::nil()); + assert_eq!(model.config_id, uuid::uuid!("00000000-0000-0000-1234-000000000000")); assert_eq!(model.display_name, "this is a config"); + assert_eq!(model.poll_period, chrono::TimeDelta::seconds(1800)); assert_eq!(model.light_config, serde_json::json!({"luminaires": []})); } @@ -81,13 +103,17 @@ mod tests { let config = ganymede::v2::Config { uid: "not-a-uuid".to_string(), display_name: "".to_string(), + poll_period: Some(prost_types::Duration { + seconds: 1800, + nanos: 0, + }), light_config: Some(ganymede::v2::LightConfig { luminaires: [].to_vec(), }), }; let error = ConfigModel::try_from(config).unwrap_err(); - assert_eq!(error, ConfigError::InvalidConfigId); + assert_eq!(error, Error::BadUuid); } #[test] @@ -95,24 +121,41 @@ mod tests { let config = ganymede::v2::Config { uid: uuid::uuid!("00000000-0000-0000-0000-000000000000").to_string(), display_name: "".to_string(), + poll_period: Some(prost_types::Duration { + seconds: 1800, + nanos: 0, + }), + light_config: None, + }; + + let error = ConfigModel::try_from(config).unwrap_err(); + assert_eq!(error, Error::BadLightConfiguration); + } + + #[test] + pub fn test_refuses_poll_period_below_10_minutes() { + let config = ganymede::v2::Config { + uid: uuid::uuid!("00000000-0000-0000-0000-000000000000").to_string(), + display_name: "".to_string(), + poll_period: Some(prost_types::Duration { seconds: 360, nanos: 0 }), light_config: None, }; let error = ConfigModel::try_from(config).unwrap_err(); - assert_eq!(error, ConfigError::InvalidLightConfig); + assert_eq!(error, Error::BadPollPeriod); } #[test] pub fn test_to_proto() { let config = ConfigModel { - config_id: uuid::uuid!("00000000-0000-0000-0000-000000000001"), - domain_id: uuid::uuid!("00000000-0000-0000-0000-000000000002"), + config_id: uuid!("00000000-0000-0000-0000-000000000001"), display_name: "This is a config!?".to_string(), + poll_period: chrono::TimeDelta::seconds(1800), light_config: serde_json::json!({ "luminaires": [ { "port": 1, - "usePwm": true, + "activeHigh": true, "photoPeriod": [ { "start": { "hour": 1, "minute": 2, "second": 3}, @@ -128,12 +171,19 @@ mod tests { let result = ganymede::v2::Config::try_from(config).unwrap(); assert_eq!(result.uid, "00000000-0000-0000-0000-000000000001"); assert_eq!(result.display_name, "This is a config!?"); + assert_eq!( + result.poll_period, + Some(prost_types::Duration { + seconds: 1800, + nanos: 0 + }) + ); assert_eq!( result.light_config, Some(ganymede::v2::LightConfig { luminaires: [ganymede::v2::Luminaire { port: 1, - use_pwm: true, + active_high: true, photo_period: [ganymede::v2::luminaire::DailySchedule { start: Some(ganymede::v2::Time { hour: 1, diff --git a/src/database/models/device/mod.rs b/src/database/models/device/mod.rs new file mode 100644 index 0000000..25a9c70 --- /dev/null +++ b/src/database/models/device/mod.rs @@ -0,0 +1,3 @@ +pub mod model; +pub mod operations; +pub mod tonic; diff --git a/src/database/models/device/model.rs b/src/database/models/device/model.rs new file mode 100644 index 0000000..d4229dc --- /dev/null +++ b/src/database/models/device/model.rs @@ -0,0 +1,26 @@ +use sqlx::FromRow; +use uuid::Uuid; + +use crate::types::MacAddress; + +#[derive(Debug, Clone, PartialEq, FromRow)] +pub struct DeviceModel { + // Unique identifier + pub device_id: Uuid, + + // Config identifier for this device + pub config_id: Uuid, + + // Device's MAC address. Used by devices for self-identification during poll + #[sqlx(try_from = "String")] + pub mac: MacAddress, + + // Short display name + pub display_name: String, + + // Extended user-facing description + pub description: String, + + // Timezone in tzdata format + pub timezone: String, +} diff --git a/src/database/models/device/operations.rs b/src/database/models/device/operations.rs new file mode 100644 index 0000000..4fba81b --- /dev/null +++ b/src/database/models/device/operations.rs @@ -0,0 +1,335 @@ +use chrono::{DateTime, Utc}; +use uuid::Uuid; + +use crate::database::DomainDatabaseTransaction; +use crate::types::MacAddress; +use crate::{Error, Result}; + +use super::model::DeviceModel; + +pub enum DeviceFilter { + NameFilter(String), + ConfigId(uuid::Uuid), + None, +} + +impl DomainDatabaseTransaction { + pub async fn fetch_device_id_for_mac(&mut self, mac: &MacAddress) -> Result> { + let result = sqlx::query_as::<_, (uuid::Uuid,)>( + "SELECT + device_id + FROM device + WHERE + domain_id = $1 + AND mac = $2 + LIMIT 1", + ) + .bind(self.domain_id()) + .bind(mac) + .fetch_one(self.executor()) + .await; + + match result { + Ok(row) => Ok(Some(row.0)), + Err(err) => match err { + sqlx::Error::RowNotFound => Ok(None), + _ => return Err(err.into()), + }, + } + } + + pub async fn fetch_one_device(&mut self, device_id: &Uuid) -> Result { + let result = sqlx::query_as::<_, DeviceModel>( + "SELECT + device_id, domain_id, display_name, mac, config_id, description, timezone + FROM device + WHERE + domain_id = $1 + AND device_id = $2", + ) + .bind(self.domain_id()) + .bind(device_id) + .fetch_one(self.executor()) + .await; + + match result { + Ok(model) => Ok(model), + Err(err) => match err { + sqlx::Error::RowNotFound => Err(Error::NoSuchDevice), + _ => Err(err.into()), + }, + } + } + + pub async fn fetch_many_device(&mut self, filter: DeviceFilter) -> Result> { + let mut query = sqlx::QueryBuilder::new( + "SELECT + device_id, domain_id, display_name, mac, config_id, description, timezone + FROM device + WHERE domain_id =", + ); + query.push_bind(self.domain_id()); + + match filter { + DeviceFilter::NameFilter(name_filter) => { + query.push(" AND display_name LIKE ").push_bind(format!("%{name_filter}%")); + } + DeviceFilter::ConfigId(config_id) => { + query.push(" AND config_id = ").push_bind(config_id); + } + DeviceFilter::None => (), + }; + + let result = query.build_query_as::().fetch_all(self.executor()).await; + + match result { + Ok(rows) => Ok(rows), + Err(err) => Err(err.into()), + } + } + + pub async fn insert_device(&mut self, device: DeviceModel) -> Result { + let result = sqlx::query_as::<_, (uuid::Uuid,)>( + "INSERT INTO device( + domain_id, display_name, mac, config_id, description, timezone + ) VALUES ( + $1, $2, $3, $4, $5, $6 + ) RETURNING device_id", + ) + .bind(self.domain_id()) + .bind(device.display_name) + .bind(device.mac) + .bind(device.config_id) + .bind(device.description) + .bind(device.timezone) + .fetch_one(self.executor()) + .await; + + match result { + Ok(row) => Ok(row.0), + Err(err) => match err.as_database_error() { + Some(db_err) => match db_err.constraint() { + Some("device_config_id_fkey") => Err(Error::NoSuchConfig), + Some("device_mac_unique") => Err(Error::DuplicateMacAddress), + _ => Err(Error::DatabaseError(err.to_string())), + }, + None => Err(Error::DatabaseError(err.to_string())), + }, + } + } + + pub async fn update_device(&mut self, device: DeviceModel) -> Result { + let result = sqlx::query_as::<_, (uuid::Uuid,)>( + "UPDATE device + SET + display_name = $3, + mac = $4, + config_id = $5, + description = $6, + timezone = $7 + WHERE + domain_id = $1 + AND device_id = $2 + RETURNING device_id", + ) + .bind(self.domain_id()) + .bind(&device.device_id) + .bind(&device.display_name) + .bind(&device.mac) + .bind(&device.config_id) + .bind(&device.description) + .bind(&device.timezone) + .fetch_one(self.executor()) + .await; + + match result { + Ok(row) => Ok(row.0), + Err(sqlx::Error::RowNotFound) => Err(Error::NoSuchDevice), + Err(err) => match err.as_database_error() { + Some(db_err) => match db_err.constraint() { + Some("device_config_id_fkey") => Err(Error::NoSuchConfig), + Some("device_mac_unique") => Err(Error::DuplicateMacAddress), + _ => Err(Error::DatabaseError(err.to_string())), + }, + None => Err(Error::DatabaseError(err.to_string())), + }, + } + } + + pub async fn delete_device(&mut self, device_id: &uuid::Uuid) -> Result<()> { + let result = sqlx::query( + "DELETE FROM device + WHERE + domain_id = $1 + AND device_id = $2", + ) + .bind(self.domain_id()) + .bind(device_id) + .execute(self.executor()) + .await; + + match result { + Ok(row) => match row.rows_affected() { + 0 => Ok(()), + _ => Err(Error::NoSuchDevice), + }, + Err(err) => Err(err.into()), + } + } + + pub async fn update_last_poll(&mut self, device_id: &uuid::Uuid, last_poll: DateTime) -> Result<()> { + let result = sqlx::query( + " + UPDATE device + SET + last_poll = $3 + WHERE + domain_id = $1 + AND device_id = $2", + ) + .bind(self.domain_id()) + .bind(device_id) + .bind(last_poll) + .execute(self.executor()) + .await; + + match result { + Ok(row) => match row.rows_affected() { + 0 => Ok(()), + _ => Err(Error::NoSuchDevice), + }, + Err(err) => Err(err.into()), + } + } +} + +#[cfg(test)] +mod tests { + use uuid::uuid; + + use crate::database::Database; + use crate::types::MacAddress; + + use super::*; + + type TestResult = Result<(), Box>; + + async fn start_transaction(pool: sqlx::PgPool) -> DomainDatabaseTransaction { + Database::new(pool).for_domain(Uuid::nil()).begin().await.expect("Failed to acquire transaction") + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain", "config")))] + async fn test_insert_device(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + let device = DeviceModel { + device_id: Uuid::nil(), + display_name: "This is a device!".to_string(), + mac: MacAddress::try_from("00:00:00:00:00:00".to_string()).unwrap(), + config_id: Uuid::nil(), + description: "This is a description".to_string(), + timezone: "America/Montreal".to_string(), + }; + + let result = transaction.insert_device(device).await.unwrap(); + assert_ne!(result, Uuid::nil()); + Ok(()) + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain")))] + async fn test_insert_device_no_such_config(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + // Same definition as before, but we haven't loaded the config fixture + let device = DeviceModel { + device_id: Uuid::nil(), + display_name: "This is a device!".to_string(), + mac: MacAddress::try_from("00:00:00:00:00:00".to_string()).unwrap(), + config_id: Uuid::nil(), + description: "This is a description".to_string(), + timezone: "America/Montreal".to_string(), + }; + + let result = transaction.insert_device(device).await.unwrap_err(); + assert_eq!(result, Error::NoSuchConfig); + Ok(()) + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain", "config", "device")))] + async fn test_insert_device_duplicate_mac(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + // Same definition as before, but we already use the MAC address in the device fixture + let device = DeviceModel { + device_id: Uuid::nil(), + display_name: "This is a device!".to_string(), + mac: MacAddress::try_from("00:00:00:00:00:00".to_string()).unwrap(), + config_id: Uuid::nil(), + description: "This is a description".to_string(), + timezone: "America/Montreal".to_string(), + }; + + let result = transaction.insert_device(device).await.unwrap_err(); + assert_eq!(result, Error::DuplicateMacAddress); + Ok(()) + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain", "config", "device")))] + async fn test_update_device(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + let updated = DeviceModel { + device_id: Uuid::nil(), + display_name: "Different device".to_string(), + description: "Yup totally different".to_string(), + mac: MacAddress::try_from("00:00:00:00:00:00".to_string()).unwrap(), + config_id: Uuid::nil(), + timezone: "America/Montreal".to_string(), + }; + + let returned = transaction.update_device(updated.clone()).await.unwrap(); + let read = transaction.fetch_one_device(&returned).await.unwrap(); + + assert_eq!(updated, read); + Ok(()) + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain", "config", "device")))] + async fn test_update_device_no_such_config(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + let updated = DeviceModel { + device_id: Uuid::nil(), + display_name: "Different device".to_string(), + description: "Yup totally different".to_string(), + mac: MacAddress::try_from("00:00:00:00:00:00".to_string()).unwrap(), + config_id: uuid!("00000000-0000-0000-0000-000000000001"), + timezone: "America/Montreal".to_string(), + }; + + let result = transaction.update_device(updated).await.unwrap_err(); + assert_eq!(result, Error::NoSuchConfig); + Ok(()) + } + + #[sqlx::test(fixtures(path = "../../../../fixtures", scripts("domain", "config", "device")))] + async fn test_update_device_duplicate_mac(pool: sqlx::PgPool) -> TestResult { + let mut transaction = start_transaction(pool).await; + + let mut device = DeviceModel { + device_id: Uuid::nil(), + display_name: "Different device".to_string(), + description: "Yup totally different".to_string(), + mac: MacAddress::try_from("00:00:00:00:00:01".to_string())?, + config_id: Uuid::nil(), + timezone: "America/Montreal".to_string(), + }; + + device.device_id = transaction.insert_device(device.clone()).await.unwrap(); + device.mac = MacAddress::try_from("00:00:00:00:00:00".to_string())?; + + let result = transaction.update_device(device).await.unwrap_err(); + assert_eq!(result, Error::DuplicateMacAddress); + Ok(()) + } +} diff --git a/src/device/device/protobuf.rs b/src/database/models/device/tonic.rs similarity index 62% rename from src/device/device/protobuf.rs rename to src/database/models/device/tonic.rs index 4eb568a..16c1f8c 100644 --- a/src/device/device/protobuf.rs +++ b/src/database/models/device/tonic.rs @@ -1,28 +1,26 @@ +use uuid::Uuid; + use crate::ganymede; +use crate::{Error, Result}; -use super::{errors::DeviceError, model::DeviceModel}; +use super::model::DeviceModel; impl TryFrom for DeviceModel { - type Error = DeviceError; - - fn try_from(value: ganymede::v2::Device) -> Result { - if value.timezone.parse::().is_err() { - return Err(DeviceError::InvalidTimezone); - }; + type Error = Error; + fn try_from(value: ganymede::v2::Device) -> Result { let device_id = match value.uid.as_str() { - "" => uuid::Uuid::nil(), - _ => uuid::Uuid::try_parse(&value.uid).map_err(|_| DeviceError::InvalidDeviceId)? + "" => Uuid::nil(), + _ => Uuid::try_parse(&value.uid)?, }; let result = DeviceModel { device_id, display_name: value.display_name, - mac: value.mac.try_into().map_err(|_| DeviceError::InvalidMac)?, - config_id: uuid::Uuid::try_parse(&value.config_uid) - .map_err(|_| DeviceError::InvalidConfigId)?, + mac: value.mac.try_into()?, + config_id: Uuid::try_parse(&value.config_uid)?, description: value.description, - timezone: value.timezone, + timezone: value.timezone.parse::()?.to_string(), }; Ok(result) @@ -30,12 +28,12 @@ impl TryFrom for DeviceModel { } impl TryFrom for ganymede::v2::Device { - type Error = DeviceError; + type Error = Error; - fn try_from(value: DeviceModel) -> Result { + fn try_from(value: DeviceModel) -> Result { let result = ganymede::v2::Device { uid: value.device_id.to_string(), - mac: value.mac.try_into().map_err(|_| DeviceError::InvalidMac)?, + mac: value.mac.into(), display_name: value.display_name, description: value.description, timezone: value.timezone, @@ -48,14 +46,16 @@ impl TryFrom for ganymede::v2::Device { #[cfg(test)] mod tests { - use crate::types::mac; + use uuid::uuid; + + use crate::types::MacAddress; use super::*; #[test] fn test_to_model() { - let device_uid = uuid::Uuid::new_v4(); - let config_uid = uuid::Uuid::new_v4(); + let device_uid = Uuid::new_v4(); + let config_uid = Uuid::new_v4(); let device = ganymede::v2::Device { uid: device_uid.to_string(), @@ -69,7 +69,7 @@ mod tests { let model = DeviceModel::try_from(device).unwrap(); assert_eq!(model.device_id, device_uid); assert_eq!(model.config_id, config_uid); - assert_eq!(model.mac, mac::Mac::try_from("aa:bb:cc:dd:ee:ff").unwrap()); + assert_eq!(model.mac, MacAddress::try_from("aa:bb:cc:dd:ee:ff").unwrap()); assert_eq!(model.display_name, "I am a device".to_string()); assert_eq!(model.description, "Watch how I pour".to_string()); assert_eq!(model.timezone, "America/Caracas"); @@ -78,16 +78,16 @@ mod tests { #[test] fn test_refuses_invalid_timezone() { let device = ganymede::v2::Device { - uid: uuid::Uuid::nil().to_string(), + uid: Uuid::nil().to_string(), mac: "00:00:00:00:00:00".to_string(), display_name: "".to_string(), description: "".to_string(), timezone: "Rohan/Edoras".to_string(), - config_uid: uuid::Uuid::nil().to_string(), + config_uid: Uuid::nil().to_string(), }; let error = DeviceModel::try_from(device).unwrap_err(); - assert_eq!(error, DeviceError::InvalidTimezone); + assert_eq!(error, Error::BadTimezone); } #[test] @@ -98,11 +98,11 @@ mod tests { display_name: "".to_string(), description: "".to_string(), timezone: "America/Montreal".to_string(), - config_uid: uuid::Uuid::nil().to_string(), + config_uid: Uuid::nil().to_string(), }; let error = DeviceModel::try_from(device).unwrap_err(); - assert_eq!(error, DeviceError::InvalidDeviceId); + assert_eq!(error, Error::BadUuid); } #[test] @@ -113,17 +113,17 @@ mod tests { display_name: "".to_string(), description: "".to_string(), timezone: "America/Montreal".to_string(), - config_uid: uuid::Uuid::nil().to_string(), + config_uid: Uuid::nil().to_string(), }; let device = DeviceModel::try_from(device).unwrap(); - assert_eq!(device.device_id, uuid::Uuid::nil()); + assert_eq!(device.device_id, Uuid::nil()); } #[test] fn test_refuses_invalid_config_uid() { let device = ganymede::v2::Device { - uid: uuid::Uuid::nil().to_string(), + uid: Uuid::nil().to_string(), mac: "00:00:00:00:00:00".to_string(), display_name: "".to_string(), description: "".to_string(), @@ -132,31 +132,31 @@ mod tests { }; let error = DeviceModel::try_from(device).unwrap_err(); - assert_eq!(error, DeviceError::InvalidConfigId); + assert_eq!(error, Error::BadUuid); } #[test] fn test_refuses_invalid_mac() { let device = ganymede::v2::Device { - uid: uuid::Uuid::nil().to_string(), + uid: Uuid::nil().to_string(), mac: "".to_string(), display_name: "".to_string(), description: "".to_string(), timezone: "America/Montreal".to_string(), - config_uid: uuid::Uuid::nil().to_string(), + config_uid: Uuid::nil().to_string(), }; let error = DeviceModel::try_from(device).unwrap_err(); - assert_eq!(error, DeviceError::InvalidMac); + assert_eq!(error, Error::BadMacAddress); } #[test] fn test_to_proto() { let device = DeviceModel { - device_id: uuid::uuid!("00000000-0000-0000-0000-000000000001"), + device_id: uuid!("00000000-0000-0000-0000-000000000001"), display_name: "I am a device".to_string(), - mac: mac::Mac::try_from("aa:bb:cc:dd:ee:ff".to_string()).unwrap(), - config_id: uuid::uuid!("ffffffff-ffff-ffff-ffff-ffffffffffff"), + mac: MacAddress::try_from("aa:bb:cc:dd:ee:ff".to_string()).unwrap(), + config_id: uuid!("ffffffff-ffff-ffff-ffff-ffffffffffff"), description: "Short and stout".to_string(), timezone: "America/Caracas".to_string(), }; @@ -169,23 +169,4 @@ mod tests { assert_eq!(result.timezone, "America/Caracas"); assert_eq!(result.config_uid, "ffffffff-ffff-ffff-ffff-ffffffffffff"); } - - // #[test] - // fn test_computes_correct_timezone_offset() { - // let mut device = DeviceModel { - // device_id: uuid::Uuid::nil(), - // display_name: "".to_string(), - // mac: mac::Mac::try_from("00:00:00:00:00:00".to_string()).unwrap(), - // config_id: uuid::Uuid::nil(), - // description: "".to_string(), - // timezone: "America/Caracas".to_string(), - // }; - - // let result = ganymede::v2::Device::try_from(device.clone()).unwrap(); - // assert_eq!(result.timezone_offset_minutes, -4 * 60); - - // device.timezone = "Asia/Shanghai".to_string(); - // let result = ganymede::v2::Device::try_from(device.clone()).unwrap(); - // assert_eq!(result.timezone_offset_minutes, 8 * 60); - // } } diff --git a/src/database/models/mod.rs b/src/database/models/mod.rs new file mode 100644 index 0000000..0738f6c --- /dev/null +++ b/src/database/models/mod.rs @@ -0,0 +1,6 @@ +pub mod atmosphere_data; +pub mod config; +pub mod device; + +pub type DeviceModel = device::model::DeviceModel; +pub type AtmosphereDataModel = atmosphere_data::model::AtmosphereDataModel; diff --git a/src/database/transaction.rs b/src/database/transaction.rs new file mode 100644 index 0000000..02f6024 --- /dev/null +++ b/src/database/transaction.rs @@ -0,0 +1,36 @@ +use crate::{Error, Result}; + +#[derive(Debug)] +pub struct DomainDatabaseTransaction { + transaction: sqlx::Transaction<'static, sqlx::Postgres>, + domain_id: uuid::Uuid, +} + +impl DomainDatabaseTransaction { + pub fn new(transaction: sqlx::Transaction<'static, sqlx::Postgres>, domain_id: uuid::Uuid) -> Self { + DomainDatabaseTransaction { transaction, domain_id } + } + + pub fn domain_id(&self) -> uuid::Uuid { + self.domain_id.clone() + } + + pub fn executor(&mut self) -> &mut sqlx::PgConnection { + &mut *self.transaction + } + + pub async fn commit(self) -> Result<()> { + match self.transaction.commit().await { + Ok(result) => Ok(result), + Err(err) => Err(Error::DatabaseError(err.to_string())), + } + } + + #[expect(unused)] + pub async fn rollback(self) -> Result<()> { + match self.transaction.rollback().await { + Ok(result) => Ok(result), + Err(err) => Err(Error::DatabaseError(err.to_string())), + } + } +} diff --git a/src/device/config/errors.rs b/src/device/config/errors.rs deleted file mode 100644 index 5737a2b..0000000 --- a/src/device/config/errors.rs +++ /dev/null @@ -1,25 +0,0 @@ -#[derive(Debug, PartialEq)] -pub enum ConfigError { - InvalidConfigId, - InvalidLightConfig, - NoSuchConfig, - ConfigInUse, - DatabaseError(String), -} - -impl From for tonic::Status { - fn from(value: ConfigError) -> Self { - match value { - ConfigError::InvalidConfigId => tonic::Status::invalid_argument("invalid config id"), - ConfigError::NoSuchConfig => tonic::Status::not_found("no such config"), - ConfigError::InvalidLightConfig => { - tonic::Status::invalid_argument("invalid light config") - } - ConfigError::ConfigInUse => tonic::Status::failed_precondition("config is in use"), - ConfigError::DatabaseError(err) => { - log::error!("{err}"); - tonic::Status::internal("internal error") - }, - } - } -} diff --git a/src/device/config/model.rs b/src/device/config/model.rs deleted file mode 100644 index 3173e85..0000000 --- a/src/device/config/model.rs +++ /dev/null @@ -1,9 +0,0 @@ -use sqlx::FromRow; - -#[derive(Debug, Clone, FromRow)] -pub struct ConfigModel { - pub config_id: uuid::Uuid, - pub domain_id: uuid::Uuid, - pub display_name: String, - pub light_config: serde_json::Value, -} diff --git a/src/device/config/operations.rs b/src/device/config/operations.rs deleted file mode 100644 index e5f391f..0000000 --- a/src/device/config/operations.rs +++ /dev/null @@ -1,162 +0,0 @@ -use crate::device::database::DomainDatabase; - -use super::{errors::ConfigError, model::ConfigModel}; - -impl<'a> DomainDatabase<'a> { - pub async fn exists_config(&self, config_id: &uuid::Uuid) -> Result { - let (row,) = sqlx::query_as::<_, (bool,)>( - "SELECT EXISTS (SELECT 1 FROM config WHERE domain_id = $1 AND config_id = $2)", - ) - .bind(self.domain_id()) - .bind(config_id) - .fetch_one(self.pool()) - .await - .map_err(|err| ConfigError::DatabaseError(err.to_string()))?; - Ok(row) - } - - pub async fn insert_config(&self, config: &ConfigModel) -> Result { - let row = sqlx::query_as::<_, (uuid::Uuid,)>("INSERT INTO config(domain_id, display_name, light_config) VALUES ($1, $2, $3) RETURNING config_id") - .bind(self.domain_id()) - .bind(&config.display_name) - .bind(&config.light_config) - .fetch_one(self.pool()) - .await - .map_err(|err| ConfigError::DatabaseError(err.to_string()))?; - - self.fetch_one_config(&row.0).await - } - - pub async fn update_config(&self, config: &ConfigModel) -> Result { - let row = match sqlx::query_as::<_, (uuid::Uuid,)>("UPDATE config SET display_name = $3, light_config = $4 WHERE domain_id = $1 AND config_id = $2 RETURNING config_id") - .bind(self.domain_id()) - .bind(&config.config_id) - .bind(&config.display_name) - .bind(&config.light_config) - .fetch_one(self.pool()) - .await - { - Ok(row) => row, - Err(err) => match err { - sqlx::Error::RowNotFound => return Err(ConfigError::NoSuchConfig), - _ => return Err(ConfigError::DatabaseError(err.to_string())), - }, - }; - - self.fetch_one_config(&row.0).await - } - - pub async fn fetch_one_config( - &self, - config_id: &uuid::Uuid, - ) -> Result { - let row = match sqlx::query_as::<_, ConfigModel>("SELECT config_id, domain_id, display_name, light_config FROM config WHERE domain_id = $1 AND config_id = $2") - .bind(self.domain_id()) - .bind(config_id) - .fetch_one(self.pool()) - .await - { - Ok(row) => row, - Err(err) => match err { - sqlx::Error::RowNotFound => return Err(ConfigError::NoSuchConfig), - _ => return Err(ConfigError::DatabaseError(err.to_string())), - }, - }; - - Ok(row) - } - - pub async fn fetch_many_config( - &self, - name_filter: Option, - ) -> Result, ConfigError> { - let mut query = sqlx::QueryBuilder::new("SELECT config_id, domain_id, display_name, light_config FROM config WHERE domain_id = "); - query.push_bind(self.domain_id()); - - if let Some(name_filter) = name_filter { - query - .push(" AND display_name LIKE ") - .push_bind(format!("%{name_filter}%")); - } - - let rows = query - .build_query_as::() - .fetch_all(self.pool()) - .await - .map_err(|err| ConfigError::DatabaseError(err.to_string()))?; - Ok(rows) - } - - pub async fn delete_config(&self, config_id: &uuid::Uuid) -> Result<(), ConfigError> { - let (is_used,) = sqlx::query_as::<_, (bool,)>("SELECT EXISTS(SELECT 1 FROM device WHERE config_id = $1)") - .bind(config_id) - .fetch_one(self.pool()) - .await - .map_err(|err| ConfigError::DatabaseError(err.to_string()))?; - - if is_used { - return Err(ConfigError::ConfigInUse); - } - - let result = sqlx::query("DELETE FROM config WHERE domain_id = $1 AND config_id = $2") - .bind(self.domain_id()) - .bind(config_id) - .execute(self.pool()) - .await - .map_err(|err| ConfigError::DatabaseError(err.to_string()))?; - - match result.rows_affected() { - 0 => Err(ConfigError::NoSuchConfig), - _ => Ok(()), - } - } -} - -#[cfg(test)] -mod tests { - use crate::{device::device::model::DeviceModel, types::mac}; - - use super::*; - - async fn insert_test_domain(pool: &sqlx::PgPool) -> sqlx::Result<()> { - sqlx::query( - "INSERT INTO domain VALUES ('00000000-0000-0000-0000-000000000000', 'root', '')", - ) - .execute(pool) - .await?; - Ok(()) - } - - fn create_test_config() -> ConfigModel { - ConfigModel { - config_id: uuid::Uuid::nil(), - domain_id: uuid::Uuid::nil(), - display_name: "config".to_string(), - light_config: serde_json::json!({"luminaires": []}), - } - } - - fn create_test_device(config_id: uuid::Uuid) -> DeviceModel { - DeviceModel { - device_id: uuid::Uuid::nil(), - display_name: "This is a device!".to_string(), - mac: mac::Mac::try_from("00:00:00:00:00:00".to_string()).unwrap(), - config_id: config_id, - description: "This is a description".to_string(), - timezone: "America/Montreal".to_string(), - } - } - - #[sqlx::test] - async fn test_can_remove_config_in_use(pool: sqlx::PgPool) { - let database = DomainDatabase::new(&pool, uuid::Uuid::nil()); - - insert_test_domain(&pool).await.unwrap(); - - let config = database.insert_config(&create_test_config()).await.unwrap(); - let _ = database.insert_device(create_test_device(config.config_id.clone())).await.unwrap(); - - let err = database.delete_config(&config.config_id).await.unwrap_err(); - assert_eq!(err, ConfigError::ConfigInUse); - } -} \ No newline at end of file diff --git a/src/device/database.rs b/src/device/database.rs deleted file mode 100644 index e524723..0000000 --- a/src/device/database.rs +++ /dev/null @@ -1,21 +0,0 @@ -pub struct DomainDatabase<'a> { - connection_pool: &'a sqlx::Pool, - domain_id: uuid::Uuid, -} - -impl<'a> DomainDatabase<'a> { - pub fn new(connection_pool: &'a sqlx::Pool, domain_id: uuid::Uuid) -> Self { - DomainDatabase { - connection_pool: connection_pool, - domain_id: domain_id, - } - } - - pub fn pool(&self) -> &'a sqlx::Pool { - &self.connection_pool - } - - pub fn domain_id(&self) -> &uuid::Uuid { - &self.domain_id - } -} diff --git a/src/device/device/errors.rs b/src/device/device/errors.rs deleted file mode 100644 index 5bebfec..0000000 --- a/src/device/device/errors.rs +++ /dev/null @@ -1,31 +0,0 @@ -#[derive(Debug, PartialEq)] -pub enum DeviceError { - InvalidMac, - InvalidTimezone, - InvalidDeviceId, - InvalidConfigId, - NoSuchDevice, - NoSuchConfig, - MacConflict, - DatabaseError(String), -} - -impl From for tonic::Status { - fn from(value: DeviceError) -> Self { - match value { - DeviceError::InvalidConfigId => tonic::Status::invalid_argument("invalid config id"), - DeviceError::InvalidDeviceId => tonic::Status::invalid_argument("invalid device id"), - DeviceError::InvalidTimezone => tonic::Status::invalid_argument("invalid timezone"), - DeviceError::InvalidMac => tonic::Status::invalid_argument("invalid mac address"), - DeviceError::NoSuchDevice => tonic::Status::not_found("no such device"), - DeviceError::NoSuchConfig => tonic::Status::not_found("no such config"), - DeviceError::MacConflict => { - tonic::Status::invalid_argument("mac address already in use") - } - DeviceError::DatabaseError(err) => { - log::error!("{err}"); - tonic::Status::internal("internal error") - }, - } - } -} diff --git a/src/device/device/model.rs b/src/device/device/model.rs deleted file mode 100644 index ea54f74..0000000 --- a/src/device/device/model.rs +++ /dev/null @@ -1,14 +0,0 @@ -use sqlx::FromRow; - -use crate::types::mac; - -#[derive(Debug, Clone, PartialEq, FromRow)] -pub struct DeviceModel { - pub device_id: uuid::Uuid, - pub display_name: String, - #[sqlx(try_from = "String")] - pub mac: mac::Mac, - pub config_id: uuid::Uuid, - pub description: String, - pub timezone: String, -} diff --git a/src/device/device/operations.rs b/src/device/device/operations.rs deleted file mode 100644 index 2a822e8..0000000 --- a/src/device/device/operations.rs +++ /dev/null @@ -1,303 +0,0 @@ -use crate::device::{config::errors::ConfigError, database::DomainDatabase}; -use crate::types::mac::Mac; - -use super::{errors::DeviceError, model::DeviceModel}; - -pub enum DeviceFilter { - NameFilter(String), - ConfigId(uuid::Uuid), - None, -} - -impl<'a> DomainDatabase<'a> { - pub async fn fetch_device_id_for_mac(&self, mac: &Mac) -> Result, DeviceError> { - let device_id = match sqlx::query_as::<_, (uuid::Uuid,)>("SELECT device_id FROM device WHERE domain_id = $1 AND mac = $2 LIMIT 1") - .bind(self.domain_id()) - .bind(mac) - .fetch_one(self.pool()) - .await - { - Ok(row) => Some(row.0), - Err(err) => match err { - sqlx::Error::RowNotFound => None, - _ => return Err(DeviceError::DatabaseError(err.to_string())), - } - }; - - Ok(device_id) - } - - pub async fn insert_device(&self, device: DeviceModel) -> Result { - if let Some(_) = self.fetch_device_id_for_mac(&device.mac).await? { - return Err(DeviceError::MacConflict); - } - - match self.exists_config(&device.config_id).await { - Ok(true) => (), - Ok(false) => return Err(DeviceError::NoSuchConfig), - Err(ConfigError::DatabaseError(err)) => return Err(DeviceError::DatabaseError(err)), - _ => return Err(DeviceError::DatabaseError("unknown error".to_string())), - }; - - let (device_id,) = sqlx::query_as::<_, (uuid::Uuid,)>("INSERT INTO device(domain_id, display_name, mac, config_id, description, timezone) VALUES ($1, $2, $3, $4, $5, $6) RETURNING device_id") - .bind(self.domain_id()) - .bind(device.display_name) - .bind(device.mac) - .bind(device.config_id) - .bind(device.description) - .bind(device.timezone) - .fetch_one(self.pool()) - .await - .map_err(|err| DeviceError::DatabaseError(err.to_string()))?; - - self.fetch_one_device(device_id) - .await - } - - pub async fn update_device(&self, device: DeviceModel) -> Result { - if let Some(existing_id) = self.fetch_device_id_for_mac(&device.mac).await? { - if existing_id != device.device_id { - return Err(DeviceError::MacConflict); - } - } - - match self.exists_config(&device.config_id).await { - Ok(true) => (), - Ok(false) => return Err(DeviceError::NoSuchConfig), - Err(ConfigError::DatabaseError(err)) => return Err(DeviceError::DatabaseError(err)), - _ => return Err(DeviceError::DatabaseError("unknown error".to_string())), - }; - - let (device_id,) = match sqlx::query_as::<_, (uuid::Uuid,)>("UPDATE device SET display_name = $3, mac = $4, config_id = $5, description = $6, timezone = $7 WHERE domain_id = $1 AND device_id = $2 RETURNING device_id") - .bind(self.domain_id()) - .bind(device.device_id) - .bind(device.display_name) - .bind(device.mac) - .bind(device.config_id) - .bind(device.description) - .bind(device.timezone) - .fetch_one(self.pool()) - .await - { - Ok(row) => row, - Err(err) => match err { - sqlx::Error::RowNotFound => return Err(DeviceError::NoSuchDevice), - _ => return Err(DeviceError::DatabaseError(err.to_string())), - }, - }; - - self.fetch_one_device(device_id) - .await - } - - pub async fn fetch_one_device( - &self, - device_id: uuid::Uuid, - ) -> Result { - let device = match sqlx::query_as::<_, DeviceModel>("SELECT device_id, domain_id, display_name, mac, config_id, description, timezone FROM device WHERE domain_id = $1 AND device_id = $2") - .bind(self.domain_id()) - .bind(device_id) - .fetch_one(self.pool()) - .await - { - Ok(device) => device, - Err(err) => match err { - sqlx::Error::RowNotFound => return Err(DeviceError::NoSuchDevice), - _ => return Err(DeviceError::DatabaseError(err.to_string())), - }, - }; - - Ok(device) - } - - pub async fn fetch_many_device( - &self, - filter: DeviceFilter, - ) -> Result, DeviceError> { - let mut query = sqlx::QueryBuilder::new("SELECT device_id, domain_id, display_name, mac, config_id, description, timezone FROM device WHERE domain_id = "); - query.push_bind(self.domain_id()); - - match filter { - DeviceFilter::NameFilter(name_filter) => { - query - .push(" AND display_name LIKE ") - .push_bind(format!("%{name_filter}%")); - } - DeviceFilter::ConfigId(config_id) => { - query.push(" AND config_id = ").push_bind(config_id); - } - DeviceFilter::None => (), - }; - - let devices = query - .build_query_as::() - .fetch_all(self.pool()) - .await - .map_err(|err| DeviceError::DatabaseError(err.to_string()))?; - - Ok(devices) - } - - pub async fn delete_device(&self, device_id: &uuid::Uuid) -> Result<(), DeviceError> { - let result = sqlx::query("DELETE FROM device WHERE domain_id = $1 AND device_id = $2") - .bind(self.domain_id()) - .bind(device_id) - .execute(self.pool()) - .await - .map_err(|err| DeviceError::DatabaseError(err.to_string()))?; - - if result.rows_affected() == 0 { - return Err(DeviceError::NoSuchDevice); - } - - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use crate::{device::config::model::ConfigModel, types::mac}; - - use super::*; - - type TestResult = Result<(), Box>; - - async fn insert_test_domain(pool: &sqlx::PgPool) -> sqlx::Result<()> { - sqlx::query( - "INSERT INTO domain VALUES ('00000000-0000-0000-0000-000000000000', 'root', '')", - ) - .execute(pool) - .await?; - Ok(()) - } - - fn create_test_config() -> ConfigModel { - ConfigModel { - config_id: uuid::Uuid::nil(), - domain_id: uuid::Uuid::nil(), - display_name: "config".to_string(), - light_config: serde_json::json!({"luminaires": []}), - } - } - - fn create_test_device(config_id: uuid::Uuid) -> DeviceModel { - DeviceModel { - device_id: uuid::Uuid::nil(), - display_name: "This is a device!".to_string(), - mac: mac::Mac::try_from("00:00:00:00:00:00".to_string()).unwrap(), - config_id: config_id, - description: "This is a description".to_string(), - timezone: "America/Montreal".to_string(), - } - } - - async fn insert_test_config( - pool: &sqlx::PgPool, - ) -> Result> { - let database = DomainDatabase::new(&pool, uuid::Uuid::nil()); - Ok(database - .insert_config(&create_test_config()) - .await - .unwrap() - .config_id) - } - - #[sqlx::test] - async fn test_insert_device(pool: sqlx::PgPool) -> TestResult { - let database = DomainDatabase::new(&pool, uuid::Uuid::nil()); - - insert_test_domain(&pool).await?; - let device = create_test_device(insert_test_config(&pool).await?); - - let result = database.insert_device(device).await.unwrap(); - - assert_ne!(result.device_id, uuid::Uuid::nil()); - Ok(()) - } - - #[sqlx::test] - async fn test_insert_device_no_such_config(pool: sqlx::PgPool) -> TestResult { - let database = DomainDatabase::new(&pool, uuid::Uuid::nil()); - - insert_test_domain(&pool).await?; - let device = create_test_device(uuid::Uuid::nil()); - - let error = database.insert_device(device).await.unwrap_err(); - assert_eq!(error, DeviceError::NoSuchConfig); - Ok(()) - } - - #[sqlx::test] - async fn test_insert_device_duplicate_mac(pool: sqlx::PgPool) -> TestResult { - env_logger::init(); - let database = DomainDatabase::new(&pool, uuid::Uuid::nil()); - - insert_test_domain(&pool).await?; - let device = create_test_device(insert_test_config(&pool).await?); - - let _ = database.insert_device(device.clone()).await; - let error = database.insert_device(device).await.unwrap_err(); - - assert_eq!(error, DeviceError::MacConflict); - Ok(()) - } - - #[sqlx::test] - async fn test_update_device(pool: sqlx::PgPool) -> TestResult { - let database = DomainDatabase::new(&pool, uuid::Uuid::nil()); - - insert_test_domain(&pool).await?; - let device = create_test_device(insert_test_config(&pool).await?); - - let updated = DeviceModel { - display_name: "Different device".to_string(), - description: "Yup totally different".to_string(), - ..database.insert_device(device).await.unwrap() - }; - - let result = database.update_device(updated).await; - assert!(result.is_ok()); - Ok(()) - } - - #[sqlx::test] - async fn test_update_device_no_such_config(pool: sqlx::PgPool) -> TestResult { - let database = DomainDatabase::new(&pool, uuid::Uuid::nil()); - - insert_test_domain(&pool).await?; - let device = create_test_device(insert_test_config(&pool).await?); - - let updated = DeviceModel { - config_id: uuid::Uuid::nil(), - ..database.insert_device(device).await.unwrap() - }; - - let error = database.update_device(updated).await.unwrap_err(); - assert_eq!(error, DeviceError::NoSuchConfig); - Ok(()) - } - - #[sqlx::test] - async fn test_update_device_duplicate_mac(pool: sqlx::PgPool) -> TestResult { - let database = DomainDatabase::new(&pool, uuid::Uuid::nil()); - - insert_test_domain(&pool).await?; - - let original = create_test_device(insert_test_config(&pool).await?); - let _ = database.insert_device(original).await.unwrap(); - - let device = DeviceModel { - mac: mac::Mac::try_from("aa:bb:cc:dd:ee:ff".to_string()).unwrap(), - ..create_test_device(insert_test_config(&pool).await?) - }; - - let updated = DeviceModel { - mac: mac::Mac::try_from("00:00:00:00:00:00".to_string()).unwrap(), // Already taken by original - ..database.insert_device(device).await.unwrap() - }; - - let error = database.update_device(updated).await.unwrap_err(); - assert_eq!(error, DeviceError::MacConflict); - Ok(()) - } -} diff --git a/src/device/mod.rs b/src/device/mod.rs deleted file mode 100644 index 899064a..0000000 --- a/src/device/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -mod config; -mod database; -mod device; -pub mod service; diff --git a/src/ganymede.rs b/src/ganymede.rs index 9fb1924..639a5ee 100644 --- a/src/ganymede.rs +++ b/src/ganymede.rs @@ -2,6 +2,5 @@ pub mod v2 { tonic::include_proto!("ganymede.v2"); - pub(crate) const FILE_DESCRIPTOR_SET: &[u8] = - tonic::include_file_descriptor_set!("ganymede.v2"); + pub(crate) const FILE_DESCRIPTOR_SET: &[u8] = tonic::include_file_descriptor_set!("ganymede.v2"); } diff --git a/src/main.rs b/src/main.rs index 6cf62b9..3007ed3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,59 +1,51 @@ -use sqlx::postgres::PgPoolOptions; +use crate::result::{Error, Result}; use tonic::transport::Server; -use crate::device::service::DeviceService; -use ganymede::v2::device_service_server::DeviceServiceServer; +use crate::database::database::Database; +use crate::ganymede::v2::{ + device_service_server::DeviceServiceServer, measurements_service_server::MeasurementsServiceServer, +}; +use crate::services::{DeviceService, MeasurementsService}; -use crate::measurements::service::MeasurementsService; -use ganymede::v2::measurements_service_server::MeasurementsServiceServer; +mod database; +mod ganymede; +mod result; +mod services; +mod types; -pub mod auth; -pub mod device; -pub mod ganymede; -pub mod types; -pub mod measurements; +#[derive(clap::Parser, Debug)] +#[command(version, about, long_about = None)] +struct Arguments { + // Path to the configuration file + #[arg(short, long, default_value_t = String::from("Ganymede.toml"))] + pub config: String, +} #[derive(serde::Deserialize)] -struct Settings { +struct RuntimeConfiguration { pub postgres_uri: String, pub port: u16, } #[tokio::main] async fn main() -> Result<(), Box> { - env_logger::init(); - - let settings_file = std::fs::read_to_string("Ganymede.toml").map_err(|err| { - log::error!("Failed to read 'Ganymede.toml': {err}"); - err - })?; + configure_logging(); - let settings: Settings = toml::from_str(&settings_file).map_err(|err| { - log::error!("Failed to parse 'Ganymede.toml': {err}"); - err - })?; + let configuration = try_read_configuration_file("Ganymede.toml")?; - let postgres = PgPoolOptions::new() - .max_connections(5) - .connect(&settings.postgres_uri) - .await - .map_err(|err| { - log::error!("Failed to connect to postgres: {err}"); - err - })?; + let database = Database::try_from_uri(&configuration.postgres_uri).await?; + let device = DeviceService::new(database.clone()); + let measurements = MeasurementsService::new(database.clone()); - let addr = format!("0.0.0.0:{0}", settings.port).parse()?; + let addr = format!("0.0.0.0:{0}", configuration.port).parse()?; let reflection = tonic_reflection::server::Builder::configure() .register_encoded_file_descriptor_set(ganymede::v2::FILE_DESCRIPTOR_SET) - .build() + .build_v1() .map_err(|err| { log::error!("Failed to create reflection service: {err}"); err })?; - let device = DeviceService::new(postgres); - let measurements = MeasurementsService::new(); - Server::builder() .add_service(reflection) .add_service(DeviceServiceServer::new(device)) @@ -63,3 +55,22 @@ async fn main() -> Result<(), Box> { Ok(()) } + +fn configure_logging() { + let env = env_logger::Env::new().default_filter_or("INFO"); + env_logger::init_from_env(env); +} + +fn try_read_configuration_file(path: &str) -> Result> { + let settings_file = std::fs::read_to_string(path).map_err(|err| { + log::error!("Failed to read 'Ganymede.toml': {err}"); + err + })?; + + let settings: RuntimeConfiguration = toml::from_str(&settings_file).map_err(|err| { + log::error!("Failed to read 'Ganymede.toml': {err}"); + err + })?; + + Ok(settings) +} diff --git a/src/measurements/mod.rs b/src/measurements/mod.rs deleted file mode 100644 index cc097b5..0000000 --- a/src/measurements/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod service; \ No newline at end of file diff --git a/src/measurements/service.rs b/src/measurements/service.rs deleted file mode 100644 index 6c6e63b..0000000 --- a/src/measurements/service.rs +++ /dev/null @@ -1,41 +0,0 @@ -use std::result::Result; - -use tonic::{Request, Response, Status}; - - -use crate::auth::authenticate; -use crate::ganymede; - -pub struct MeasurementsService { -} - -impl MeasurementsService { - pub fn new() -> Self { - MeasurementsService { } - } -} - -#[tonic::async_trait] -impl ganymede::v2::measurements_service_server::MeasurementsService for MeasurementsService { - async fn get_measurements( - &self, - request: Request - ) -> Result, Status> { - authenticate(&request)?; - - // TODO - - Err(Status::unimplemented("not yet implemented")) - } - - async fn push_measurements( - &self, - request: Request - ) -> Result, Status> { - authenticate(&request)?; - - // TODO - - Err(Status::unimplemented("not yet implemented")) - } -} diff --git a/src/result/error.rs b/src/result/error.rs new file mode 100644 index 0000000..aa6da79 --- /dev/null +++ b/src/result/error.rs @@ -0,0 +1,56 @@ +#[derive(Debug, Clone, PartialEq)] +pub enum Error { + // Value is out of range + OutOfRange, + + // Errors for various types of parsing errors + BadUuid, + BadMacAddress, + BadTimezone, + BadTimestamp, + BadPollPeriod, + BadLightConfiguration, + + // There is already a device with this MAC address in the database + DuplicateMacAddress, + + // Config is referenced by devices and cannot be deleted + ConfigInUse, + + // Could not find the requested entity + NoSuchDevice, + NoSuchConfig, + + // Unhandled database error + DatabaseError(String), + + // Avoid this, prefer creating a new enum type if necessary + GenericError(String), +} + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + +impl std::error::Error for Error {} + +// Conversions from commonly found errors +impl From for Error { + fn from(value: sqlx::Error) -> Self { + Error::DatabaseError(value.to_string()) + } +} + +impl From for Error { + fn from(_: uuid::Error) -> Self { + Error::BadUuid + } +} + +impl From for Error { + fn from(_: chrono_tz::ParseError) -> Self { + Error::BadTimezone + } +} diff --git a/src/result/mod.rs b/src/result/mod.rs new file mode 100644 index 0000000..9b990db --- /dev/null +++ b/src/result/mod.rs @@ -0,0 +1,5 @@ +pub mod error; +pub mod tonic; + +pub use error::Error; +pub type Result = std::result::Result; diff --git a/src/result/tonic.rs b/src/result/tonic.rs new file mode 100644 index 0000000..63a2f3a --- /dev/null +++ b/src/result/tonic.rs @@ -0,0 +1,31 @@ +use super::Error; + +fn log_and_return_internal_error(message: String) -> tonic::Status { + log::error!("request failed with database error: {message}"); + + if cfg!(debug_assertions) { + tonic::Status::internal(message.to_string()) + } else { + tonic::Status::internal("internal error") + } +} + +impl From for tonic::Status { + fn from(value: Error) -> Self { + match value { + Error::OutOfRange => tonic::Status::invalid_argument("value out of range"), + Error::BadUuid => tonic::Status::invalid_argument("invalid uuid"), + Error::BadMacAddress => tonic::Status::invalid_argument("invalid mac address"), + Error::BadTimezone => tonic::Status::invalid_argument("invalid or unknown timezone"), + Error::BadTimestamp => tonic::Status::invalid_argument("invalid timestamp"), + Error::BadPollPeriod => tonic::Status::invalid_argument("invalid poll period"), + Error::BadLightConfiguration => tonic::Status::invalid_argument("invalid light configuration"), + Error::DuplicateMacAddress => tonic::Status::invalid_argument("duplicate mac address"), + Error::ConfigInUse => tonic::Status::failed_precondition("config is in use"), + Error::NoSuchDevice => tonic::Status::not_found("no such device"), + Error::NoSuchConfig => tonic::Status::not_found("no such config"), + Error::GenericError(message) => log_and_return_internal_error(message), + Error::DatabaseError(message) => log_and_return_internal_error(message), + } + } +} diff --git a/src/auth.rs b/src/services/auth.rs similarity index 72% rename from src/auth.rs rename to src/services/auth.rs index f9c48b8..2475e73 100644 --- a/src/auth.rs +++ b/src/services/auth.rs @@ -33,26 +33,16 @@ struct Claims { pub fn authenticate(request: &tonic::Request) -> Result { let header = match request.metadata().get("authorization") { Some(header) => header, - None => { - return Err(tonic::Status::unauthenticated( - "Missing authorization header", - )) - } + None => return Err(tonic::Status::unauthenticated("Missing authorization header")), }; let header_ascii = match header.to_str() { Ok(ascii) => ascii, - Err(_) => { - return Err(tonic::Status::unauthenticated( - "Invalid authorization token", - )) - } + Err(_) => return Err(tonic::Status::unauthenticated("Invalid authorization token")), }; if !header_ascii.starts_with("Bearer ") { - return Err(tonic::Status::unauthenticated( - "Invalid authorization token", - )); + return Err(tonic::Status::unauthenticated("Invalid authorization token")); } let decoding_key = match DecodingKey::from_rsa_pem(AUTH0_KEY.as_bytes()) { @@ -69,20 +59,12 @@ pub fn authenticate(request: &tonic::Request) -> Result token, - Err(_) => { - return Err(tonic::Status::unauthenticated( - "Invalid authorization token", - )) - } + Err(_) => return Err(tonic::Status::unauthenticated("Invalid authorization token")), }; let domain_id = match Uuid::try_parse(&token.claims.domain_id) { Ok(header) => header, - Err(_) => { - return Err(tonic::Status::unauthenticated( - "Invalid authorization token", - )) - } + Err(_) => return Err(tonic::Status::unauthenticated("Invalid authorization token")), }; Ok(domain_id) diff --git a/src/device/service.rs b/src/services/device.rs similarity index 50% rename from src/device/service.rs rename to src/services/device.rs index cdb1984..5bf6742 100644 --- a/src/device/service.rs +++ b/src/services/device.rs @@ -1,27 +1,27 @@ -use std::result::Result; - use chrono::{Offset, TimeZone}; +use uuid::Uuid; use tonic::{Request, Response, Status}; -use crate::auth::authenticate; +use crate::database::models::config::operations::ConfigFilter; +use crate::database::models::device::operations::DeviceFilter; +use crate::database::Database; use crate::ganymede; use crate::ganymede::v2::PollResponse; -use crate::types::mac; +use crate::result::{Error, Result}; +use crate::types::MacAddress; + +use crate::database::models::DeviceModel; -use super::config::errors::ConfigError; -use super::database::DomainDatabase; -use super::device::errors::DeviceError; -use super::device::model::DeviceModel; -use super::device::operations::DeviceFilter; +use super::auth::authenticate; pub struct DeviceService { - dbpool: sqlx::Pool, + database: Database, } impl DeviceService { - pub fn new(pool: sqlx::Pool) -> Self { - DeviceService { dbpool: pool } + pub fn new(database: Database) -> Self { + DeviceService { database } } } @@ -32,7 +32,7 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { request: Request, ) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); @@ -42,11 +42,13 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { }; let model: DeviceModel = device.try_into()?; - let result = database.insert_device(model).await?; + let result = transaction.insert_device(model).await?; + let model = transaction.fetch_one_device(&result).await?; + + transaction.commit().await?; + Ok(Response::new( - result - .try_into() - .map_err(|_| Status::internal("unhandled error"))?, + model.try_into().map_err(|_| Status::internal("unhandled error"))?, )) } @@ -55,7 +57,7 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { request: Request, ) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); @@ -65,8 +67,11 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { }; let model = device.try_into()?; - let result = database.update_device(model).await?; - Ok(Response::new(result.try_into()?)) + let result = transaction.update_device(model).await?; + let model = transaction.fetch_one_device(&result).await?; + + transaction.commit().await?; + Ok(Response::new(model.try_into()?)) } async fn get_device( @@ -74,16 +79,14 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { request: Request, ) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); - let device_id = match uuid::Uuid::try_parse(&payload.device_uid) { - Ok(uuid) => uuid, - Err(_) => Err(DeviceError::InvalidDeviceId)? - }; + let device_id = Uuid::try_parse(&payload.device_uid).map_err(|_| Error::BadUuid)?; + let result = transaction.fetch_one_device(&device_id).await?; - let result = database.fetch_one_device(device_id).await?; + transaction.commit().await?; Ok(Response::new(result.try_into()?)) } @@ -92,15 +95,14 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { request: Request, ) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); - + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); let filter = match payload.filter { Some(filter) => match filter { ganymede::v2::list_device_request::Filter::ConfigUid(config_id) => { match uuid::Uuid::try_parse(&config_id) { Ok(uuid) => DeviceFilter::ConfigId(uuid), - Err(_) => Err(DeviceError::InvalidConfigId)?, + Err(_) => Err(Error::BadUuid)?, } } ganymede::v2::list_device_request::Filter::NameFilter(name_filter) => { @@ -110,30 +112,32 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { None => DeviceFilter::None, }; - let results = database.fetch_many_device(filter).await?; - Ok(Response::new(ganymede::v2::ListDeviceResponse { + let results = transaction.fetch_many_device(filter).await?; + transaction.commit().await?; + + let response = ganymede::v2::ListDeviceResponse { devices: results .into_iter() .map(|result| result.try_into()) - .collect::, DeviceError>>()?, - })) + .collect::>>()?, + }; + Ok(Response::new(response)) } - async fn delete_device( - &self, - request: Request, - ) -> Result, Status> { + async fn delete_device(&self, request: Request) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); let device_id = match uuid::Uuid::try_parse(&payload.device_uid) { Ok(device_id) => device_id, - Err(_) => Err(DeviceError::InvalidDeviceId)?, + Err(_) => Err(Error::BadUuid)?, }; - database.delete_device(&device_id).await?; + transaction.delete_device(&device_id).await?; + + transaction.commit().await?; Ok(Response::new(())) } @@ -142,40 +146,54 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { request: Request, ) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); - let mac = mac::Mac::try_parse(&payload.device_mac).map_err(|_| DeviceError::InvalidMac)?; - let device_id = match database.fetch_device_id_for_mac(&mac).await? { + let mac = MacAddress::try_parse(&payload.device_mac)?; + let device_id = match transaction.fetch_device_id_for_mac(&mac).await? { Some(device_id) => device_id, - None => Err(DeviceError::NoSuchDevice)? + None => Err(Error::NoSuchDevice)?, }; - let device = database.fetch_one_device(device_id).await?; - let config = database.fetch_one_config(&device.config_id).await?; + let device = transaction.fetch_one_device(&device_id).await?; + let config = transaction.fetch_one_config(&device.config_id).await?; let tz: chrono_tz::Tz = match device.timezone.parse() { Ok(tz) => tz, Err(err) => { log::error!("Failed to parse timezone: {err}"); - Err(DeviceError::InvalidTimezone)? + Err(Error::BadTimezone)? } }; - let offset_seconds = tz - .offset_from_utc_datetime(&chrono::Utc::now().naive_utc()) - .fix() - .local_minus_utc() as i64; - + let offset_seconds = + tz.offset_from_utc_datetime(&chrono::Utc::now().naive_utc()).fix().local_minus_utc() as i64; let response = PollResponse { - uid: device.device_id.to_string(), - display_name: device.display_name, + device_uid: device.device_id.to_string(), + device_display_name: device.display_name, + config_uid: config.config_id.to_string(), + config_display_name: config.display_name, timezone_offset_minutes: offset_seconds / 60, - config: Some(config.try_into()?), + poll_period: Some(prost_types::Duration { + seconds: config.poll_period.num_seconds(), + nanos: config.poll_period.subsec_nanos(), + }), + light_config: Some( + match serde_json::from_value::(config.light_config) { + Ok(config) => config, + Err(err) => { + log::error!("error parsing JSON from DB: {err}"); + return Err(Error::BadLightConfiguration)?; + } + }, + ), }; + transaction.update_last_poll(&device.device_id, chrono::offset::Utc::now()).await?; + + transaction.commit().await?; Ok(Response::new(response)) } @@ -184,7 +202,7 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { request: Request, ) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); let config = match payload.config { @@ -193,8 +211,11 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { }; let model = config.try_into()?; - let result = database.insert_config(&model).await?; - Ok(Response::new(result.try_into()?)) + let result = transaction.insert_config(model).await?; + let model = transaction.fetch_one_config(&result).await?; + + transaction.commit().await?; + Ok(Response::new(model.try_into()?)) } async fn update_config( @@ -202,7 +223,7 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { request: Request, ) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); let config = match payload.config { @@ -211,8 +232,11 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { }; let model = config.try_into()?; - let result = database.update_config(&model).await?; - Ok(Response::new(result.try_into()?)) + let result = transaction.update_config(model).await?; + let model = transaction.fetch_one_config(&result).await?; + + transaction.commit().await?; + Ok(Response::new(model.try_into()?)) } async fn get_config( @@ -220,16 +244,15 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { request: Request, ) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); - let config_id = match uuid::Uuid::try_parse(&payload.config_uid) { - Ok(config_id) => config_id, - Err(_) => Err(ConfigError::InvalidConfigId)?, - }; + let config_id = Uuid::try_parse(&payload.config_uid).map_err(|_| Error::BadUuid)?; - let result = database.fetch_one_config(&config_id).await?; - Ok(Response::new(result.try_into()?)) + let model = transaction.fetch_one_config(&config_id).await?; + + transaction.commit().await?; + Ok(Response::new(model.try_into()?)) } async fn list_config( @@ -237,38 +260,40 @@ impl ganymede::v2::device_service_server::DeviceService for DeviceService { request: Request, ) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); - let name_filter = if payload.name_filter.is_empty() { - None - } else { - Some(payload.name_filter) + let filter = match payload.name_filter.is_empty() { + false => ConfigFilter::NameFilter(payload.name_filter), + true => ConfigFilter::None, }; - let results = database.fetch_many_config(name_filter).await?; - Ok(Response::new(ganymede::v2::ListConfigResponse { + let results = transaction.fetch_many_config(filter).await?; + + let response = ganymede::v2::ListConfigResponse { configs: results .into_iter() .map(|result| result.try_into()) - .collect::, ConfigError>>()?, - })) + .collect::>>()?, + }; + + transaction.commit().await?; + Ok(Response::new(response)) } - async fn delete_config( - &self, - request: Request, - ) -> Result, Status> { + async fn delete_config(&self, request: Request) -> Result, Status> { let domain_id = authenticate(&request)?; - let database = DomainDatabase::new(&self.dbpool, domain_id); + let mut transaction = self.database.for_domain(domain_id).begin().await?; let payload = request.into_inner(); let config_id = match uuid::Uuid::try_parse(&payload.config_uid) { Ok(config_id) => config_id, - Err(_) => Err(ConfigError::InvalidConfigId)?, + Err(_) => Err(Error::BadUuid)?, }; - database.delete_config(&config_id).await?; + transaction.delete_config(&config_id).await?; + + transaction.commit().await?; Ok(Response::new(())) } } diff --git a/src/services/measurement.rs b/src/services/measurement.rs new file mode 100644 index 0000000..fe056ff --- /dev/null +++ b/src/services/measurement.rs @@ -0,0 +1,50 @@ +use tonic::{Request, Response, Status}; + +use crate::database::models::AtmosphereDataModel; +use crate::database::Database; +use crate::ganymede; +use crate::Result; + +use super::auth::authenticate; + +pub struct MeasurementsService { + database: Database, +} + +impl MeasurementsService { + pub fn new(database: Database) -> Self { + MeasurementsService { database } + } +} + +#[tonic::async_trait] +impl ganymede::v2::measurements_service_server::MeasurementsService for MeasurementsService { + async fn get_measurements( + &self, + request: Request, + ) -> Result, Status> { + let _domain_id = authenticate(&request)?; + + // TODO + + Err(Status::unimplemented("not yet implemented")) + } + + async fn push_measurements( + &self, + request: Request, + ) -> Result, Status> { + let domain_id = authenticate(&request)?; + let mut transaction = self.database.for_domain(domain_id).begin().await?; + + let payload = request.into_inner(); + let atmosphere_data: Vec = (&payload).try_into()?; + + log::debug!("Parsed {} valid atmospheric data points", atmosphere_data.len()); + + transaction.insert_many_atmosphere_data(atmosphere_data).await?; + transaction.commit().await?; + + Ok(Response::new(())) + } +} diff --git a/src/services/mod.rs b/src/services/mod.rs new file mode 100644 index 0000000..58527ff --- /dev/null +++ b/src/services/mod.rs @@ -0,0 +1,6 @@ +mod auth; +pub mod device; +pub mod measurement; + +pub type DeviceService = device::DeviceService; +pub type MeasurementsService = measurement::MeasurementsService; diff --git a/src/types/celsius.rs b/src/types/celsius.rs new file mode 100644 index 0000000..89e9c04 --- /dev/null +++ b/src/types/celsius.rs @@ -0,0 +1,23 @@ +use crate::{Error, Result}; + +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, sqlx::Type)] +#[sqlx(transparent)] +pub struct Celsius(f32); + +impl TryFrom for Celsius { + type Error = Error; + + fn try_from(value: f32) -> Result { + if value < -273.15 { + Err(Error::OutOfRange) + } else { + Ok(Celsius(value)) + } + } +} + +impl Into for Celsius { + fn into(self) -> f32 { + self.0 + } +} diff --git a/src/types/fractional.rs b/src/types/fractional.rs new file mode 100644 index 0000000..e170254 --- /dev/null +++ b/src/types/fractional.rs @@ -0,0 +1,23 @@ +use crate::{Error, Result}; + +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, sqlx::Type)] +#[sqlx(transparent)] +pub struct Fractional(f32); + +impl TryFrom for Fractional { + type Error = Error; + + fn try_from(value: f32) -> Result { + if 0.0 <= value && value <= 1.0 { + Ok(Fractional(value)) + } else { + Err(Error::OutOfRange) + } + } +} + +impl Into for Fractional { + fn into(self) -> f32 { + self.0 + } +} diff --git a/src/types/mac.rs b/src/types/mac.rs deleted file mode 100644 index c26edb0..0000000 --- a/src/types/mac.rs +++ /dev/null @@ -1,73 +0,0 @@ -#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, sqlx::Type)] -#[sqlx(transparent)] -pub struct Mac(String); - -#[derive(Debug)] -pub enum Error { - InvalidMac, -} - -impl Mac { - pub fn try_parse(input: &str) -> Result { - if input.len() != 17 { - return Err(Error::InvalidMac); - } - - for (i, c) in input.chars().enumerate() { - if (i + 1) % 3 == 0 { - if c != ':' { - return Err(Error::InvalidMac); - } - } else if !c.is_ascii_hexdigit() { - return Err(Error::InvalidMac); - } - } - - Ok(Mac { - 0: input.to_ascii_lowercase(), - }) - } - - pub fn to_string(&self) -> &String { - &self.0 - } -} - -impl TryFrom for Mac { - type Error = Error; - - fn try_from(value: String) -> Result { - Mac::try_parse(&value) - } -} - -impl TryFrom<&str> for Mac { - type Error = Error; - - fn try_from(value: &str) -> Result { - Mac::try_parse(value) - } -} - -impl From for String { - fn from(value: Mac) -> String { - value.0 - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_try_into_mac() { - assert!(Mac::try_from("00:00:00:00:00:00".to_string()).is_ok()); - assert!(Mac::try_from("AA:bb:CC:dd:EE:ff".to_string()).is_ok()); - - assert!(Mac::try_from("not-a-mac".to_string()).is_err()); - assert!(Mac::try_from("aa:aa:aa:aa:aa:GG").is_err()); - assert!(Mac::try_from("aa:aa:aa:aa:aa:aa:aa").is_err()); - assert!(Mac::try_from("aaaaaaaaaaaa").is_err()); - assert!(Mac::try_from("").is_err()); - } -} diff --git a/src/types/mac_address.rs b/src/types/mac_address.rs new file mode 100644 index 0000000..b2d8513 --- /dev/null +++ b/src/types/mac_address.rs @@ -0,0 +1,70 @@ +use crate::{Error, Result}; + +#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, sqlx::Type)] +#[sqlx(transparent)] +pub struct MacAddress(String); + +impl MacAddress { + pub fn try_parse(input: &str) -> Result { + if input.len() != 17 { + return Err(Error::BadMacAddress); + } + + for (i, c) in input.chars().enumerate() { + if (i + 1) % 3 == 0 { + if c != ':' { + return Err(Error::BadMacAddress); + } + } else if !c.is_ascii_hexdigit() { + return Err(Error::BadMacAddress); + } + } + + Ok(MacAddress { + 0: input.to_ascii_lowercase(), + }) + } + + pub fn to_string(&self) -> &String { + &self.0 + } +} + +impl TryFrom for MacAddress { + type Error = Error; + + fn try_from(value: String) -> Result { + MacAddress::try_parse(&value) + } +} + +impl TryFrom<&str> for MacAddress { + type Error = Error; + + fn try_from(value: &str) -> Result { + MacAddress::try_parse(value) + } +} + +impl From for String { + fn from(value: MacAddress) -> String { + value.0 + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_try_into_mac() { + assert!(MacAddress::try_from("00:00:00:00:00:00".to_string()).is_ok()); + assert!(MacAddress::try_from("AA:bb:CC:dd:EE:ff".to_string()).is_ok()); + + assert!(MacAddress::try_from("not-a-mac".to_string()).is_err()); + assert!(MacAddress::try_from("aa:aa:aa:aa:aa:GG").is_err()); + assert!(MacAddress::try_from("aa:aa:aa:aa:aa:aa:aa").is_err()); + assert!(MacAddress::try_from("aaaaaaaaaaaa").is_err()); + assert!(MacAddress::try_from("").is_err()); + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index 7fb8c44..692d146 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1 +1,7 @@ -pub mod mac; +pub mod celsius; +mod fractional; +pub mod mac_address; + +pub type Celsius = celsius::Celsius; +pub type MacAddress = mac_address::MacAddress; +pub type RelativeHumidity = fractional::Fractional;