diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index badd69b..fc53c17 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -102,3 +102,17 @@ jobs: tags: ${{ steps.prep.outputs.tags }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache + + clippy: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - run: rustup component add clippy + + - uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features diff --git a/Cargo.lock b/Cargo.lock index b562f81..9c89d9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.51" +version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" +checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" dependencies = [ "proc-macro2", "quote", @@ -68,9 +68,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.7.1" +version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "byteorder" @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.70" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" [[package]] name = "cfg-if" @@ -133,9 +133,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.0.0-beta.4" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcd70aa5597dbc42f7217a543f9ef2768b2ef823ba29036072d30e1d88e98406" +checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375" dependencies = [ "atty", "bitflags", @@ -146,14 +146,13 @@ dependencies = [ "strsim", "termcolor", "textwrap", - "vec_map", ] [[package]] name = "clap_derive" -version = "3.0.0-beta.4" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5bb0d655624a0b8770d1c178fb8ffcb1f91cc722cb08f451e3dc72465421ac" +checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153" dependencies = [ "heck", "proc-macro-error", @@ -164,9 +163,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" dependencies = [ "core-foundation-sys", "libc", @@ -174,9 +173,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cpufeatures" @@ -189,9 +188,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" +checksum = "738c290dfaea84fc1ca15ad9c168d083b05a714e1efddd8edaab678dc28d2836" dependencies = [ "cfg-if", ] @@ -255,13 +254,22 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" [[package]] name = "encoding_rs" -version = "0.8.28" +version = "0.8.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" dependencies = [ "cfg-if", ] +[[package]] +name = "fastrand" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "779d043b6a0b90cc4c0ed7ee380a6504394cee7efd7db050e3774eee387324b2" +dependencies = [ + "instant", +] + [[package]] name = "flate2" version = "1.0.22" @@ -307,9 +315,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" +checksum = "28560757fe2bb34e79f907794bb6b22ae8b0e5c669b638a1132f2592b19035b4" dependencies = [ "futures-channel", "futures-core", @@ -322,9 +330,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" dependencies = [ "futures-core", "futures-sink", @@ -332,15 +340,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" +checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" [[package]] name = "futures-executor" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" +checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a" dependencies = [ "futures-core", "futures-task", @@ -349,18 +357,16 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" +checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" [[package]] name = "futures-macro" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c" dependencies = [ - "autocfg", - "proc-macro-hack", "proc-macro2", "quote", "syn", @@ -368,23 +374,22 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" +checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" [[package]] name = "futures-task" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" +checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" [[package]] name = "futures-util" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" dependencies = [ - "autocfg", "futures-channel", "futures-core", "futures-io", @@ -394,37 +399,24 @@ dependencies = [ "memchr", "pin-project-lite", "pin-utils", - "proc-macro-hack", - "proc-macro-nested", "slab", ] [[package]] name = "generic-array" -version = "0.14.4" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" dependencies = [ "typenum", "version_check", ] -[[package]] -name = "getrandom" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "h2" -version = "0.3.6" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c06815895acec637cd6ed6e9662c935b866d20a106f8361892893a7d9234964" +checksum = "0c9de88456263e249e241fcd211d3954e2c9b0ef7ccfc235a444eb367cae3689" dependencies = [ "bytes", "fnv", @@ -447,18 +439,18 @@ checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" [[package]] name = "headers" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b7591fb62902706ae8e7aaff416b1b0fa2c0fd0878b46dc13baa3712d8a855" +checksum = "a4c4eb0471fcb85846d8b0690695ef354f9afb11cb03cac2e1d7c9253351afb0" dependencies = [ "base64", "bitflags", "bytes", "headers-core", "http", + "httpdate", "mime", "sha-1", - "time", ] [[package]] @@ -472,12 +464,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" @@ -490,20 +479,20 @@ dependencies = [ [[package]] name = "http" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" +checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" dependencies = [ "bytes", "fnv", - "itoa", + "itoa 1.0.1", ] [[package]] name = "http-body" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "399c583b2979440c60be0821a6199eca73bc3c8dcd9d070d75ac726e2c6186e5" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" dependencies = [ "bytes", "http", @@ -518,15 +507,15 @@ checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" [[package]] name = "httpdate" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" -version = "0.14.13" +version = "0.14.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" +checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" dependencies = [ "bytes", "futures-channel", @@ -537,7 +526,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa", + "itoa 0.4.8", "pin-project-lite", "socket2", "tokio", @@ -572,9 +561,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" dependencies = [ "autocfg", "hashbrown", @@ -582,9 +571,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", ] @@ -601,6 +590,12 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +[[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + [[package]] name = "js-sys" version = "0.3.55" @@ -618,9 +613,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.103" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "lock_api" @@ -640,15 +635,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "matchers" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" -dependencies = [ - "regex-automata", -] - [[package]] name = "matches" version = "0.1.9" @@ -710,9 +696,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.13" +version = "0.7.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" dependencies = [ "libc", "log", @@ -778,9 +764,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ "hermit-abi", "libc", @@ -788,9 +774,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" [[package]] name = "opaque-debug" @@ -800,9 +786,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.36" +version = "0.10.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" +checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" dependencies = [ "bitflags", "cfg-if", @@ -814,15 +800,15 @@ dependencies = [ [[package]] name = "openssl-probe" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.67" +version = "0.9.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" +checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" dependencies = [ "autocfg", "cc", @@ -833,9 +819,12 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "3.1.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] [[package]] name = "parking_lot" @@ -870,18 +859,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" +checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" +checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb" dependencies = [ "proc-macro2", "quote", @@ -890,9 +879,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" [[package]] name = "pin-utils" @@ -902,15 +891,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.20" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" - -[[package]] -name = "ppv-lite86" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" [[package]] name = "pq-sys" @@ -945,32 +928,20 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - [[package]] name = "proc-macro2" -version = "1.0.29" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.10" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" dependencies = [ "proc-macro2", ] @@ -986,46 +957,6 @@ dependencies = [ "scheduled-thread-pool", ] -[[package]] -name = "rand" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", - "rand_hc", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rand_hc" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" -dependencies = [ - "rand_core", -] - [[package]] name = "redox_syscall" version = "0.2.10" @@ -1035,30 +966,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "regex" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" -dependencies = [ - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" - [[package]] name = "remove_dir_all" version = "0.5.3" @@ -1070,15 +977,16 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.4" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246e9f61b9bb77df069a947682be06e31ac43ea37862e244a69f177694ea6d22" +checksum = "87f242f1488a539a79bac6dbe7c8609ae43b7914b7736210f239a37cccb32525" dependencies = [ "base64", "bytes", "encoding_rs", "futures-core", "futures-util", + "h2", "http", "http-body", "hyper", @@ -1096,6 +1004,7 @@ dependencies = [ "serde_urlencoded", "tokio", "tokio-native-tls", + "tokio-util", "url", "wasm-bindgen", "wasm-bindgen-futures", @@ -1105,9 +1014,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" [[package]] name = "schannel" @@ -1142,9 +1051,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" +checksum = "d09d3c15d814eda1d6a836f2f2b56a6abc1446c8a34351cb3180d3db92ffe4ce" dependencies = [ "bitflags", "core-foundation", @@ -1155,9 +1064,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" +checksum = "e90dd10c41c6bfc633da6e0c659bd25d31e0791e5974ac42970267d59eba87f7" dependencies = [ "core-foundation-sys", "libc", @@ -1165,18 +1074,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" dependencies = [ "proc-macro2", "quote", @@ -1185,23 +1094,23 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.68" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +checksum = "c059c05b48c5c0067d4b4b2b4f0732dd65feb52daf7e0ea09cd87e7dadc1af79" dependencies = [ - "itoa", + "itoa 1.0.1", "ryu", "serde", ] [[package]] name = "serde_urlencoded" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa", + "itoa 1.0.1", "ryu", "serde", ] @@ -1221,16 +1130,16 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740223c51853f3145fe7c90360d2d4232f2b62e3449489c207eccde818979982" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" dependencies = [ "lazy_static", ] [[package]] name = "sirene" -version = "2.2.0" +version = "2.3.0" dependencies = [ "async-trait", "chrono", @@ -1255,15 +1164,15 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" [[package]] name = "smallvec" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "socket2" @@ -1283,9 +1192,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.80" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" dependencies = [ "proc-macro2", "quote", @@ -1294,13 +1203,13 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ "cfg-if", + "fastrand", "libc", - "rand", "redox_syscall", "remove_dir_all", "winapi", @@ -1320,24 +1229,21 @@ name = "textwrap" version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" -dependencies = [ - "unicode-width", -] [[package]] name = "thiserror" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.29" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" dependencies = [ "proc-macro2", "quote", @@ -1355,19 +1261,20 @@ dependencies = [ [[package]] name = "time" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", + "wasi", "winapi", ] [[package]] name = "tinyvec" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" dependencies = [ "tinyvec_macros", ] @@ -1380,11 +1287,10 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.12.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" +checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838" dependencies = [ - "autocfg", "bytes", "libc", "memchr", @@ -1397,9 +1303,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.4.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "154794c8f499c2619acd19e839294703e9e32e7630ef5f46ea80d4ef0fbee5eb" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ "proc-macro2", "quote", @@ -1418,9 +1324,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" +checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" dependencies = [ "futures-core", "pin-project-lite", @@ -1429,9 +1335,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d3725d3efa29485e87311c5b699de63cde14b00ed4d256b8318aa30ca452cd" +checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" dependencies = [ "bytes", "futures-core", @@ -1492,36 +1398,18 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "tracing-serde" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb65ea441fbb84f9f6748fd496cf7f63ec9af5bca94dd86456978d055e8eb28b" -dependencies = [ - "serde", - "tracing-core", -] - [[package]] name = "tracing-subscriber" -version = "0.2.25" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +checksum = "77be66445c4eeebb934a7340f227bfe7b338173d3f8c00a60a5a58005c9faecf" dependencies = [ "ansi_term", - "chrono", - "lazy_static", - "matchers", - "regex", - "serde", - "serde_json", "sharded-slab", "smallvec", "thread_local", - "tracing", "tracing-core", "tracing-log", - "tracing-serde", ] [[package]] @@ -1532,9 +1420,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "typenum" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicase" @@ -1547,9 +1435,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" [[package]] name = "unicode-normalization" @@ -1560,18 +1448,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" - -[[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - [[package]] name = "unicode-xid" version = "0.2.2" @@ -1596,17 +1472,11 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "want" @@ -1620,12 +1490,13 @@ dependencies = [ [[package]] name = "warp" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "332d47745e9a0c38636dbd454729b147d16bd1ed08ae67b3ab281c4506771054" +checksum = "3cef4e1e9114a4b7f1ac799f16ce71c14de5778500c5450ec6b7b920c55b587e" dependencies = [ "bytes", - "futures", + "futures-channel", + "futures-util", "headers", "http", "hyper", @@ -1647,9 +1518,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" @@ -1658,8 +1529,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ "cfg-if", - "serde", - "serde_json", "wasm-bindgen-macro", ] diff --git a/Cargo.toml b/Cargo.toml index e964658..406c015 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "sirene" -version = "2.2.0" +version = "2.3.0" authors = ["Julien Blatecky "] -edition = "2018" +edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] async-trait = "0.1" chrono = { version = "0.4", features = ["serde"] } -clap = "3.0.0-beta" +clap = { version = "3.0", features = ["derive", "env"] } custom_error = "1.9" diesel = { version = "1.4", features = ["postgres", "chrono", "r2d2", "serde_json", "64-column-tables"] } diesel_migrations = { version = "1.4", features = ["postgres"] } @@ -19,10 +19,10 @@ r2d2 = "0.8" reqwest = { version = "0.11", features = ["json", "stream"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -tokio = { version = "1.12", features = ["macros", "io-util", "fs", "rt-multi-thread", "time"] } +tokio = { version = "1.15", features = ["macros", "io-util", "fs", "rt-multi-thread", "time"] } tokio-util = { version = "0.6", features = ["compat"] } tracing = "0.1" -tracing-subscriber = "0.2" +tracing-subscriber = "0.3" warp = { version = "0.3", default-features = false } zip = "0.5" diff --git a/app/Chart.yaml b/app/Chart.yaml index 5d4befa..3bd700e 100644 --- a/app/Chart.yaml +++ b/app/Chart.yaml @@ -21,9 +21,9 @@ version: 0.1.0 # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "v2.2.0" +appVersion: "v2.3.0" dependencies: - - name: postgresql - version: "10.3.13" - repository: https://charts.bitnami.com/bitnami + - name: postgresql + version: "10.3.13" + repository: https://charts.bitnami.com/bitnami diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 53233e4..762bb3f 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -3,36 +3,35 @@ mod serve; mod update; use crate::connectors::ConnectorsBuilders; -use clap::Clap; +use clap::Parser; use common::FolderOptions; use serve::ServeFlags; -use std::env; use update::UpdateFlags; /// Sirene service used to update data in database /// and serve it through a HTTP REST API -#[derive(Clap, Debug)] -#[clap(version = "2.2.0", author = "Julien Blatecky")] +#[derive(Parser, Debug)] +#[clap(version = "2.3.0", author = "Julien Blatecky")] struct Opts { - /// Path to the temp folder, you can set in environment variable as TEMP_FOLDER - #[clap(long = "temp-folder")] - temp_folder: Option, + /// Path to the temp folder + #[clap(long = "temp-folder", env, default_value = "./data/temp")] + temp_folder: String, - /// Path to the file storage folder for this app, you can set in environment variable as FILE_FOLDER - #[clap(long = "file-folder")] - file_folder: Option, + /// Path to the file storage folder for this app + #[clap(long = "file-folder", env, default_value = "./data/files")] + file_folder: String, - /// Path to the file storage folder for the database, you can set in environment variable as DB_FOLDER. + /// Path to the file storage folder for the database. /// Could be the same as FILE_FOLDER if this app and the database are on the same file system. /// Files copied by this app inside FILE_FOLDER must be visible by the database in DB_FOLDER - #[clap(long = "db-folder")] - db_folder: Option, + #[clap(long = "db-folder", env, default_value = "./data/files")] + db_folder: String, #[clap(subcommand)] main_command: MainCommand, } -#[derive(clap::Clap, Debug)] +#[derive(clap::Parser, Debug)] enum MainCommand { /// Update data from CSV source files #[clap(name = "update")] @@ -46,22 +45,10 @@ enum MainCommand { pub async fn run(builders: ConnectorsBuilders) { let opts = Opts::parse(); - let temp_folder = opts - .temp_folder - .unwrap_or_else(|| env::var("TEMP_FOLDER").unwrap_or(String::from("./data/temp"))); - - let file_folder = opts - .file_folder - .unwrap_or_else(|| env::var("FILE_FOLDER").unwrap_or(String::from("./data/files"))); - - let db_folder = opts - .db_folder - .unwrap_or_else(|| env::var("DB_FOLDER").unwrap_or(file_folder.clone())); - let folder_options = FolderOptions { - temp: temp_folder, - file: file_folder, - db: db_folder, + temp: opts.temp_folder, + file: opts.file_folder, + db: opts.db_folder, }; match opts.main_command { diff --git a/src/commands/serve/mod.rs b/src/commands/serve/mod.rs index 7361cc0..9c78366 100644 --- a/src/commands/serve/mod.rs +++ b/src/commands/serve/mod.rs @@ -3,93 +3,55 @@ mod runner; use super::common::FolderOptions; use crate::connectors::ConnectorsBuilders; use runner::common::Context; -use std::env; use std::net::ToSocketAddrs; use tracing::info; #[derive(clap::Args, Debug)] pub struct ServeFlags { - /// Configure log level, you can set in environment variable as SIRENE_ENV - #[clap(arg_enum, long = "env")] - environment: Option, + /// Configure log level + #[clap(arg_enum, long = "env", env = "SIRENE_ENV")] + environment: CmdEnvironment, - /// Listen this port, you can set in environment variable as PORT - #[clap(short = 'p', long = "port")] - port: Option, + /// Listen this port + #[clap(long = "port", env)] + port: u16, - /// Listen this host, you can set in environment variable as HOST - #[clap(short = 'h', long = "host")] - host: Option, + /// Listen this host + #[clap(long = "host", env)] + host: String, - /// API key needed to allow maintenance operation from HTTP, you can set in environment variable as API_KEY - #[clap(short = 'k', long = "api-key")] + /// API key needed to allow maintenance operation from HTTP + #[clap(long = "api-key", env)] api_key: Option, - /// Base URL needed to configure asynchronous polling for updates, you can set in environment variable as BASE_URL - #[clap(short = 'b', long = "base-url")] + /// Base URL needed to configure asynchronous polling for updates + #[clap(long = "base-url", env)] base_url: Option, } -#[derive(clap::ArgEnum, Debug)] +#[derive(clap::ArgEnum, Clone, Debug)] enum CmdEnvironment { Development, Staging, Production, } -impl CmdEnvironment { - pub fn from_str(s: String) -> Option { - match s.as_str() { - "development" => Some(CmdEnvironment::Development), - "staging" => Some(CmdEnvironment::Staging), - "production" => Some(CmdEnvironment::Production), - _ => None, - } - } -} - pub async fn run(flags: ServeFlags, folder_options: FolderOptions, builders: ConnectorsBuilders) { - let env = flags.environment.unwrap_or_else(|| { - CmdEnvironment::from_str(env::var("SIRENE_ENV").expect("Missing SIRENE_ENV")) - .expect("Invalid SIRENE_ENV") - }); - - let port = flags.port.unwrap_or_else(|| { - env::var("PORT") - .expect("Missing PORT") - .parse() - .expect("Invalid PORT") - }); - - let host = flags - .host - .unwrap_or_else(|| env::var("HOST").expect("Missing HOST")); - - let addr = format!("{}:{}", host, port) + let addr = format!("{}:{}", flags.host, flags.port) .to_socket_addrs() .expect("Unable to resolve domain") .next() .expect("No address available"); - let api_key = match flags.api_key { - Some(key) => Some(key), - None => env::var("API_KEY").ok(), - }; - - let base_url = match flags.base_url { - Some(key) => Some(key), - None => env::var("BASE_URL").ok(), - }; - - info!("Configuring for {:#?}", env); + info!("Configuring for {:#?}", flags.environment); runner::run( addr, Context { builders, - api_key, + api_key: flags.api_key, folder_options, - base_url, + base_url: flags.base_url, }, ) .await; diff --git a/src/commands/serve/runner/error.rs b/src/commands/serve/runner/error.rs index 1036562..b2f23f9 100644 --- a/src/commands/serve/runner/error.rs +++ b/src/commands/serve/runner/error.rs @@ -1,6 +1,6 @@ use crate::connectors::Error as ConnectorError; use crate::models::{etablissement, unite_legale, update_metadata}; -use crate::update::error::Error as InternalUpdateError; +use crate::update::error::Error as InternalUpdate; use custom_error::custom_error; use serde::Serialize; use std::convert::Infallible; @@ -9,15 +9,15 @@ use warp::{http::StatusCode, Rejection, Reply}; custom_error! { pub Error InvalidData = "Invalid data", - MissingApiKeyError = "[Admin] Missing API key in configuration", - ApiKeyError = "[Admin] Wrong API key", - MissingBaseUrlForAsyncError = "[Admin] No BASE_URL configured, needed for asynchronous updates", + MissingApiKey = "[Admin] Missing API key in configuration", + ApiKey = "[Admin] Wrong API key", + MissingBaseUrlForAsync = "[Admin] No BASE_URL configured, needed for asynchronous updates", LocalConnectionFailed{source: r2d2::Error} = "Unable to connect to local database ({source}).", - UpdateConnectorError {source: ConnectorError} = "[Update] Error while creating connector: {source}", - UpdateError {source: InternalUpdateError} = "[Update] {source}", - UniteLegaleError {source: unite_legale::error::Error} = "[UniteLegale] {source}", - EtablissementError {source: etablissement::error::Error} = "[Etablissement] {source}", - StatusError {source: update_metadata::error::Error} = "[Status] {source}", + UpdateConnector {source: ConnectorError} = "[Update] Error while creating connector: {source}", + Update {source: InternalUpdate} = "[Update] {source}", + UniteLegale {source: unite_legale::error::Error} = "[UniteLegale] {source}", + Etablissement {source: etablissement::error::Error} = "[Etablissement] {source}", + Status {source: update_metadata::error::Error} = "[Status] {source}", } impl warp::reject::Reject for Error {} @@ -29,8 +29,8 @@ impl From for Rejection { } } -impl From for Rejection { - fn from(e: InternalUpdateError) -> Self { +impl From for Rejection { + fn from(e: InternalUpdate) -> Self { let error: Error = e.into(); error.into() } @@ -72,21 +72,21 @@ pub async fn handle_rejection(err: Rejection) -> Result ( match e { Error::InvalidData => StatusCode::BAD_REQUEST, - Error::MissingApiKeyError => StatusCode::UNAUTHORIZED, - Error::ApiKeyError => StatusCode::UNAUTHORIZED, - Error::MissingBaseUrlForAsyncError => StatusCode::BAD_REQUEST, + Error::MissingApiKey => StatusCode::UNAUTHORIZED, + Error::ApiKey => StatusCode::UNAUTHORIZED, + Error::MissingBaseUrlForAsync => StatusCode::BAD_REQUEST, Error::LocalConnectionFailed { source: _ } => StatusCode::INTERNAL_SERVER_ERROR, - Error::UpdateConnectorError { source: _ } => StatusCode::INTERNAL_SERVER_ERROR, - Error::UpdateError { source: _ } => StatusCode::INTERNAL_SERVER_ERROR, - Error::UniteLegaleError { source } => match source { + Error::UpdateConnector { source: _ } => StatusCode::INTERNAL_SERVER_ERROR, + Error::Update { source: _ } => StatusCode::INTERNAL_SERVER_ERROR, + Error::UniteLegale { source } => match source { unite_legale::error::Error::UniteLegaleNotFound => StatusCode::NOT_FOUND, _ => StatusCode::INTERNAL_SERVER_ERROR, }, - Error::EtablissementError { source } => match source { + Error::Etablissement { source } => match source { etablissement::error::Error::EtablissementNotFound => StatusCode::NOT_FOUND, _ => StatusCode::INTERNAL_SERVER_ERROR, }, - Error::StatusError { source } => match source { + Error::Status { source } => match source { update_metadata::error::Error::MetadataNotFound => StatusCode::NOT_FOUND, _ => StatusCode::INTERNAL_SERVER_ERROR, }, diff --git a/src/commands/serve/runner/mod.rs b/src/commands/serve/runner/mod.rs index c75f596..8030952 100644 --- a/src/commands/serve/runner/mod.rs +++ b/src/commands/serve/runner/mod.rs @@ -27,15 +27,15 @@ fn index() -> &'static str { async fn update(options: UpdateOptions, context: Context) -> Result { let api_key = match &context.api_key { Some(key) => key, - None => return Err(Error::MissingApiKeyError.into()), + None => return Err(Error::MissingApiKey.into()), }; if &options.api_key != api_key { - return Err(Error::ApiKeyError.into()); + return Err(Error::ApiKey.into()); } if options.asynchronous && context.base_url == None { - return Err(Error::MissingBaseUrlForAsyncError.into()); + return Err(Error::MissingBaseUrlForAsync.into()); } let mut connectors = context.builders.create_with_insee().await?; @@ -60,11 +60,11 @@ async fn update(options: UpdateOptions, context: Context) -> Result Result { let api_key = match &context.api_key { Some(key) => key, - None => return Err(Error::MissingApiKeyError.into()), + None => return Err(Error::MissingApiKey.into()), }; if &query.api_key != api_key { - return Err(Error::ApiKeyError.into()); + return Err(Error::ApiKey.into()); } let connectors = context.builders.create(); @@ -77,7 +77,7 @@ async fn status(query: StatusQueryString, context: Context) -> Result, - api_key: &String, + api_key: &str, ) -> Result { let status_code = match update_metadata.status.as_str() { "launched" => StatusCode::ACCEPTED, @@ -109,11 +109,11 @@ async fn set_status_to_error( ) -> Result { let api_key = match &context.api_key { Some(key) => key, - None => return Err(Error::MissingApiKeyError.into()), + None => return Err(Error::MissingApiKey.into()), }; if &query.api_key != api_key { - return Err(Error::ApiKeyError.into()); + return Err(Error::ApiKey.into()); } let connectors = context.builders.create(); diff --git a/src/commands/update.rs b/src/commands/update.rs index b04ede8..ef08ce7 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -5,7 +5,7 @@ use crate::models::update_metadata::error_update; use crate::update::{common::Config, error::Error, update, update_step}; use chrono::Utc; -#[derive(clap::Clap, Debug)] +#[derive(clap::Parser, Debug)] pub struct UpdateFlags { /// Configure which part will be updated #[clap(arg_enum)] diff --git a/src/connectors/insee/error.rs b/src/connectors/insee/error.rs index 628c016..785b0ae 100644 --- a/src/connectors/insee/error.rs +++ b/src/connectors/insee/error.rs @@ -1,12 +1,11 @@ use custom_error::custom_error; custom_error! { pub InseeTokenError - NetworkError { source: reqwest::Error } = "Unable to retrieve INSEE token (network error: {source})", - ApiError = "Unable to retrieve INSEE token", - MalformedError {source: serde_json::Error} = "Unable to read INSEE token ({source})", - InvalidError {source: reqwest::header::InvalidHeaderValue} = "Unable to use INSEE token in header ({source})", + Network { source: reqwest::Error } = "Unable to retrieve INSEE token (network error: {source})", + Malformed {source: serde_json::Error} = "Unable to read INSEE token ({source})", + Invalid {source: reqwest::header::InvalidHeaderValue} = "Unable to use INSEE token in header ({source})", } -custom_error! { pub InseeUpdateError - NetworkError {source: reqwest::Error} = "Unable to retrieve INSEE data (network error: {source})", +custom_error! { pub InseeUpdate + Network {source: reqwest::Error} = "Unable to retrieve INSEE data (network error: {source})", } diff --git a/src/connectors/insee/implementation.rs b/src/connectors/insee/implementation.rs index 60f2384..15a9c9f 100644 --- a/src/connectors/insee/implementation.rs +++ b/src/connectors/insee/implementation.rs @@ -1,4 +1,4 @@ -use super::error::InseeUpdateError; +use super::error::InseeUpdate; use super::types::{ etablissement::InseeEtablissementResponse, unite_legale::InseeUniteLegaleResponse, InseeCountQueryParams, InseeCountResponse, InseeQueryParams, InseeResponse, @@ -48,7 +48,7 @@ impl Connector { pub async fn get_total_unites_legales( &mut self, start_timestamp: NaiveDateTime, - ) -> Result { + ) -> Result { self.wait_for_insee_limitation().await; get_total(&self.client, &UNITES_LEGALES_ENDPOINT, start_timestamp).await @@ -57,7 +57,7 @@ impl Connector { pub async fn get_total_etablissements( &mut self, start_timestamp: NaiveDateTime, - ) -> Result { + ) -> Result { self.wait_for_insee_limitation().await; get_total(&self.client, &ETABLISSEMENTS_ENDPOINT, start_timestamp).await @@ -67,7 +67,7 @@ impl Connector { &mut self, start_timestamp: NaiveDateTime, cursor: String, - ) -> Result<(Option, Vec), InseeUpdateError> { + ) -> Result<(Option, Vec), InseeUpdate> { self.wait_for_insee_limitation().await; let (next_cursor, response) = get_daily_data::( @@ -95,7 +95,7 @@ impl Connector { &mut self, start_timestamp: NaiveDateTime, cursor: String, - ) -> Result<(Option, Vec), InseeUpdateError> { + ) -> Result<(Option, Vec), InseeUpdate> { self.wait_for_insee_limitation().await; let (next_cursor, response) = get_daily_data::( @@ -125,7 +125,7 @@ async fn get_daily_data( config: &EndpointConfig, start_timestamp: NaiveDateTime, cursor: String, -) -> Result<(Option, Option), InseeUpdateError> { +) -> Result<(Option, Option), InseeUpdate> { let url = format!("{}/{}", BASE_URL, config.route); let response = match client @@ -144,7 +144,7 @@ async fn get_daily_data( .await? .error_for_status() { - Ok(response) => response.json::().await.map_err(|error| error.into()), + Ok(response) => response.json::().await.map_err(|error| error), Err(error) => { // Insee returns 404 for empty data if let Some(status) = error.status() { @@ -171,7 +171,7 @@ async fn get_total( client: &reqwest::Client, config: &EndpointConfig, start_timestamp: NaiveDateTime, -) -> Result { +) -> Result { let url = format!("{}/{}", BASE_URL, config.route); let response = client diff --git a/src/connectors/insee/types/etablissement.rs b/src/connectors/insee/types/etablissement.rs index 8633e70..b16e1c2 100644 --- a/src/connectors/insee/types/etablissement.rs +++ b/src/connectors/insee/types/etablissement.rs @@ -94,39 +94,27 @@ pub struct InseePeriodeEtablissement { date_debut: Option, #[serde(deserialize_with = "deserialize_etat_administratif")] etat_administratif_etablissement: String, - changement_etat_administratif_etablissement: bool, enseigne1_etablissement: Option, enseigne2_etablissement: Option, enseigne3_etablissement: Option, - changement_enseigne_etablissement: bool, denomination_usuelle_etablissement: Option, - changement_denomination_usuelle_etablissement: bool, activite_principale_etablissement: Option, nomenclature_activite_principale_etablissement: Option, - changement_activite_principale_etablissement: bool, caractere_employeur_etablissement: Option, - changement_caractere_employeur_etablissement: bool, } impl From<&InseeEtablissement> for Option { fn from(u: &InseeEtablissement) -> Self { - match u - .periodes_etablissement + u.periodes_etablissement .iter() .find(|p| p.date_fin.is_none()) - { - Some(periode) => { - // Convert - Some( - InseeEtablissementWithPeriode { - content: u.content.clone(), - periode: periode.clone(), - } - .into(), - ) - } - None => None, - } + .map(|periode| { + InseeEtablissementWithPeriode { + content: u.content.clone(), + periode: periode.clone(), + } + .into() + }) } } @@ -197,5 +185,5 @@ where D: serde::Deserializer<'de>, { let opt = Option::deserialize(deserializer)?; - Ok(opt.unwrap_or(String::from("F"))) + Ok(opt.unwrap_or_else(|| String::from("F"))) } diff --git a/src/connectors/insee/types/mod.rs b/src/connectors/insee/types/mod.rs index 55bf1c6..774a801 100644 --- a/src/connectors/insee/types/mod.rs +++ b/src/connectors/insee/types/mod.rs @@ -28,9 +28,6 @@ pub trait InseeResponse: DeserializeOwned { #[derive(Clone, Deserialize, Debug)] #[serde(rename_all = "camelCase")] pub struct Header { - total: u32, - debut: u32, - nombre: u32, pub curseur: String, pub curseur_suivant: String, } diff --git a/src/connectors/insee/types/unite_legale.rs b/src/connectors/insee/types/unite_legale.rs index dea7da0..1656d14 100644 --- a/src/connectors/insee/types/unite_legale.rs +++ b/src/connectors/insee/types/unite_legale.rs @@ -97,23 +97,16 @@ pub struct PeriodeInseeUniteLegale { impl From<&InseeUniteLegale> for Option { fn from(u: &InseeUniteLegale) -> Self { - match u - .periodes_unite_legale + u.periodes_unite_legale .iter() .find(|p| p.date_fin.is_none()) - { - Some(periode) => { - // Convert - Some( - InseeUniteLegaleWithPeriode { - content: u.content.clone(), - periode: periode.clone(), - } - .into(), - ) - } - None => None, - } + .map(|periode| { + InseeUniteLegaleWithPeriode { + content: u.content.clone(), + periode: periode.clone(), + } + .into() + }) } } @@ -164,5 +157,5 @@ where D: serde::Deserializer<'de>, { let opt = Option::deserialize(deserializer)?; - Ok(opt.unwrap_or(String::from("C"))) + Ok(opt.unwrap_or_else(|| String::from("C"))) } diff --git a/src/connectors/local.rs b/src/connectors/local.rs index 4bc8d6b..fbd0b8b 100644 --- a/src/connectors/local.rs +++ b/src/connectors/local.rs @@ -48,7 +48,7 @@ impl ConnectorBuilder { pool: Pool::builder() .max_size(pool_size) .build(manager) - .expect(&format!("Error connecting to {}", database_url)), + .unwrap_or_else(|_| panic!("Error connecting to {}", database_url)), }; let connection = builder diff --git a/src/main.rs b/src/main.rs index a54a2bf..dcca236 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,6 @@ mod update; use connectors::ConnectorsBuilders; use dotenv::dotenv; -use tracing_subscriber; #[tokio::main] async fn main() { diff --git a/src/models/common.rs b/src/models/common.rs index a619b63..ea638cc 100644 --- a/src/models/common.rs +++ b/src/models/common.rs @@ -1,4 +1,4 @@ -use crate::connectors::insee::error::InseeUpdateError; +use crate::connectors::insee::error::InseeUpdate; use crate::connectors::Connectors; use async_trait::async_trait; use chrono::NaiveDateTime; @@ -29,7 +29,7 @@ pub trait UpdatableModel: Sync + Send { custom_error! { pub Error LocalConnectionFailed{source: r2d2::Error} = "Unable to connect to local database ({source}).", - DatabaseError{source: diesel::result::Error} = "Unable to run some operations on updatable model ({source}).", - UpdateError {source: InseeUpdateError} = "{source}", + Database{source: diesel::result::Error} = "Unable to run some operations on updatable model ({source}).", + Update {source: InseeUpdate} = "{source}", MissingInseeConnector = "Missing required Insee connector", } diff --git a/src/models/etablissement/error.rs b/src/models/etablissement/error.rs index 3a25487..8c4e1c9 100644 --- a/src/models/etablissement/error.rs +++ b/src/models/etablissement/error.rs @@ -3,14 +3,14 @@ use custom_error::custom_error; custom_error! { pub Error LocalConnectionFailed{source: r2d2::Error} = "Unable to connect to local database ({source}).", EtablissementNotFound = "Etablissement not found.", - DatabaseError{diesel_error: diesel::result::Error} = "Unable to run some operations on etablissement ({diesel_error}).", + Database{diesel_error: diesel::result::Error} = "Unable to run some operations on etablissement ({diesel_error}).", } impl From for Error { fn from(error: diesel::result::Error) -> Self { match error { diesel::result::Error::NotFound => Error::EtablissementNotFound, - _ => Error::DatabaseError { + _ => Error::Database { diesel_error: error, }, } diff --git a/src/models/etablissement/mod.rs b/src/models/etablissement/mod.rs index 2e3eabb..ffec4e3 100644 --- a/src/models/etablissement/mod.rs +++ b/src/models/etablissement/mod.rs @@ -13,27 +13,21 @@ use diesel::prelude::*; use diesel::sql_query; use error::Error; -pub fn get(connection: &Connection, siret: &String) -> Result { +pub fn get(connection: &Connection, siret: &str) -> Result { dsl::etablissement .find(siret) .first::(connection) .map_err(|error| error.into()) } -pub fn get_with_siren( - connection: &Connection, - siren: &String, -) -> Result, Error> { +pub fn get_with_siren(connection: &Connection, siren: &str) -> Result, Error> { dsl::etablissement .filter(dsl::siren.eq(siren)) .load::(connection) .map_err(|error| error.into()) } -pub fn get_siege_with_siren( - connection: &Connection, - siren: &String, -) -> Result { +pub fn get_siege_with_siren(connection: &Connection, siren: &str) -> Result { dsl::etablissement .filter(dsl::siren.eq(siren).and(dsl::etablissement_siege.eq(true))) .first::(connection) diff --git a/src/models/group_metadata/error.rs b/src/models/group_metadata/error.rs index ee4a943..d910029 100644 --- a/src/models/group_metadata/error.rs +++ b/src/models/group_metadata/error.rs @@ -3,14 +3,14 @@ use custom_error::custom_error; custom_error! { pub Error LocalConnectionFailed{source: r2d2::Error} = "Unable to connect to local database ({source}).", MetadataNotFound = "Metadata not found.", - DatabaseError{diesel_error: diesel::result::Error} = "Unable to run some operations on metadata ({diesel_error}).", + Database{diesel_error: diesel::result::Error} = "Unable to run some operations on metadata ({diesel_error}).", } impl From for Error { fn from(error: diesel::result::Error) -> Self { match error { diesel::result::Error::NotFound => Error::MetadataNotFound, - _ => Error::DatabaseError { + _ => Error::Database { diesel_error: error, }, } diff --git a/src/models/unite_legale/error.rs b/src/models/unite_legale/error.rs index d7cfe90..d7de2f0 100644 --- a/src/models/unite_legale/error.rs +++ b/src/models/unite_legale/error.rs @@ -3,14 +3,14 @@ use custom_error::custom_error; custom_error! { pub Error LocalConnectionFailed{source: r2d2::Error} = "Unable to connect to local database ({source}).", UniteLegaleNotFound = "Unite Legale not found.", - DatabaseError{diesel_error: diesel::result::Error} = "Unable to run some operations on unite_legale ({diesel_error}).", + Database{diesel_error: diesel::result::Error} = "Unable to run some operations on unite_legale ({diesel_error}).", } impl From for Error { fn from(error: diesel::result::Error) -> Self { match error { diesel::result::Error::NotFound => Error::UniteLegaleNotFound, - _ => Error::DatabaseError { + _ => Error::Database { diesel_error: error, }, } diff --git a/src/models/unite_legale/mod.rs b/src/models/unite_legale/mod.rs index 9b972f1..9450766 100644 --- a/src/models/unite_legale/mod.rs +++ b/src/models/unite_legale/mod.rs @@ -13,7 +13,7 @@ use diesel::prelude::*; use diesel::sql_query; use error::Error; -pub fn get(connection: &Connection, siren: &String) -> Result { +pub fn get(connection: &Connection, siren: &str) -> Result { dsl::unite_legale .find(siren) .first::(connection) diff --git a/src/models/update_metadata/error.rs b/src/models/update_metadata/error.rs index 6489649..067ba47 100644 --- a/src/models/update_metadata/error.rs +++ b/src/models/update_metadata/error.rs @@ -5,14 +5,14 @@ custom_error! { pub Error UpdateNotRegistered = "Unable to register this update in database.", LocalConnectionFailed{source: r2d2::Error} = "Unable to connect to local database ({source}).", MetadataNotFound = "Metadata not found.", - DatabaseError{diesel_error: diesel::result::Error} = "Unable to run some operations on metadata ({diesel_error}).", + Database{diesel_error: diesel::result::Error} = "Unable to run some operations on metadata ({diesel_error}).", } impl From for Error { fn from(error: diesel::result::Error) -> Self { match error { diesel::result::Error::NotFound => Error::MetadataNotFound, - _ => Error::DatabaseError { + _ => Error::Database { diesel_error: error, }, } diff --git a/src/update/action/download_stock.rs b/src/update/action/download_stock.rs index 17a055b..e33d314 100644 --- a/src/update/action/download_stock.rs +++ b/src/update/action/download_stock.rs @@ -38,13 +38,13 @@ impl Action for DownloadAction { .connect_timeout(Duration::from_secs(10)) .timeout(Duration::from_secs(3600)) .build() - .map_err(|req_error| Error::DownloadError { req_error })?; + .map_err(|req_error| Error::Download { req_error })?; let resp = client .get(&metadata.url) .send() .await - .map_err(|req_error| Error::DownloadError { req_error })?; + .map_err(|req_error| Error::Download { req_error })?; // Decode Last-Modified header let last_modified_str = resp @@ -94,7 +94,7 @@ impl Action for DownloadAction { // Create temp path create_dir_all(self.temp_folder.clone()) - .map_err(|io_error| Error::TempFolderCreationError { io_error })?; + .map_err(|io_error| Error::TempFolderCreation { io_error })?; // Get Zip path let mut zip_path = PathBuf::from(self.temp_folder.clone()); @@ -104,7 +104,7 @@ impl Action for DownloadAction { // Create an output file into which we will save current stock. let mut outfile = File::create(zip_path) .await - .map_err(|io_error| Error::FileCreationError { io_error })?; + .map_err(|io_error| Error::FileCreation { io_error })?; let mut stream = resp .bytes_stream() // Convert the body of the response into a futures::io::Stream. @@ -115,7 +115,7 @@ impl Action for DownloadAction { // Invoke tokio::io::copy to actually perform the download. tokio::io::copy(&mut stream, &mut outfile) .await - .map_err(|io_error| Error::FileCopyError { io_error })?; + .map_err(|io_error| Error::FileCopy { io_error })?; debug!("Download of {:#?} finished", group_type); diff --git a/src/update/action/mod.rs b/src/update/action/mod.rs index cff54bb..4dd5821 100644 --- a/src/update/action/mod.rs +++ b/src/update/action/mod.rs @@ -17,7 +17,7 @@ pub mod unzip_stock; pub async fn execute_step<'a>( step: Step, config: &Config, - groups: &Vec, + groups: &[GroupType], connectors: &mut Connectors, summary_delegate: &'a mut SummaryStepDelegate<'a>, ) -> Result<(), Error> { diff --git a/src/update/action/unzip_stock.rs b/src/update/action/unzip_stock.rs index 4f3cc85..795af26 100644 --- a/src/update/action/unzip_stock.rs +++ b/src/update/action/unzip_stock.rs @@ -86,23 +86,21 @@ impl Action for UnzipAction { if let Some(p) = csv_path.parent() { if !p.exists() { - create_dir_all(&p) - .map_err(|io_error| Error::FileFolderCreationError { io_error })?; + create_dir_all(&p).map_err(|io_error| Error::FileFolderCreation { io_error })?; } } - let zip_file = - File::open(&zip_path).map_err(|io_error| Error::ZipOpenError { io_error })?; - let mut archive = zip::ZipArchive::new(zip_file) - .map_err(|zip_error| Error::ZipDecodeError { zip_error })?; + let zip_file = File::open(&zip_path).map_err(|io_error| Error::ZipOpen { io_error })?; + let mut archive = + zip::ZipArchive::new(zip_file).map_err(|zip_error| Error::ZipDecode { zip_error })?; if archive.len() != 1 { - return Err(Error::ZipFormatError); + return Err(Error::ZipFormat); } let mut zipped_csv_file = archive .by_index(0) - .map_err(|zip_error| Error::ZipAccessFileError { zip_error })?; + .map_err(|zip_error| Error::ZipAccessFile { zip_error })?; debug!( "Unzipping file {:#?} extracted to \"{}\" ({} bytes)", @@ -112,9 +110,9 @@ impl Action for UnzipAction { ); let mut csv_file = - File::create(&csv_path).map_err(|io_error| Error::FileCSVCreationError { io_error })?; + File::create(&csv_path).map_err(|io_error| Error::FileCSVCreation { io_error })?; io::copy(&mut zipped_csv_file, &mut csv_file) - .map_err(|io_error| Error::FileCSVCopyError { io_error })?; + .map_err(|io_error| Error::FileCSVCopy { io_error })?; // Get and Set permissions #[cfg(unix)] @@ -122,7 +120,7 @@ impl Action for UnzipAction { use std::os::unix::fs::PermissionsExt; if let Some(mode) = zipped_csv_file.unix_mode() { set_permissions(&csv_path, Permissions::from_mode(mode)) - .map_err(|io_error| Error::FileCSVPermissionError { io_error })?; + .map_err(|io_error| Error::FileCSVPermission { io_error })?; } } diff --git a/src/update/error.rs b/src/update/error.rs index 210d865..deae064 100644 --- a/src/update/error.rs +++ b/src/update/error.rs @@ -1,4 +1,4 @@ -use crate::connectors::insee::error::InseeUpdateError; +use crate::connectors::insee::error::InseeUpdate; use crate::models; use crate::models::group_metadata::common::GroupType; use crate::models::{group_metadata, update_metadata}; @@ -7,29 +7,29 @@ use std::process; use tracing::error; custom_error! { pub Error - MetadataModelError {source: group_metadata::error::Error} = "Error on Metadata model: {source}", - UpdateMetadataModelError {source: update_metadata::error::Error} = "Error on UpdateMetadata model: {source}", - UpdatableModelError {source: models::common::Error} = "Error on UpdatableModel model: {source}", - TempFolderCreationError {io_error: std::io::Error} = "Unable to create temporary folder ({io_error})", - FileFolderCreationError {io_error: std::io::Error} = "Unable to create data folder ({io_error})", - FileCreationError {io_error: std::io::Error} = "Unable to create file for download ({io_error})", - FileCopyError {io_error: std::io::Error} = "Unable to copy file from download ({io_error})", - FileCSVCreationError {io_error: std::io::Error} = "Unable to create CSV file for unzip ({io_error})", - FileCSVCopyError {io_error: std::io::Error} = "Unable to copy CSV file from archive ({io_error})", - FileCSVPermissionError {io_error: std::io::Error} = "Unable to set permission for CSV file ({io_error})", - DownloadError {req_error: reqwest::Error} = "Unable to download data from remote server ({req_error})", - ZipOpenError {io_error: std::io::Error} = "Unable to open data zip file ({io_error})", - ZipDecodeError {zip_error: zip::result::ZipError} = "Unable to decode zip file ({zip_error})", - ZipFormatError = "Archive has more than one file inside it, you should review it before running it again", - ZipAccessFileError {zip_error: zip::result::ZipError} = "Unable to open file in archive ({zip_error})", + MetadataModel {source: group_metadata::error::Error} = "Error on Metadata model: {source}", + UpdateMetadataModel {source: update_metadata::error::Error} = "Error on UpdateMetadata model: {source}", + UpdatableModel {source: models::common::Error} = "Error on UpdatableModel model: {source}", + TempFolderCreation {io_error: std::io::Error} = "Unable to create temporary folder ({io_error})", + FileFolderCreation {io_error: std::io::Error} = "Unable to create data folder ({io_error})", + FileCreation {io_error: std::io::Error} = "Unable to create file for download ({io_error})", + FileCopy {io_error: std::io::Error} = "Unable to copy file from download ({io_error})", + FileCSVCreation {io_error: std::io::Error} = "Unable to create CSV file for unzip ({io_error})", + FileCSVCopy {io_error: std::io::Error} = "Unable to copy CSV file from archive ({io_error})", + FileCSVPermission {io_error: std::io::Error} = "Unable to set permission for CSV file ({io_error})", + Download {req_error: reqwest::Error} = "Unable to download data from remote server ({req_error})", + ZipOpen {io_error: std::io::Error} = "Unable to open data zip file ({io_error})", + ZipDecode {zip_error: zip::result::ZipError} = "Unable to decode zip file ({zip_error})", + ZipFormat = "Archive has more than one file inside it, you should review it before running it again", + ZipAccessFile {zip_error: zip::result::ZipError} = "Unable to open file in archive ({zip_error})", MissingLastModifiedHeader = "Needed header 'Last-Modified' is missing while downloading", InvalidLastModifiedHeader {head_error: reqwest::header::ToStrError} = "Needed header 'Last-Modified' is invalid while downloading ({head_error})", InvalidLastModifiedDate {date_error: chrono::format::ParseError} = "Needed header 'Last-Modified' is invalid while downloading ({date_error})", InvalidCSVPath = "Invalid CSV path, not UTF8 compatible", InvalidComponentInCSVPath {io_error: std::io::Error} = "Invalid component in CSV path ({io_error})", SwapStoppedTooMuchDifference {group_type: GroupType} = "Swapping stopped on {group_type}, more than 1% difference between the old values and the new ones. Use --force to override", - SyncInseeError {source: InseeUpdateError} = "{source}", - WaitThreadError {source: tokio::task::JoinError} = "Error while waiting for thread: {source}", + SyncInsee {source: InseeUpdate} = "{source}", + WaitThread {source: tokio::task::JoinError} = "Error while waiting for thread: {source}", } impl Error { diff --git a/src/update/mod.rs b/src/update/mod.rs index a305c16..6f5643d 100644 --- a/src/update/mod.rs +++ b/src/update/mod.rs @@ -1,4 +1,5 @@ use crate::connectors::Connectors; +use crate::models::group_metadata::common::GroupType; use crate::models::update_metadata; use crate::models::update_metadata::common::{ Step, SyntheticGroupType, UpdateMetadata, UpdateSummary, @@ -47,7 +48,7 @@ async fn execute_workflow( connectors: &mut Connectors, ) -> Result { // Execute workflow - let mut summary = UpdateSummary::new(); + let mut summary = UpdateSummary::default(); summary.start( connectors, @@ -76,36 +77,38 @@ async fn execute_workflow( handle.await??; } - Ok(update_metadata::current_update(&connectors)?) + Ok(update_metadata::current_update(connectors)?) } async fn execute_workflow_thread( workflow: Vec, synthetic_group_type: SyntheticGroupType, config: Config, - mut connectors: &mut Connectors, + connectors: &mut Connectors, mut summary: UpdateSummary, ) -> Result<(), Error> { debug!("Starting"); for step in workflow.into_iter() { + let groups: Vec = synthetic_group_type.into(); + execute_step( step, &config, - &synthetic_group_type.into(), - &mut connectors, + groups.as_slice(), + connectors, &mut summary.step_delegate(step), ) .await .or_else(|error| { error!("Errored: {}", error.to_string()); - update_metadata::error_update(&mut connectors, error.to_string(), Utc::now())?; + update_metadata::error_update(connectors, error.to_string(), Utc::now())?; Err(error) })?; } - summary.finish(&mut connectors)?; + summary.finish(connectors)?; debug!("Finished"); diff --git a/src/update/summary.rs b/src/update/summary.rs index 8454198..d37d200 100644 --- a/src/update/summary.rs +++ b/src/update/summary.rs @@ -17,8 +17,8 @@ pub struct SummaryGroupDelegate<'a, 'b> { step_delegate: &'b mut SummaryStepDelegate<'a>, } -impl UpdateSummary { - pub fn new() -> Self { +impl Default for UpdateSummary { + fn default() -> Self { UpdateSummary { steps: vec![], updated: false, @@ -26,8 +26,10 @@ impl UpdateSummary { finished_timestamp: None, } } +} - pub fn step_delegate<'a>(&'a mut self, step: Step) -> SummaryStepDelegate<'a> { +impl UpdateSummary { + pub fn step_delegate(&'_ mut self, step: Step) -> SummaryStepDelegate<'_> { let step_summary = UpdateStepSummary { step, updated: false, @@ -61,7 +63,7 @@ impl UpdateSummary { pub fn finish(&mut self, connectors: &Connectors) -> Result<(), Error> { self.finished_timestamp = Some(Utc::now()); - self.updated = self.steps.iter().find(|s| s.updated).is_some(); + self.updated = self.steps.iter().any(|s| s.updated); update_metadata::finished_update(connectors, self.clone()).map(|_| Ok(()))? } @@ -97,7 +99,7 @@ impl<'a> SummaryStepDelegate<'a> { pub fn finish(&mut self, connectors: &Connectors) -> Result<(), Error> { if let Some(step_summary) = self.summary.steps.first_mut() { step_summary.finished_timestamp = Some(Utc::now()); - step_summary.updated = step_summary.groups.iter().find(|g| g.updated).is_some(); + step_summary.updated = step_summary.groups.iter().any(|g| g.updated); } update_metadata::progress_update(connectors, self.summary.clone()).map(|_| Ok(()))?