From 3ade5aeba94539432c949f96255869a03abf7948 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Thu, 21 Jan 2021 21:21:16 -0500 Subject: [PATCH] Add ability to search by URL, rate limit headers (#2) * Initial progress on searching by URL. * Avoid rejections for error messages. * Handle some more rejections. * Fix build issues. * Remove detailed error messages. * Fix issue with built Docker image. * Add rate limit headers to all responses. * Remove unneeded dependency. * Limit URLs to 10MB. --- .drone.yml | 4 + Cargo.lock | 1073 +++++++++++++++++++++++++---------------------- Cargo.toml | 19 +- Dockerfile | 2 + src/filters.rs | 18 +- src/handlers.rs | 319 +++++++++----- src/main.rs | 12 +- src/types.rs | 7 +- src/utils.rs | 51 ++- 9 files changed, 878 insertions(+), 627 deletions(-) diff --git a/.drone.yml b/.drone.yml index ba1f691..a723c2f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -37,4 +37,8 @@ steps: exclude: - master +--- +kind: signature +hmac: c17d371c096be4b0544aad509cd58fa475e8737ac2c2dd77db5603044e3a5892 + ... diff --git a/Cargo.lock b/Cargo.lock index b00810d..ee5443e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,7 +18,28 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "winapi 0.3.9", + "winapi", +] + +[[package]] +name = "async-stream" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3670df70cbc01729f901f94c887814b3c68db038aad1329a418bae178bc5295c" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3548b8efc9f8e8a5a0a2808c5bd8451a9031b9e5b879a79590304ae928b0a70" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -32,12 +53,6 @@ dependencies = [ "syn", ] -[[package]] -name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - [[package]] name = "autocfg" version = "1.0.1" @@ -50,12 +65,6 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - [[package]] name = "base64" version = "0.13.0" @@ -64,26 +73,26 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bb8" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a4d5a11ea6fe65800f3225ab57f7c28024595c99e809a0ca7eee60a8e3fa24b" +checksum = "dae93eccab998c4b8703e3a6bbaa1714c38e445ebacb4bede25d0408521e293c" dependencies = [ "async-trait", "futures-channel", "futures-util", "parking_lot", - "tokio 0.3.5", + "tokio", ] [[package]] name = "bb8-postgres" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7556910cdbd798b51b16da3a93dfc4cc303b326503a8d03e830d11fe3969ae1d" +checksum = "61fdf56d52b2cca401d2380407e5c35d3d25d3560224ecf74d6e4ca13e51239b" dependencies = [ "async-trait", "bb8", - "tokio 0.3.5", + "tokio", "tokio-postgres", ] @@ -139,6 +148,12 @@ dependencies = [ "safemem", ] +[[package]] +name = "bumpalo" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" + [[package]] name = "byte-tools" version = "0.3.1" @@ -147,27 +162,21 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytemuck" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41aa2ec95ca3b5c54cf73c91acf06d24f4495d5f1b1c12506ae3483d646177ac" +checksum = "5a4bad0c5981acc24bc09e532f35160f952e35422603f0563cd7a73c2c2e65a0" [[package]] name = "byteorder" -version = "1.3.4" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" [[package]] name = "bytes" -version = "0.5.6" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - -[[package]] -name = "bytes" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0dcbc35f504eb6fc275a6d20e4ebcda18cf50d40ba6fabff8c711fa16cb3b16" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cc" @@ -197,16 +206,7 @@ dependencies = [ "num-integer", "num-traits", "time", - "winapi 0.3.9", -] - -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", + "winapi", ] [[package]] @@ -217,9 +217,25 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "const_fn" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c478836e029dcef17fb47c89023448c64f781a046e0300e257ad8225ae59afab" +checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" + +[[package]] +name = "core-foundation" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "cpuid-bool" @@ -277,16 +293,16 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" dependencies = [ - "autocfg 1.0.1", + "autocfg", "cfg-if 1.0.0", "lazy_static", ] [[package]] name = "crypto-mac" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58bcd97a54c7ca5ce2f6eb16f6bede5b0ab5f0055fedc17d2f0b4466e21671ca" +checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" dependencies = [ "generic-array 0.14.4", "subtle", @@ -320,18 +336,21 @@ dependencies = [ "generic-array 0.14.4", ] -[[package]] -name = "dtoa" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" - [[package]] name = "either" version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "encoding_rs" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801bbab217d7f79c0062f4f7205b5d4427c6d1a7bd7aafdd1475f7c59d62b283" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "fake-simd" version = "0.1.2" @@ -350,6 +369,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.0.0" @@ -360,33 +394,11 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futures" -version = "0.3.8" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b3b0c040a1fe6529d30b3c5944b280c7f0dcb2930d2c3062bca967b602583d0" +checksum = "da9052a1a50244d8d5aa9bf55cbc2fb6f357c86cc52e46c62ed390a7180cf150" dependencies = [ "futures-channel", "futures-core", @@ -399,9 +411,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.8" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64" +checksum = "f2d31b7ec7efab6eefc7c57233bb10b847986139d88cc2f5a02a1ae6871a1846" dependencies = [ "futures-core", "futures-sink", @@ -409,15 +421,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.8" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748" +checksum = "79e5145dde8da7d1b3892dad07a9c98fc04bc39892b1ecc9692cf53e2b780a65" [[package]] name = "futures-executor" -version = "0.3.8" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4caa2b2b68b880003057c1dd49f1ed937e38f22fcf6c212188a121f08cf40a65" +checksum = "e9e59fdc009a4b3096bf94f740a0f2424c082521f20a9b08c5c07c48d90fd9b9" dependencies = [ "futures-core", "futures-task", @@ -426,15 +438,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.8" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" +checksum = "28be053525281ad8259d47e4de5de657b25e7bac113458555bb4b70bc6870500" [[package]] name = "futures-macro" -version = "0.3.8" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556" +checksum = "c287d25add322d9f9abdcdc5927ca398917996600182178774032e9f8258fedd" dependencies = [ "proc-macro-hack", "proc-macro2", @@ -444,24 +456,24 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.8" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f878195a49cee50e006b02b93cf7e0a95a38ac7b776b4c4d9cc1207cd20fcb3d" +checksum = "caf5c69029bda2e743fddd0582d1083951d65cc9539aebf8812f36c3491342d6" [[package]] name = "futures-task" -version = "0.3.8" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d" +checksum = "13de07eb8ea81ae445aca7b69f5f7bf15d7bf4912d8ca37d6645c77ae8a58d86" dependencies = [ "once_cell", ] [[package]] name = "futures-util" -version = "0.3.8" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" +checksum = "632a8cd0f2a4b3fdea1657f08bde063848c3bd00f9bbf6e256b8be78802e624b" dependencies = [ "futures-channel", "futures-core", @@ -470,7 +482,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project 1.0.2", + "pin-project-lite", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -481,20 +493,23 @@ dependencies = [ name = "fuzzysearch" version = "0.1.0" dependencies = [ + "async-stream", "bb8", "bb8-postgres", "bk-tree", - "bytes 0.5.6", + "bytes", "chrono", "futures", - "futures-util", "hamming", + "hyper", "image", "img_hash", "opentelemetry", "opentelemetry-jaeger", + "reqwest", "serde", - "tokio 0.3.5", + "serde_json", + "tokio", "tokio-postgres", "tracing", "tracing-futures", @@ -503,19 +518,6 @@ dependencies = [ "warp", ] -[[package]] -name = "generator" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cdc09201b2e8ca1b19290cf7e65de2246b8e91fb6874279722189c4de7b94dc" -dependencies = [ - "cc", - "libc", - "log", - "rustc_version", - "winapi 0.3.9", -] - [[package]] name = "generic-array" version = "0.12.3" @@ -537,15 +539,26 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.1+wasi-snapshot-preview1", +] + [[package]] name = "gif" version = "0.11.1" @@ -558,11 +571,11 @@ dependencies = [ [[package]] name = "h2" -version = "0.2.7" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" +checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5" dependencies = [ - "bytes 0.5.6", + "bytes", "fnv", "futures-core", "futures-sink", @@ -570,8 +583,8 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 0.2.23", - "tokio-util 0.3.1", + "tokio", + "tokio-util", "tracing", "tracing-futures", ] @@ -590,13 +603,13 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" [[package]] name = "headers" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed18eb2459bf1a09ad2d6b1547840c3e5e62882fa09b9a6a20b1de8e3228848f" +checksum = "62689dc57c7456e69712607ffcbd0aa1dfcccf9af73727e9b25bc1825375cac3" dependencies = [ - "base64 0.12.3", + "base64 0.13.0", "bitflags", - "bytes 0.5.6", + "bytes", "headers-core", "http", "mime", @@ -615,18 +628,18 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] [[package]] name = "hmac" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deae6d9dbb35ec2c502d62b8f7b1c000a0822c3b0794ba36b3149c0a1c840dff" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" dependencies = [ "crypto-mac", "digest 0.9.0", @@ -634,22 +647,22 @@ dependencies = [ [[package]] name = "http" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" +checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ - "bytes 0.5.6", + "bytes", "fnv", "itoa", ] [[package]] name = "http-body" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" dependencies = [ - "bytes 0.5.6", + "bytes", "http", ] @@ -667,11 +680,11 @@ checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" [[package]] name = "hyper" -version = "0.13.9" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ad767baac13b44d4529fcf58ba2cd0995e36e7b435bc5b039de6f47e880dbf" +checksum = "12219dc884514cb4a6a03737f4413c0e01c23a1b059b0156004b23f1e19dccbe" dependencies = [ - "bytes 0.5.6", + "bytes", "futures-channel", "futures-core", "futures-util", @@ -681,14 +694,27 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project 1.0.2", + "pin-project 1.0.4", "socket2", - "tokio 0.2.23", + "tokio", "tower-service", "tracing", "want", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "idna" version = "0.2.0" @@ -734,21 +760,21 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" dependencies = [ - "autocfg 1.0.1", + "autocfg", "hashbrown", ] [[package]] name = "input_buffer" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" +checksum = "f97967975f448f1a7ddb12b0bc41069d09ed6a1c161a92687e057325db35d413" dependencies = [ - "bytes 0.5.6", + "bytes", ] [[package]] @@ -762,24 +788,21 @@ dependencies = [ [[package]] name = "integer-encoding" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4ebd0bd29be0f11973e9b3e219005661042a019fd757798c36a47c87852625" +checksum = "f6104619c35f8835695e517cfb80fb7142139ee4b53f4d0fa4c8dca6e98fbc66" [[package]] -name = "iovec" -version = "0.1.4" +name = "ipnet" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] +checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" [[package]] name = "itoa" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "jpeg-decoder" @@ -792,13 +815,12 @@ dependencies = [ ] [[package]] -name = "kernel32-sys" -version = "0.2.2" +name = "js-sys" +version = "0.3.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "wasm-bindgen", ] [[package]] @@ -809,9 +831,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" +checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" [[package]] name = "lock_api" @@ -824,26 +846,13 @@ dependencies = [ [[package]] name = "log" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2" dependencies = [ "cfg-if 0.1.10", ] -[[package]] -name = "loom" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0e8460f2f2121162705187214720353c517b97bdfb3494c0b1e33d83ebe4bed" -dependencies = [ - "cfg-if 0.1.10", - "generator", - "scoped-tls", - "serde", - "serde_json", -] - [[package]] name = "matchers" version = "0.0.1" @@ -877,7 +886,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" dependencies = [ - "autocfg 1.0.1", + "autocfg", ] [[package]] @@ -912,51 +921,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" dependencies = [ "adler", - "autocfg 1.0.1", + "autocfg", ] [[package]] name = "mio" -version = "0.6.23" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow 0.2.2", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "mio" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f33bc887064ef1fd66020c9adfc45bb9f33d75a42096c81e7c56c65b75dd1a8b" +checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" dependencies = [ "libc", "log", - "miow 0.3.6", + "miow", "ntapi", - "winapi 0.3.9", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "winapi", ] [[package]] @@ -966,14 +944,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a33c1b55807fbed163481b5ba66db4b2fa6cde694a5027be10fb724206c5897" dependencies = [ "socket2", - "winapi 0.3.9", + "winapi", ] [[package]] name = "multipart" -version = "0.17.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8209c33c951f07387a8497841122fc6f712165e3f9bda3e6be4645b58188f676" +checksum = "d050aeedc89243f5347c3e237e3e13dc76fbe4ae3742a57b94dc14f69acf76d4" dependencies = [ "buf_redux", "httparse", @@ -981,21 +959,28 @@ dependencies = [ "mime", "mime_guess", "quick-error", - "rand 0.6.5", + "rand 0.7.3", "safemem", "tempfile", "twoway", ] [[package]] -name = "net2" -version = "0.2.36" +name = "native-tls" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cf75f38f16cb05ea017784dc6dbfd354f76c223dba37701734c4f5a9337d02" +checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ - "cfg-if 0.1.10", + "lazy_static", "libc", - "winapi 0.3.9", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", ] [[package]] @@ -1004,7 +989,7 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1013,7 +998,7 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-traits", ] @@ -1023,7 +1008,7 @@ version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-traits", ] @@ -1033,7 +1018,7 @@ version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-integer", "num-traits", ] @@ -1044,7 +1029,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" dependencies = [ - "autocfg 1.0.1", + "autocfg", "num-integer", "num-traits", ] @@ -1055,7 +1040,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ - "autocfg 1.0.1", + "autocfg", ] [[package]] @@ -1086,6 +1071,39 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "openssl" +version = "0.10.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" + +[[package]] +name = "openssl-sys" +version = "0.9.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "opentelemetry" version = "0.6.0" @@ -1132,16 +1150,16 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c6d9b8427445284a09c55be860a15855ab580a417ccad9da88f5a06787ced0" +checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272" dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall", + "redox_syscall 0.1.57", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1179,11 +1197,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7" +checksum = "95b70b68509f17aa2857863b6fa00bf21fc93674c7a8893de2f469f6aa7ca2f2" dependencies = [ - "pin-project-internal 1.0.2", + "pin-project-internal 1.0.4", ] [[package]] @@ -1199,9 +1217,9 @@ dependencies = [ [[package]] name = "pin-project-internal" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f" +checksum = "caa25a6393f22ce819b0f50e0be89287292fda8d425be38ee0ca14c4931d9e71" dependencies = [ "proc-macro2", "quote", @@ -1210,15 +1228,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.1.11" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" - -[[package]] -name = "pin-project-lite" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" +checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" [[package]] name = "pin-utils" @@ -1227,10 +1239,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "png" -version = "0.16.7" +name = "pkg-config" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfe7f9f1c730833200b134370e1d5098964231af8450bce9b78ee3ab5278b970" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" + +[[package]] +name = "png" +version = "0.16.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" dependencies = [ "bitflags", "crc32fast", @@ -1240,29 +1258,29 @@ dependencies = [ [[package]] name = "postgres-protocol" -version = "0.5.3" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4888a0e36637ab38d76cace88c1476937d617ad015f07f6b669cec11beacc019" +checksum = "70e34ad3dc5c56d036b9418185ee97e14b6766d55c8ccf9dc18302ad4e6371d9" dependencies = [ "base64 0.13.0", "byteorder", - "bytes 0.5.6", + "bytes", "fallible-iterator", "hmac", "md5", "memchr", - "rand 0.7.3", + "rand 0.8.2", "sha2", "stringprep", ] [[package]] name = "postgres-types" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfc08a7d94a80665de4a83942fa8db2fdeaf2f123fc0535e384dc4fff251efae" +checksum = "5493d9d4613b88b12433aa12890e74e74cd93fdc1e08b7c2aed4768aaae8414c" dependencies = [ - "bytes 0.5.6", + "bytes", "fallible-iterator", "postgres-protocol", ] @@ -1281,9 +1299,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro-nested" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" [[package]] name = "proc-macro2" @@ -1310,9 +1328,9 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.18.1" +version = "2.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da78e04bc0e40f36df43ecc6575e4f4b180e8156c4efd73f13d5619479b05696" +checksum = "86473d5f16580f10b131a0bf0afb68f8e029d1835d33a00f37281b05694e5312" [[package]] name = "quick-error" @@ -1322,39 +1340,20 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.9", -] - [[package]] name = "rand" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.16", "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", @@ -1362,13 +1361,15 @@ dependencies = [ ] [[package]] -name = "rand_chacha" -version = "0.1.1" +name = "rand" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +checksum = "18519b42a40024d661e1714153e9ad0c3de27cd495760ceb09710920f1098b1e" dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.1", + "rand_hc 0.3.0", ] [[package]] @@ -1382,36 +1383,31 @@ dependencies = [ ] [[package]] -name = "rand_core" -version = "0.3.1" +name = "rand_chacha" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ - "rand_core 0.4.2", + "ppv-lite86", + "rand_core 0.6.1", ] -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", ] [[package]] -name = "rand_hc" -version = "0.1.0" +name = "rand_core" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +checksum = "c026d7df8b298d90ccbbc5190bd04d85e159eaf5576caeacf8741da93ccbd2e5" dependencies = [ - "rand_core 0.3.1", + "getrandom 0.2.2", ] [[package]] @@ -1424,56 +1420,12 @@ dependencies = [ ] [[package]] -name = "rand_isaac" -version = "0.1.1" +name = "rand_hc" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.9", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", + "rand_core 0.6.1", ] [[package]] @@ -1482,7 +1434,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674" dependencies = [ - "autocfg 1.0.1", + "autocfg", "crossbeam-deque", "either", "rayon-core", @@ -1501,15 +1453,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.1.57" @@ -1517,10 +1460,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] -name = "regex" -version = "1.4.2" +name = "redox_syscall" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" +checksum = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" dependencies = [ "regex-syntax", ] @@ -1537,9 +1489,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" +checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" [[package]] name = "remove_dir_all" @@ -1547,16 +1499,41 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] -name = "rustc_version" -version = "0.2.3" +name = "reqwest" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +checksum = "fd281b1030aa675fb90aa994d07187645bb3c8fc756ca766e7c3070b439de9de" dependencies = [ - "semver", + "base64 0.13.0", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", ] [[package]] @@ -1593,6 +1570,16 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + [[package]] name = "scoped-tls" version = "1.0.0" @@ -1612,34 +1599,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] -name = "semver" -version = "0.9.0" +name = "security-framework" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" dependencies = [ - "semver-parser", + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", ] [[package]] -name = "semver-parser" -version = "0.7.0" +name = "security-framework-sys" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" +dependencies = [ + "core-foundation-sys", + "libc", +] [[package]] name = "serde" -version = "1.0.118" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" +checksum = "166b2349061381baf54a58e4b13c89369feb0ef2eaa57198899e2312aac30aab" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.118" +version = "1.0.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" +checksum = "0ca2a8cb5805ce9e3b95435e3765b7b553cecc762d938d409434338386cb5775" dependencies = [ "proc-macro2", "quote", @@ -1648,9 +1643,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779" +checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" dependencies = [ "itoa", "ryu", @@ -1659,14 +1654,14 @@ dependencies = [ [[package]] name = "serde_urlencoded" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" dependencies = [ - "dtoa", + "form_urlencoded", "itoa", + "ryu", "serde", - "url", ] [[package]] @@ -1709,12 +1704,20 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4921be914e16899a80adefb821f8ddb7974e3f1250223575a44ed994882127" +checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" dependencies = [ "lazy_static", - "loom", +] + +[[package]] +name = "signal-hook-registry" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +dependencies = [ + "libc", ] [[package]] @@ -1731,20 +1734,19 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "1.5.1" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "socket2" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1771,15 +1773,15 @@ dependencies = [ [[package]] name = "subtle" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.53" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8833e20724c24de12bbaba5ad230ea61c3eafb05b881c7c9d3cfe8638b187e68" +checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" dependencies = [ "proc-macro2", "quote", @@ -1788,23 +1790,23 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", - "rand 0.7.3", - "redox_syscall", + "rand 0.8.2", + "redox_syscall 0.2.4", "remove_dir_all", - "winapi 0.3.9", + "winapi", ] [[package]] name = "thread_local" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447" dependencies = [ "lazy_static", ] @@ -1833,9 +1835,9 @@ dependencies = [ [[package]] name = "tiff" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abeb4e3f32a8973722c0254189e6890358e72b1bf11becb287ee0b23c595a41d" +checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" dependencies = [ "jpeg-decoder", "miniz_oxide 0.4.3", @@ -1844,13 +1846,12 @@ dependencies = [ [[package]] name = "time" -version = "0.1.44" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1870,46 +1871,29 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "0.2.23" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6d7ad61edd59bfcc7e80dababf0f4aed2e6d5e0ba1659356ae889752dfc12ff" +checksum = "0ca04cec6ff2474c638057b65798f60ac183e5e79d3448bb7163d36a39cff6ec" dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "iovec", - "lazy_static", - "memchr", - "mio 0.6.23", - "pin-project-lite 0.1.11", - "slab", -] - -[[package]] -name = "tokio" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12a3eb39ee2c231be64487f1fcbe726c8f2514876a55480a5ab8559fc374252" -dependencies = [ - "autocfg 1.0.1", - "bytes 0.6.0", - "futures-core", - "lazy_static", + "autocfg", + "bytes", "libc", "memchr", - "mio 0.7.6", + "mio", "num_cpus", + "once_cell", "parking_lot", - "pin-project-lite 0.2.0", - "slab", + "pin-project-lite", + "signal-hook-registry", "tokio-macros", + "winapi", ] [[package]] name = "tokio-macros" -version = "0.3.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21d30fdbb5dc2d8f91049691aa1a9d4d4ae422a21c334ce8936e5886d30c5c45" +checksum = "42517d2975ca3114b22a16192634e8241dc5cc1f130be194645970cc1c371494" dependencies = [ "proc-macro2", "quote", @@ -1917,66 +1901,76 @@ dependencies = [ ] [[package]] -name = "tokio-postgres" -version = "0.6.0" +name = "tokio-native-tls" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "150d9be163b0df6dc185b8ee33bcb9a74865f0cad754495847f2e06e2051a345" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-postgres" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cc9f82c2bfb06a33dd0dfb44b07ca98fe72df19e681d80c78d05a1bac2138e2" dependencies = [ "async-trait", "byteorder", - "bytes 0.5.6", + "bytes", "fallible-iterator", "futures", "log", "parking_lot", "percent-encoding", "phf", - "pin-project-lite 0.1.11", + "pin-project-lite", "postgres-protocol", "postgres-types", - "tokio 0.3.5", - "tokio-util 0.4.0", + "socket2", + "tokio", + "tokio-util", +] + +[[package]] +name = "tokio-stream" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76066865172052eb8796c686f0b441a93df8b08d40a950b062ffb9a426f00edd" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", ] [[package]] name = "tokio-tungstenite" -version = "0.11.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d9e878ad426ca286e4dcae09cbd4e1973a7f8987d97570e2469703dd7f5720c" +checksum = "e1a5f475f1b9d077ea1017ecbc60890fda8e54942d680ca0b1d2b47cfa2d861b" dependencies = [ "futures-util", "log", - "pin-project 0.4.27", - "tokio 0.2.23", + "pin-project 1.0.4", + "tokio", "tungstenite", ] [[package]] name = "tokio-util" -version = "0.3.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +checksum = "feb971a26599ffd28066d387f109746df178eff14d5ea1e235015c5601967a4b" dependencies = [ - "bytes 0.5.6", + "async-stream", + "bytes", "futures-core", "futures-sink", "log", - "pin-project-lite 0.1.11", - "tokio 0.2.23", -] - -[[package]] -name = "tokio-util" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24793699f4665ba0416ed287dc794fe6b11a4aa5e4e95b58624f45f6c46b97d4" -dependencies = [ - "bytes 0.5.6", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.1.11", - "tokio 0.3.5", + "pin-project-lite", + "tokio", + "tokio-stream", ] [[package]] @@ -1993,7 +1987,7 @@ checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.0", + "pin-project-lite", "tracing-attributes", "tracing-core", ] @@ -2109,18 +2103,18 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "tungstenite" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" +checksum = "8ada8297e8d70872fa9a551d93250a9f407beb9f37ef86494eb20012a2ff7c24" dependencies = [ - "base64 0.12.3", + "base64 0.13.0", "byteorder", - "bytes 0.5.6", + "bytes", "http", "httparse", "input_buffer", "log", - "rand 0.7.3", + "rand 0.8.2", "sha-1 0.9.2", "url", "utf-8", @@ -2186,18 +2180,18 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "urlencoding" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9232eb53352b4442e40d7900465dfc534e8cb2dc8f18656fcb2ac16112b5593" - [[package]] name = "utf-8" version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" +[[package]] +name = "vcpkg" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" + [[package]] name = "version_check" version = "0.9.2" @@ -2216,11 +2210,11 @@ dependencies = [ [[package]] name = "warp" -version = "0.2.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f41be6df54c97904af01aa23e613d4521eed7ab23537cede692d4058f6449407" +checksum = "3dafd0aac2818a94a34df0df1100a7356c493d8ede4393875fd0b5c51bb6bc80" dependencies = [ - "bytes 0.5.6", + "bytes", "futures", "headers", "http", @@ -2229,17 +2223,19 @@ dependencies = [ "mime", "mime_guess", "multipart", - "pin-project 0.4.27", + "percent-encoding", + "pin-project 1.0.4", "scoped-tls", "serde", "serde_json", "serde_urlencoded", - "tokio 0.2.23", + "tokio", + "tokio-stream", "tokio-tungstenite", + "tokio-util", "tower-service", "tracing", "tracing-futures", - "urlencoding", ] [[package]] @@ -2250,9 +2246,87 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +version = "0.10.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "93c6c3420963c5c64bca373b25e77acb562081b9bb4dd5bb864187742186cea9" + +[[package]] +name = "wasm-bindgen" +version = "0.2.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" +dependencies = [ + "cfg-if 1.0.0", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe9756085a84584ee9457a002b7cdfe0bfff169f45d2591d8be1345a6780e35" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" + +[[package]] +name = "web-sys" +version = "0.3.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" +dependencies = [ + "js-sys", + "wasm-bindgen", +] [[package]] name = "weezl" @@ -2260,12 +2334,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2bb9fc8309084dd7cd651336673844c1d47f8ef6d2091ec160b27f5c4aa277" -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -2276,12 +2344,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -2295,11 +2357,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "ws2_32-sys" -version = "0.2.1" +name = "winreg" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 83a7ce7..02404a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,19 +13,24 @@ opentelemetry = "0.6" opentelemetry-jaeger = "0.5" tracing-opentelemetry = "0.5" -tokio = { version = "0.3", features = ["macros", "rt-multi-thread", "sync"] } +tokio = { version = "1", features = ["full"] } +async-stream = "0.3" + futures = "0.3" -futures-util = "0.3" chrono = "0.4" -bytes = "0.5" +bytes = "1" serde = { version = "1", features = ["derive"] } -warp = "0.2" +serde_json = "1" -tokio-postgres = "0.6" -bb8 = "0.6" -bb8-postgres = "0.6" +warp = "0.3" +reqwest = "0.11" +hyper = "0.14" + +tokio-postgres = "0.7" +bb8 = "0.7" +bb8-postgres = "0.7" img_hash = "3" image = "0.23" diff --git a/Dockerfile b/Dockerfile index 186616d..46e231d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ FROM rust:1-slim AS builder WORKDIR /src +RUN apt-get update -y && apt-get install -y libssl-dev pkg-config COPY . . RUN cargo install --root / --path . FROM debian:buster-slim EXPOSE 8080 WORKDIR /app +RUN apt-get update -y && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/* COPY --from=builder /bin/fuzzysearch /bin/fuzzysearch CMD ["/bin/fuzzysearch"] diff --git a/src/filters.rs b/src/filters.rs index dabbd04..4cfb4a0 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -10,9 +10,10 @@ pub fn search( ) -> impl Filter + Clone { search_image(db.clone(), tree.clone()) .or(search_hashes(db.clone(), tree.clone())) - .or(stream_search_image(db.clone(), tree)) + .or(stream_search_image(db.clone(), tree.clone())) .or(search_file(db.clone())) - .or(check_handle(db)) + .or(check_handle(db.clone())) + .or(search_image_by_url(db, tree)) } pub fn search_file(db: Pool) -> impl Filter + Clone { @@ -54,6 +55,19 @@ pub fn search_image( }) } +pub fn search_image_by_url( + db: Pool, + tree: Tree, +) -> impl Filter + Clone { + warp::path("url") + .and(warp::get()) + .and(warp::query::()) + .and(with_pool(db)) + .and(with_tree(tree)) + .and(with_api_key()) + .and_then(handlers::search_image_by_url) +} + pub fn search_hashes( db: Pool, tree: Tree, diff --git a/src/handlers.rs b/src/handlers.rs index c28b3b2..d45e73a 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1,27 +1,56 @@ use crate::models::{image_query, image_query_sync}; use crate::types::*; -use crate::{rate_limit, Pool, Tree}; +use crate::{early_return, rate_limit, Pool, Tree}; +use std::convert::TryInto; use tracing::{span, warn}; use tracing_futures::Instrument; -use warp::{reject, Rejection, Reply}; - -fn map_bb8_err(err: bb8::RunError) -> Rejection { - reject::custom(Error::from(err)) -} - -fn map_postgres_err(err: tokio_postgres::Error) -> Rejection { - reject::custom(Error::from(err)) -} +use warp::{Rejection, Reply}; #[derive(Debug)] enum Error { BB8(bb8::RunError), Postgres(tokio_postgres::Error), + Reqwest(reqwest::Error), InvalidData, + InvalidImage, ApiKey, RateLimit, } +impl warp::Reply for Error { + fn into_response(self) -> warp::reply::Response { + let msg = match self { + Error::BB8(_) | Error::Postgres(_) | Error::Reqwest(_) => ErrorMessage { + code: 500, + message: "Internal server error".to_string(), + }, + Error::InvalidData => ErrorMessage { + code: 400, + message: "Invalid data provided".to_string(), + }, + Error::InvalidImage => ErrorMessage { + code: 400, + message: "Invalid image provided".to_string(), + }, + Error::ApiKey => ErrorMessage { + code: 401, + message: "Invalid API key".to_string(), + }, + Error::RateLimit => ErrorMessage { + code: 429, + message: "Too many requests".to_string(), + }, + }; + + let body = hyper::body::Body::from(serde_json::to_string(&msg).unwrap()); + + warp::http::Response::builder() + .status(msg.code) + .body(body) + .unwrap() + } +} + impl From> for Error { fn from(err: bb8::RunError) -> Self { Error::BB8(err) @@ -34,12 +63,16 @@ impl From for Error { } } -impl warp::reject::Reject for Error {} +impl From for Error { + fn from(err: reqwest::Error) -> Self { + Error::Reqwest(err) + } +} #[tracing::instrument(skip(form))] async fn hash_input(form: warp::multipart::FormData) -> (i64, img_hash::ImageHash<[u8; 8]>) { use bytes::BufMut; - use futures_util::StreamExt; + use futures::StreamExt; let parts: Vec<_> = form.collect().await; let mut parts = parts @@ -82,11 +115,11 @@ pub async fn search_image( pool: Pool, tree: Tree, api_key: String, -) -> Result { - let db = pool.get().await.map_err(map_bb8_err)?; +) -> Result, Rejection> { + let db = early_return!(pool.get().await); - rate_limit!(&api_key, &db, image_limit, "image"); - rate_limit!(&api_key, &db, hash_limit, "hash"); + let image_remaining = rate_limit!(&api_key, &db, image_limit, "image"); + let hash_remaining = rate_limit!(&api_key, &db, hash_limit, "hash"); let (num, hash) = hash_input(form).await; @@ -139,7 +172,20 @@ pub async fn search_image( matches: items, }; - Ok(warp::reply::json(&similarity)) + let resp = warp::http::Response::builder() + .header("x-image-hash", num.to_string()) + .header("x-rate-limit-total-image", image_remaining.1.to_string()) + .header( + "x-rate-limit-remaining-image", + image_remaining.0.to_string(), + ) + .header("x-rate-limit-total-hash", hash_remaining.1.to_string()) + .header("x-rate-limit-remaining-hash", hash_remaining.0.to_string()) + .header("content-type", "application/json") + .body(serde_json::to_string(&similarity).unwrap()) + .unwrap(); + + Ok(Box::new(resp)) } pub async fn stream_image( @@ -147,34 +193,38 @@ pub async fn stream_image( pool: Pool, tree: Tree, api_key: String, -) -> Result { - use futures_util::StreamExt; - - let db = pool.get().await.map_err(map_bb8_err)?; +) -> Result, Rejection> { + let db = early_return!(pool.get().await); rate_limit!(&api_key, &db, image_limit, "image", 2); rate_limit!(&api_key, &db, hash_limit, "hash"); let (num, hash) = hash_input(form).await; - let event_stream = image_query_sync( + let mut query = image_query_sync( pool.clone(), tree, vec![num], 10, Some(hash.as_bytes().to_vec()), - ) - .map(sse_matches); + ); - Ok(warp::sse::reply(event_stream)) + let event_stream = async_stream::stream! { + while let Some(result) = query.recv().await { + yield sse_matches(result); + } + }; + + Ok(Box::new(warp::sse::reply(event_stream))) } +#[allow(clippy::unnecessary_wraps)] fn sse_matches( matches: Result, tokio_postgres::Error>, -) -> Result { +) -> Result { let items = matches.unwrap(); - Ok(warp::sse::json(items)) + Ok(warp::sse::Event::default().json_data(items).unwrap()) } pub async fn search_hashes( @@ -182,9 +232,9 @@ pub async fn search_hashes( db: Pool, tree: Tree, api_key: String, -) -> Result { +) -> Result, Rejection> { let pool = db.clone(); - let db = db.get().await.map_err(map_bb8_err)?; + let db = early_return!(db.get().await); let hashes: Vec = opts .hashes @@ -194,10 +244,10 @@ pub async fn search_hashes( .collect(); if hashes.is_empty() { - return Err(warp::reject::custom(Error::InvalidData)); + return Ok(Box::new(Error::InvalidData)); } - rate_limit!(&api_key, &db, image_limit, "image", hashes.len() as i16); + let image_remaining = rate_limit!(&api_key, &db, image_limit, "image", hashes.len() as i16); let mut results = image_query_sync( pool, @@ -209,20 +259,30 @@ pub async fn search_hashes( let mut matches = Vec::new(); while let Some(r) = results.recv().await { - matches.extend(r.map_err(|e| warp::reject::custom(Error::Postgres(e)))?); + matches.extend(early_return!(r)); } - Ok(warp::reply::json(&matches)) + let resp = warp::http::Response::builder() + .header("x-rate-limit-total-image", image_remaining.1.to_string()) + .header( + "x-rate-limit-remaining-image", + image_remaining.0.to_string(), + ) + .header("content-type", "application/json") + .body(serde_json::to_string(&matches).unwrap()) + .unwrap(); + + Ok(Box::new(resp)) } pub async fn search_file( opts: FileSearchOpts, db: Pool, api_key: String, -) -> Result { - let db = db.get().await.map_err(map_bb8_err)?; +) -> Result, Rejection> { + let db = early_return!(db.get().await); - rate_limit!(&api_key, &db, name_limit, "file"); + let file_remaining = rate_limit!(&api_key, &db, name_limit, "file"); let (filter, val): (&'static str, &(dyn tokio_postgres::types::ToSql + Sync)) = if let Some(ref id) = opts.id { @@ -232,7 +292,7 @@ pub async fn search_file( } else if let Some(ref url) = opts.url { ("lower(url) = lower($1)", url) } else { - return Err(warp::reject::custom(Error::InvalidData)); + return Ok(Box::new(Error::InvalidData)); }; let query = format!( @@ -255,53 +315,143 @@ pub async fn search_file( filter ); - let matches: Vec<_> = db - .query::(&*query, &[val]) - .instrument(span!(tracing::Level::TRACE, "waiting for db")) - .await - .map_err(map_postgres_err)? - .into_iter() - .map(|row| File { - id: row.get("hash_id"), - site_id: row.get::<&str, i32>("id") as i64, - site_id_str: row.get::<&str, i32>("id").to_string(), - url: row.get("url"), - filename: row.get("filename"), - artists: row - .get::<&str, Option>("name") - .map(|artist| vec![artist]), - distance: None, - hash: None, - site_info: Some(SiteInfo::FurAffinity(FurAffinityFile { - file_id: row.get("file_id"), - })), - searched_hash: None, - }) - .collect(); + let matches: Vec<_> = early_return!( + db.query::(&*query, &[val]) + .instrument(span!(tracing::Level::TRACE, "waiting for db")) + .await + ) + .into_iter() + .map(|row| File { + id: row.get("hash_id"), + site_id: row.get::<&str, i32>("id") as i64, + site_id_str: row.get::<&str, i32>("id").to_string(), + url: row.get("url"), + filename: row.get("filename"), + artists: row + .get::<&str, Option>("name") + .map(|artist| vec![artist]), + distance: None, + hash: None, + site_info: Some(SiteInfo::FurAffinity(FurAffinityFile { + file_id: row.get("file_id"), + })), + searched_hash: None, + }) + .collect(); - Ok(warp::reply::json(&matches)) + let resp = warp::http::Response::builder() + .header("x-rate-limit-total-file", file_remaining.1.to_string()) + .header("x-rate-limit-remaining-file", file_remaining.0.to_string()) + .header("content-type", "application/json") + .body(serde_json::to_string(&matches).unwrap()) + .unwrap(); + + Ok(Box::new(resp)) } -pub async fn check_handle(opts: HandleOpts, db: Pool) -> Result { - let db = db.get().await.map_err(map_bb8_err)?; +pub async fn check_handle(opts: HandleOpts, db: Pool) -> Result, Rejection> { + let db = early_return!(db.get().await); let exists = if let Some(handle) = opts.twitter { - !db.query( - "SELECT 1 FROM twitter_user WHERE lower(data->>'screen_name') = lower($1)", - &[&handle], + !early_return!( + db.query( + "SELECT 1 FROM twitter_user WHERE lower(data->>'screen_name') = lower($1)", + &[&handle], + ) + .await ) - .await - .map_err(map_postgres_err)? .is_empty() } else { false }; - Ok(warp::reply::json(&exists)) + Ok(Box::new(warp::reply::json(&exists))) +} + +pub async fn search_image_by_url( + opts: URLSearchOpts, + pool: Pool, + tree: Tree, + api_key: String, +) -> Result, Rejection> { + use bytes::BufMut; + + let url = opts.url; + + let db = early_return!(pool.get().await); + + let image_remaining = rate_limit!(&api_key, &db, image_limit, "image"); + let hash_remaining = rate_limit!(&api_key, &db, hash_limit, "hash"); + + let mut resp = match reqwest::get(&url).await { + Ok(resp) => resp, + Err(_err) => return Ok(Box::new(Error::InvalidImage)), + }; + + let content_length = resp + .headers() + .get("content-length") + .and_then(|len| { + String::from_utf8_lossy(len.as_bytes()) + .parse::() + .ok() + }) + .unwrap_or(0); + + if content_length > 10_000_000 { + return Ok(Box::new(Error::InvalidImage)); + } + + let mut buf = bytes::BytesMut::with_capacity(content_length); + + while let Some(chunk) = early_return!(resp.chunk().await) { + if buf.len() + chunk.len() > 10_000_000 { + return Ok(Box::new(Error::InvalidImage)); + } + + buf.put(chunk); + } + + let hash = tokio::task::spawn_blocking(move || { + let hasher = crate::get_hasher(); + let image = image::load_from_memory(&buf).unwrap(); + hasher.hash_image(&image) + }) + .instrument(span!(tracing::Level::TRACE, "hashing image")) + .await + .unwrap(); + + let hash: [u8; 8] = hash.as_bytes().try_into().unwrap(); + let num = i64::from_be_bytes(hash); + + let results = image_query( + pool.clone(), + tree.clone(), + vec![num], + 3, + Some(hash.to_vec()), + ) + .await + .unwrap(); + + let resp = warp::http::Response::builder() + .header("x-image-hash", num.to_string()) + .header("x-rate-limit-total-image", image_remaining.1.to_string()) + .header( + "x-rate-limit-remaining-image", + image_remaining.0.to_string(), + ) + .header("x-rate-limit-total-hash", hash_remaining.1.to_string()) + .header("x-rate-limit-remaining-hash", hash_remaining.0.to_string()) + .header("content-type", "application/json") + .body(serde_json::to_string(&results).unwrap()) + .unwrap(); + + Ok(Box::new(resp)) } #[tracing::instrument] -pub async fn handle_rejection(err: Rejection) -> Result { +pub async fn handle_rejection(err: Rejection) -> Result, std::convert::Infallible> { warn!("had rejection"); let (code, message) = if err.is_not_found() { @@ -309,29 +459,10 @@ pub async fn handle_rejection(err: Rejection) -> Result() { - match err { - Error::BB8(_inner) => ( - warp::http::StatusCode::INTERNAL_SERVER_ERROR, - "A database error occured", - ), - Error::Postgres(_inner) => ( - warp::http::StatusCode::INTERNAL_SERVER_ERROR, - "A database error occured", - ), - Error::InvalidData => ( - warp::http::StatusCode::BAD_REQUEST, - "Unable to operate on provided data", - ), - Error::ApiKey => ( - warp::http::StatusCode::UNAUTHORIZED, - "Invalid API key provided", - ), - Error::RateLimit => ( - warp::http::StatusCode::TOO_MANY_REQUESTS, - "Your API token is rate limited", - ), - } + } else if err.find::().is_some() { + return Ok(Box::new(Error::InvalidData) as Box); + } else if err.find::().is_some() { + return Ok(Box::new(Error::InvalidData) as Box); } else { ( warp::http::StatusCode::INTERNAL_SERVER_ERROR, @@ -344,5 +475,5 @@ pub async fn handle_rejection(err: Rejection) -> Result $1", &[&id]) .await diff --git a/src/types.rs b/src/types.rs index 6106a6c..a4b76c8 100644 --- a/src/types.rs +++ b/src/types.rs @@ -20,7 +20,7 @@ pub enum RateLimit { /// This key is limited, we should deny the request. Limited, /// This key is available, contains the number of requests made. - Available(i16), + Available((i16, i16)), } /// A general type for every file. @@ -112,3 +112,8 @@ pub struct HashSearchOpts { pub struct HandleOpts { pub twitter: Option, } + +#[derive(Debug, Deserialize)] +pub struct URLSearchOpts { + pub url: String, +} diff --git a/src/utils.rs b/src/utils.rs index becb04f..404483d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -7,18 +7,38 @@ macro_rules! rate_limit { rate_limit!($api_key, $db, $limit, $group, 1) }; - ($api_key:expr, $db:expr, $limit:tt, $group:expr, $incr_by:expr) => { - let api_key = crate::models::lookup_api_key($api_key, $db) - .await - .ok_or_else(|| warp::reject::custom(Error::ApiKey))?; + ($api_key:expr, $db:expr, $limit:tt, $group:expr, $incr_by:expr) => {{ + let api_key = match crate::models::lookup_api_key($api_key, $db).await { + Some(api_key) => api_key, + None => return Ok(Box::new(Error::ApiKey)), + }; - let rate_limit = - crate::utils::update_rate_limit($db, api_key.id, api_key.$limit, $group, $incr_by) - .await - .map_err(crate::handlers::map_postgres_err)?; + let rate_limit = match crate::utils::update_rate_limit( + $db, + api_key.id, + api_key.$limit, + $group, + $incr_by, + ) + .await + { + Ok(rate_limit) => rate_limit, + Err(err) => return Ok(Box::new(Error::Postgres(err))), + }; - if rate_limit == crate::types::RateLimit::Limited { - return Err(warp::reject::custom(Error::RateLimit)); + match rate_limit { + crate::types::RateLimit::Limited => return Ok(Box::new(Error::RateLimit)), + crate::types::RateLimit::Available(count) => count, + } + }}; +} + +#[macro_export] +macro_rules! early_return { + ($val:expr) => { + match $val { + Ok(val) => val, + Err(err) => return Ok(Box::new(Error::from(err))), } }; } @@ -59,14 +79,17 @@ pub async fn update_rate_limit( if count > key_group_limit { Ok(RateLimit::Limited) } else { - Ok(RateLimit::Available(count)) + Ok(RateLimit::Available(( + key_group_limit - count, + key_group_limit, + ))) } } -pub fn extract_rows<'a>( +pub fn extract_rows( rows: Vec, - hash: Option<&'a [u8]>, -) -> impl IntoIterator + 'a { + hash: Option<&[u8]>, +) -> impl IntoIterator + '_ { rows.into_iter().map(move |row| { let dbhash: i64 = row.get("hash"); let dbbytes = dbhash.to_be_bytes();