diff --git a/Cargo.lock b/Cargo.lock index 6819ebf..8c50867 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,22 @@ dependencies = [ "memchr", "pin-project-lite", "tokio", - "tokio-util 0.7.1", + "tokio-util 0.7.2", +] + +[[package]] +name = "actix-cors" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414360eed71ba2d5435b185ba43ecbe281dfab5df3898286d6b7be8074372c92" +dependencies = [ + "actix-utils", + "actix-web", + "derive_more", + "futures-util", + "log", + "once_cell", + "smallvec", ] [[package]] @@ -66,7 +81,7 @@ dependencies = [ "http", "httparse", "httpdate", - "itoa 1.0.1", + "itoa 1.0.2", "language-tags", "local-channel", "log", @@ -125,7 +140,7 @@ dependencies = [ "actix-utils", "futures-core", "futures-util", - "mio 0.8.2", + "mio 0.8.3", "num_cpus", "socket2", "tokio", @@ -177,7 +192,7 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "itoa 1.0.1", + "itoa 1.0.2", "language-tags", "log", "mime", @@ -362,15 +377,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -379,9 +385,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base-x" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" +checksum = "dc19a4937b4fbd3fe3379793130e42060d10627a360f2127802b10b87e7baf74" [[package]] name = "base64" @@ -391,9 +397,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "base64ct" -version = "1.1.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b4d9b1225d28d360ec6a231d65af1fd99a2a095154c8040689617290569c5c" +checksum = "dea908e7347a8c64e378c17e30ef880ad73e3b4498346b055c2c00ea342f3179" [[package]] name = "bigdecimal" @@ -434,15 +440,6 @@ dependencies = [ "generic-array 0.12.4", ] -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array 0.14.5", -] - [[package]] name = "block-buffer" version = "0.10.2" @@ -583,23 +580,23 @@ dependencies = [ [[package]] name = "combine" -version = "4.6.3" +version = "4.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50b727aacc797f9fc28e355d21f34709ac4fc9adecfe470ad07b8f4464f53062" +checksum = "2a604e93b79d1808327a6fca85a6f2d69de66461e7620f5a4cbf5fb4d1d7c948" dependencies = [ "bytes", "futures-core", "memchr", "pin-project-lite", "tokio", - "tokio-util 0.6.9", + "tokio-util 0.7.2", ] [[package]] name = "const-oid" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6f2aa4d0537bcc1c74df8755072bd31c1ef1a3a1b85a68e8404a8c353b7b8b" +checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "const_fn" @@ -711,12 +708,11 @@ dependencies = [ [[package]] name = "crypto-bigint" -version = "0.2.11" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83bd3bb4314701c568e340cd8cf78c975aa0ca79e03d3f6d1677d5b0c9c0c03" +checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" dependencies = [ "generic-array 0.14.5", - "rand_core 0.6.3", "subtle", ] @@ -730,16 +726,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" -dependencies = [ - "generic-array 0.14.5", - "subtle", -] - [[package]] name = "dashmap" version = "4.0.2" @@ -752,12 +738,13 @@ dependencies = [ [[package]] name = "der" -version = "0.4.5" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79b71cca7d95d7681a4b3b9cdf63c8dbc3730d0584c2c74e31416d64a90493f4" +checksum = "6919815d73839e7ad218de758883aae3a257ba6759ce7a9992501efbb53d705c" dependencies = [ "const-oid", "crypto-bigint", + "pem-rfc7468", ] [[package]] @@ -782,15 +769,6 @@ dependencies = [ "generic-array 0.12.4", ] -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array 0.14.5", -] - [[package]] name = "digest" version = "0.10.3" @@ -799,6 +777,7 @@ checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" dependencies = [ "block-buffer 0.10.2", "crypto-common", + "subtle", ] [[package]] @@ -839,6 +818,12 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" +[[package]] +name = "dyn-clone" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21e50f3adc76d6a43f5ed73b698a87d0760ca74617f60f7c3b879003536fdd28" + [[package]] name = "either" version = "1.6.1" @@ -850,13 +835,19 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.30" +version = "0.8.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" dependencies = [ "cfg-if", ] +[[package]] +name = "event-listener" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" + [[package]] name = "fake-simd" version = "0.1.2" @@ -874,9 +865,9 @@ dependencies = [ [[package]] name = "fern" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9a4820f0ccc8a7afd67c39a0f1a0f4b07ca1725164271a64939d7aeb9af065" +checksum = "3bdd7b0849075e79ee9a1836df22c717d1eba30451796fdc631b04565dd11e2a" dependencies = [ "colored", "log", @@ -890,9 +881,9 @@ checksum = "4d3d6188b8804df28032815ea256b6955c9625c24da7525f387a7af02fbb8f01" [[package]] name = "flate2" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" +checksum = "b39522e96686d38f4bc984b9198e3a0613264abaebaff2c5c918bfa6b6da09af" dependencies = [ "cfg-if", "crc32fast", @@ -909,7 +900,7 @@ dependencies = [ "futures-core", "futures-sink", "pin-project", - "spin 0.9.2", + "spin 0.9.3", ] [[package]] @@ -1100,7 +1091,7 @@ dependencies = [ "indexmap", "slab", "tokio", - "tokio-util 0.7.1", + "tokio-util 0.7.2", "tracing", ] @@ -1131,6 +1122,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1146,40 +1143,47 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hkdf" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +dependencies = [ + "hmac", +] + [[package]] name = "hmac" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "crypto-mac", - "digest 0.9.0", + "digest 0.10.3", ] [[package]] name = "html_parser" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58112d7b68ff61447bd22a489d7877a79ee688f6f34d57d3857842776d42dd0c" +checksum = "ec016cabcf7c9c48f9d5fdc6b03f273585bfce640a0f47a69552039e92b1959a" dependencies = [ "pest", "pest_derive", "serde", "serde_derive", "serde_json", - "structopt", "thiserror", ] [[package]] name = "http" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" +checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" dependencies = [ "bytes", "fnv", - "itoa 1.0.1", + "itoa 1.0.2", ] [[package]] @@ -1201,9 +1205,9 @@ checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573" [[package]] name = "httparse" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" +checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" [[package]] name = "httpdate" @@ -1248,7 +1252,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 1.0.1", + "itoa 1.0.2", "pin-project-lite", "socket2", "tokio", @@ -1287,7 +1291,7 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" dependencies = [ - "autocfg 1.1.0", + "autocfg", "hashbrown", ] @@ -1302,9 +1306,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e70ee094dc02fd9c13fdad4940090f22dbd6ac7c9e7094a46cf0232a50bc7c" +checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "ipnetwork" @@ -1332,9 +1336,9 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "itoa" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "jobserver" @@ -1347,9 +1351,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.56" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" +checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" dependencies = [ "wasm-bindgen", ] @@ -1388,9 +1392,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.121" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "libm" @@ -1400,9 +1404,9 @@ checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" [[package]] name = "libsqlite3-sys" -version = "0.23.2" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cafc7c74096c336d9d27145f7ebd4f4b6f95ba16aa5a282387267e6925cb58" +checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" dependencies = [ "cc", "pkg-config", @@ -1411,9 +1415,9 @@ dependencies = [ [[package]] name = "local-channel" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6246c68cf195087205a0512559c97e15eaf95198bf0e206d662092cdcb03fe9f" +checksum = "7f303ec0e94c6c54447f84f3b0ef7af769858a9c4ef56ef2a986d3dcd4c3fc9c" dependencies = [ "futures-core", "futures-sink", @@ -1423,9 +1427,9 @@ dependencies = [ [[package]] name = "local-waker" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "902eb695eb0591864543cbfbf6d742510642a605a61fc5e97fe6ceb5a30ac4fb" +checksum = "e34f76eb3611940e0e7d53a9aaa4e6a3151f69541a282fd0dad5571420c53ff1" [[package]] name = "lock_api" @@ -1433,15 +1437,15 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.16" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -1458,17 +1462,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" -[[package]] -name = "md-5" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15" -dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", - "opaque-debug 0.3.0", -] - [[package]] name = "md-5" version = "0.10.1" @@ -1480,9 +1473,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mime" @@ -1508,12 +1501,11 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.4.4" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +checksum = "d2b29bd4bc3f33391105ebee3589c19197c4271e3e5a9ec9bfe8127eeff8f082" dependencies = [ "adler", - "autocfg 1.1.0", ] [[package]] @@ -1531,16 +1523,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" +checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799" dependencies = [ "libc", "log", - "miow", - "ntapi", "wasi 0.11.0+wasi-snapshot-preview1", - "winapi", + "windows-sys", ] [[package]] @@ -1630,18 +1620,17 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-bigint-dig" -version = "0.7.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4547ee5541c18742396ae2c895d0717d0f886d8823b8399cdaf7b07d63ad0480" +checksum = "566d173b2f9406afbc5510a90925d5a2cd80cae4605631f1212303df265de011" dependencies = [ - "autocfg 0.1.8", "byteorder", "lazy_static", "libm", @@ -1655,32 +1644,32 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-traits", ] [[package]] name = "num-iter" -version = "0.1.42" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.1.0", + "autocfg", "libm", ] @@ -1696,9 +1685,9 @@ dependencies = [ [[package]] name = "num_threads" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aba1801fb138d8e85e11d0fc70baf4fe1cdfffda7c6cd34a854905df588e5ed0" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" dependencies = [ "libc", ] @@ -1715,26 +1704,32 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "openssl" -version = "0.10.38" +version = "0.10.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" +checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e" dependencies = [ "bitflags", "cfg-if", "foreign-types", "libc", "once_cell", + "openssl-macros", "openssl-sys", ] +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "openssl-probe" version = "0.1.5" @@ -1752,11 +1747,11 @@ dependencies = [ [[package]] name = "openssl-sys" -version = "0.9.72" +version = "0.9.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" +checksum = "9d5fd19fb3e0a8191c1e34935718976a3e70c112ab9a24af6d7cadccd9d90bc0" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cc", "libc", "openssl-src", @@ -1782,7 +1777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" dependencies = [ "lock_api", - "parking_lot_core 0.9.2", + "parking_lot_core 0.9.3", ] [[package]] @@ -1801,9 +1796,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "995f667a6c822200b0433ac218e05582f0e2efa1b922a3fd2fbaadc5f87bab37" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" dependencies = [ "cfg-if", "libc", @@ -1831,9 +1826,9 @@ dependencies = [ [[package]] name = "pem-rfc7468" -version = "0.2.4" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84e93a3b1cc0510b03020f33f21e62acdde3dcaef432edc95bea377fbd4c2cd4" +checksum = "01de5d978f34aa4b2296576379fcc416034702fd94117c56ffd8a1a767cefb30" dependencies = [ "base64ct", ] @@ -1909,9 +1904,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "pin-utils" @@ -1932,24 +1927,22 @@ dependencies = [ [[package]] name = "pkcs1" -version = "0.2.4" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "116bee8279d783c0cf370efa1a94632f2108e5ef0bb32df31f051647810a4e2c" +checksum = "a78f66c04ccc83dd4486fd46c33896f4e17b24a7a3a6400dedc48ed0ddd72320" dependencies = [ "der", - "pem-rfc7468", + "pkcs8", "zeroize", ] [[package]] name = "pkcs8" -version = "0.7.6" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee3ef9b64d26bad0536099c816c6734379e45bbd5f14798def6809e5cc350447" +checksum = "7cabda3fb821068a9a4fab19a683eac3af12edf0f34b94a8be53c4972b8149d0" dependencies = [ "der", - "pem-rfc7468", - "pkcs1", "spki", "zeroize", ] @@ -1998,11 +1991,11 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -2026,23 +2019,11 @@ version = "2.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" -[[package]] -name = "py_sql" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406b706c360fcde6e93391e83ef16aed0798a96f08e8f0e174de0681ec0a6060" -dependencies = [ - "dashmap", - "rexpr", - "serde", - "serde_json", -] - [[package]] name = "quote" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" dependencies = [ "proc-macro2", ] @@ -2107,9 +2088,9 @@ dependencies = [ [[package]] name = "rbatis" -version = "3.1.6" +version = "3.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6696fb4732261ee61307d99b8a3d9e4178eee837593f7e43c0b28cd8558b1f" +checksum = "e8d9fe0ed28cedfdc9adf4ee956292f9913070b2f6e258cbf84ebffb351bd273" dependencies = [ "async-trait", "chrono", @@ -2129,9 +2110,9 @@ dependencies = [ [[package]] name = "rbatis-core" -version = "3.1.6" +version = "3.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b11a31670a18f9229481027358e77ff7828c501c4e834f629ab46bc60dad87ea" +checksum = "c178388af5790ddd06d8176341477aba778e1625b7d8debfbf1d0b72ad9c5149" dependencies = [ "base64", "bigdecimal", @@ -2141,9 +2122,7 @@ dependencies = [ "ipnetwork", "lazy_static", "log", - "py_sql", "rbson", - "rexpr", "serde", "serde_json", "sqlx-core", @@ -2165,9 +2144,9 @@ dependencies = [ [[package]] name = "rbatis_sql" -version = "3.0.17" +version = "3.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd41bd85af47c69fde29e2654df87307a234b52f0a2152e7797331d47bb43f69" +checksum = "151643783adb3d5ca6007b77e39988669c9742be03cf56083d5f217c6c5ca902" dependencies = [ "async-trait", "base64", @@ -2179,9 +2158,9 @@ dependencies = [ [[package]] name = "rbatis_sql_macro" -version = "3.0.10" +version = "3.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98b73d4dd3555bb3d0aceccf768d595593b4b74db242c0e0bb054d4ba58b939f" +checksum = "74a999ee51954c6d0233d3238ff40db27d708e4a0848613027c38de6e9bc291c" dependencies = [ "async-trait", "base64", @@ -2190,7 +2169,6 @@ dependencies = [ "quote", "syn", "url", - "xml-rs", ] [[package]] @@ -2237,7 +2215,7 @@ dependencies = [ "pin-project-lite", "sha1 0.6.1", "tokio", - "tokio-util 0.6.9", + "tokio-util 0.6.10", "url", ] @@ -2329,17 +2307,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "rexpr" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4753cc5e42400348f62002a279dd25e135fa46b95d0cac6935c6380deb31feda" -dependencies = [ - "dashmap", - "serde", - "serde_json", -] - [[package]] name = "ring" version = "0.16.20" @@ -2357,20 +2324,20 @@ dependencies = [ [[package]] name = "rsa" -version = "0.5.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c2603e2823634ab331437001b411b9ed11660fbc4066f3908c84a9439260d" +checksum = "4cf22754c49613d2b3b119f0e5d46e34a2c628a937e3024b8762de4e7d8c710b" dependencies = [ "byteorder", - "digest 0.9.0", - "lazy_static", + "digest 0.10.3", "num-bigint-dig", "num-integer", "num-iter", "num-traits", "pkcs1", "pkcs8", - "rand 0.8.5", + "rand_core 0.6.3", + "smallvec", "subtle", "zeroize", ] @@ -2401,7 +2368,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.7", + "semver 1.0.9", ] [[package]] @@ -2419,8 +2386,9 @@ dependencies = [ [[package]] name = "rustus" -version = "0.4.13" +version = "0.5.0" dependencies = [ + "actix-cors", "actix-files", "actix-rt", "actix-web", @@ -2431,13 +2399,13 @@ dependencies = [ "chrono", "derive_more", "digest 0.10.3", + "dyn-clone", "fern", "futures", "httptest", "lapin", - "lazy_static", "log", - "md-5 0.10.1", + "md-5", "mobc-lapin", "mobc-redis", "openssl", @@ -2448,8 +2416,7 @@ dependencies = [ "serde", "serde_json", "sha1 0.10.1", - "sha2 0.10.2", - "strfmt", + "sha2", "structopt", "strum", "tempdir", @@ -2457,7 +2424,8 @@ dependencies = [ "tokio", "tokio-amqp", "url", - "uuid 1.0.0-alpha.1", + "uuid 1.0.0", + "wildmatch", ] [[package]] @@ -2468,9 +2436,9 @@ checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" [[package]] name = "ryu" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" [[package]] name = "schannel" @@ -2532,9 +2500,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d65bd28f48be7196d222d95b9243287f48d27aca604e08497513019ff0502cc4" +checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" [[package]] name = "semver-parser" @@ -2544,27 +2512,27 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" +checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.136" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" dependencies = [ "proc-macro2", "quote", @@ -2573,12 +2541,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ "indexmap", - "itoa 1.0.1", + "itoa 1.0.2", "ryu", "serde", ] @@ -2590,7 +2558,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 1.0.1", + "itoa 1.0.2", "ryu", "serde", ] @@ -2604,20 +2572,7 @@ dependencies = [ "block-buffer 0.7.3", "digest 0.8.1", "fake-simd", - "opaque-debug 0.2.3", -] - -[[package]] -name = "sha-1" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug 0.3.0", + "opaque-debug", ] [[package]] @@ -2657,19 +2612,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug 0.3.0", -] - [[package]] name = "sha2" version = "0.10.2" @@ -2720,19 +2662,20 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spin" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" +checksum = "c530c2b0d0bf8b69304b39fe2001993e267461948b890cd037d8ad4293fa1a0d" dependencies = [ "lock_api", ] [[package]] name = "spki" -version = "0.4.1" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c01a0c15da1b0b0e1494112e7af814a678fec9bd157881b49beac661e9b6f32" +checksum = "44d01ac02a6ccf3e07db148d2be087da624fea0221a16152ed01f0496a6b0a27" dependencies = [ + "base64ct", "der", ] @@ -2749,9 +2692,9 @@ dependencies = [ [[package]] name = "sqlx-core" -version = "0.5.11" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "195183bf6ff8328bb82c0511a83faf60aacf75840103388851db61d7a9854ae3" +checksum = "e48c61941ccf5ddcada342cd59e3e5173b007c509e1e8e990dafc830294d9dc5" dependencies = [ "ahash", "atoi", @@ -2764,10 +2707,11 @@ dependencies = [ "chrono", "crc", "crossbeam-queue", - "digest 0.9.0", + "digest 0.10.3", "dirs", "either", "encoding_rs", + "event-listener", "flume", "futures-channel", "futures-core", @@ -2777,13 +2721,14 @@ dependencies = [ "generic-array 0.14.5", "hashlink", "hex", + "hkdf", "hmac", "indexmap", - "itoa 1.0.1", + "itoa 1.0.2", "libc", "libsqlite3-sys", "log", - "md-5 0.9.1", + "md-5", "memchr", "num-bigint", "once_cell", @@ -2796,8 +2741,8 @@ dependencies = [ "rustls", "serde", "serde_json", - "sha-1 0.9.8", - "sha2 0.9.9", + "sha-1 0.10.0", + "sha2", "smallvec", "sqlformat", "sqlx-rt", @@ -2814,9 +2759,9 @@ dependencies = [ [[package]] name = "sqlx-rt" -version = "0.5.11" +version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b555e70fbbf84e269ec3858b7a6515bcfe7a166a7cc9c636dd6efd20431678b6" +checksum = "4db708cd3e459078f85f39f96a00960bd841f66ee2a669e90bf36907f5a79aae" dependencies = [ "once_cell", "tokio", @@ -2881,12 +2826,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" -[[package]] -name = "strfmt" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b278b244ef7aa5852b277f52dd0c6cac3a109919e1f6d699adde63251227a30f" - [[package]] name = "stringprep" version = "0.1.2" @@ -2920,7 +2859,7 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro-error", "proc-macro2", "quote", @@ -2929,20 +2868,20 @@ dependencies = [ [[package]] name = "strum" -version = "0.23.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cae14b91c7d11c9a851d3fbc80a963198998c2a64eec840477fa92d8ce9b70bb" +checksum = "e96acfc1b70604b8b2f1ffa4c57e59176c7dbb05d556c71ecd2f5498a1dee7f8" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.23.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" +checksum = "6878079b17446e4d3eba6192bb0a2950d5b14f0ed8424b852310e5a94345d0ef" dependencies = [ - "heck", + "heck 0.4.0", "proc-macro2", "quote", "rustversion", @@ -2957,25 +2896,13 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.90" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "704df27628939572cd88d33f171cd6f896f4eaca85252c6e0a72d8d8287ee86f" +checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" dependencies = [ "proc-macro2", "quote", - "unicode-xid", -] - -[[package]] -name = "synstructure" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -3025,18 +2952,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.30" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" dependencies = [ "proc-macro2", "quote", @@ -3076,7 +3003,7 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd" dependencies = [ - "itoa 1.0.1", + "itoa 1.0.2", "libc", "num_threads", "time-macros 0.2.4", @@ -3113,9 +3040,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ "tinyvec_macros", ] @@ -3128,14 +3055,14 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.17.0" +version = "1.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" +checksum = "4903bf0427cf68dddd5aa6a93220756f8be0c34fcfa9f5e6191e103e15a31395" dependencies = [ "bytes", "libc", "memchr", - "mio 0.8.2", + "mio 0.8.3", "num_cpus", "once_cell", "parking_lot 0.12.0", @@ -3202,9 +3129,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.9" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" +checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" dependencies = [ "bytes", "futures-core", @@ -3216,9 +3143,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764" +checksum = "f988a1a1adc2fb21f9c12aa96441da33a1728193ae0b95d2be22dbd17fcb4e5c" dependencies = [ "bytes", "futures-core", @@ -3236,9 +3163,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.32" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" dependencies = [ "cfg-if", "log", @@ -3249,9 +3176,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" dependencies = [ "proc-macro2", "quote", @@ -3260,9 +3187,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90442985ee2f57c9e1b548ee72ae842f4a9a20e3f417cc38dbc5dc684d9bb4ee" +checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" dependencies = [ "lazy_static", ] @@ -3296,9 +3223,15 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.7" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-ident" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" [[package]] name = "unicode-normalization" @@ -3321,12 +3254,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - [[package]] name = "unicode_categories" version = "0.1.1" @@ -3363,9 +3290,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.0.0-alpha.1" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb3ab47baa004111b323696c6eaa2752e7356f7f77cf6b6dc7a2087368ce1ca4" +checksum = "8cfcd319456c4d6ea10087ed423473267e1a071f3bc0aa89f80d60997843c6f0" dependencies = [ "getrandom", ] @@ -3412,9 +3339,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" +checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3422,9 +3349,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" +checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" dependencies = [ "bumpalo", "lazy_static", @@ -3437,9 +3364,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.29" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb6ec270a31b1d3c7e266b999739109abce8b6c87e4b31fcfcd788b65267395" +checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" dependencies = [ "cfg-if", "js-sys", @@ -3449,9 +3376,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" +checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3459,9 +3386,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" +checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" dependencies = [ "proc-macro2", "quote", @@ -3472,15 +3399,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.79" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" +checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" [[package]] name = "web-sys" -version = "0.3.56" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" +checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" dependencies = [ "js-sys", "wasm-bindgen", @@ -3515,6 +3442,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "wildmatch" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6c48bd20df7e4ced539c12f570f937c6b4884928a87fee70a479d72f031d4e0" + [[package]] name = "winapi" version = "0.3.9" @@ -3539,9 +3472,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.34.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5acdd78cb4ba54c0045ac14f62d8f94a03d10047904ae2a40afa1e99d8f70825" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ "windows_aarch64_msvc", "windows_i686_gnu", @@ -3552,33 +3485,33 @@ dependencies = [ [[package]] name = "windows_aarch64_msvc" -version = "0.34.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] name = "windows_i686_gnu" -version = "0.34.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] name = "windows_i686_msvc" -version = "0.34.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] name = "windows_x86_64_gnu" -version = "0.34.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] name = "windows_x86_64_msvc" -version = "0.34.0" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "winreg" @@ -3589,47 +3522,26 @@ dependencies = [ "winapi", ] -[[package]] -name = "xml-rs" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" - [[package]] name = "zeroize" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.3.2" +version = "1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] +checksum = "94693807d016b2f2d2e14420eb3bfcca689311ff775dcf113d74ea624b7cdf07" [[package]] name = "zstd" -version = "0.10.0+zstd.1.5.2" +version = "0.10.2+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b1365becbe415f3f0fcd024e2f7b45bacfb5bdd055f0dc113571394114e7bdd" +checksum = "5f4a6bd64f22b5e3e94b4e238669ff9f10815c27a5180108b849d24174a83847" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "4.1.4+zstd.1.5.2" +version = "4.1.6+zstd.1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7cd17c9af1a4d6c24beb1cc54b17e2ef7b593dc92f19e9d9acad8b182bbaee" +checksum = "94b61c51bb270702d6167b8ce67340d2754b088d0c091b06e593aa772c3ee9bb" dependencies = [ "libc", "zstd-sys", diff --git a/Cargo.toml b/Cargo.toml index 9003423..3cf9514 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustus" -version = "0.4.13" +version = "0.5.0" edition = "2021" description = "TUS protocol implementation written in Rust." keywords = [ @@ -23,15 +23,17 @@ name = "rustus" [dependencies] async-trait = "^0.1.52" base64 = "^0.13.0" -lazy_static = "^1.4.0" log = "^0.4.14" serde_json = "^1" -strfmt = "^0.1.6" thiserror = "^1.0" url = "^2.2.2" bytes = "^1.1.0" prometheus = "^0.13.0" actix-web-prom = "^0.6.0" +dyn-clone = "^1.0.5" +actix-cors = "0.6.1" +wildmatch = "2.1.0" + [dependencies.digest] version = "0.10.3" @@ -66,7 +68,7 @@ features = ["vendored"] version = "^0.6.0-beta.13" [dependencies.actix-web] -version = "^4.0.0-rc.3" +version = "^4.0.1" [dependencies.chrono] features = ["serde"] @@ -113,7 +115,7 @@ version = "^0.3" [dependencies.strum] features = ["derive"] -version = "^0.23" +version = "0.24.0" [dependencies.tokio] features = ["time", "process", "fs", "io-std", "io-util", "rt-multi-thread", "bytes", "rt", "macros"] diff --git a/docs/configuration.md b/docs/configuration.md index e954b9e..c524240 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -21,6 +21,12 @@ Also you can configure number of actix `workers` that handle connections. `--workers` by default is euqal to number of physical CPU cores. Edit it carefully. +`--cors` is a list of allowed hosts with wildcards separated by commas. By default all hosts are allowed. +You can define which hosts are allowed for your particular application. + +For example if you add `--cors "*.staging.domain,*.prod.domain"`, it allows all origins +like `my.staging.domain` or `my.prod.domain`, but it will refuse to serve other origins. + === "CLI" ``` bash @@ -30,6 +36,7 @@ Also you can configure number of actix `workers` that handle connections. --max-body-size 1000000 \ --url "/files" \ --log-level "INFO" + --cors "my.*.domain.com,your.*.domain.com" ``` === "ENV" @@ -41,6 +48,7 @@ Also you can configure number of actix `workers` that handle connections. export RUSTUS_MAX_BODY_SIZE="1000000" export RUSTUS_URL="/files" export RUSTUS_LOG_LEVEL="INFO" + export RUSTUS_CORS="my.*.domain.com,your.*.domain.com" rustus ``` @@ -70,20 +78,13 @@ Available variables: * `{day}` - current day number from 1 to 31; * `{hour}` - hour number from 0 to 23; * `{minute}` - minute number from 0 to 59; -* `{env[ENV_NAME]}` - environment variable where `ENV_NAME` is name of your variable. - -!!! note - - All environment variables are saved in memory during rustus startup. - So you cannot change variable dynamically. Even if you change env used in - structure pattern it won't change. -For example if you use `{env[HOSTNAME]}/{year}/{month}/{day}` as your dir-structure, rustus stores files like: +For example if you use `files/{year}/{month}/{day}` as your dir-structure, rustus stores files like: ``` bash $ tree data data -└── rtus-68cb5b8746-5mgw9 +└── files └── 2022 └── 1 └── 8 diff --git a/src/config.rs b/src/config.rs index 3daf87f..974f3f1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -204,6 +204,12 @@ pub struct RustusConf { #[structopt(long, default_value = "/files", env = "RUSTUS_URL")] pub url: String, + /// Allowed hosts for CORS protocol. + /// + /// By default all hosts are allowed. + #[structopt(long, env = "RUSTUS_CORS", use_delimiter = true)] + pub cors: Vec, + /// Maximum payload size. /// /// This limit used to reduce amount of consumed memory. diff --git a/src/errors.rs b/src/errors.rs index 0f17602..265507d 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -67,6 +67,8 @@ pub enum RustusError { WrongHeaderValue, #[error("Metrics error: {0}")] PrometheusError(#[from] prometheus::Error), + #[error("Blocking error: {0}")] + BlockingError(#[from] actix_web::error::BlockingError), } /// This conversion allows us to use `RustusError` in the `main` function. diff --git a/src/info_storages/db_info_storage.rs b/src/info_storages/db_info_storage.rs index 2a7a1f2..f759668 100644 --- a/src/info_storages/db_info_storage.rs +++ b/src/info_storages/db_info_storage.rs @@ -1,4 +1,4 @@ -use std::time::Duration; +use std::{sync::Arc, time::Duration}; use async_trait::async_trait; use rbatis::{crud::CRUD, crud_table, db::DBPoolOptions, rbatis::Rbatis}; @@ -25,8 +25,9 @@ impl TryFrom<&FileInfo> for DbModel { } } +#[derive(Clone)] pub struct DBInfoStorage { - db: Rbatis, + db: Arc, } impl DBInfoStorage { @@ -35,7 +36,7 @@ impl DBInfoStorage { let mut opts = DBPoolOptions::new(); opts.connect_timeout = Duration::new(2, 0); db.link_opt(dsn, opts).await?; - Ok(Self { db }) + Ok(Self { db: Arc::new(db) }) } } diff --git a/src/info_storages/file_info_storage.rs b/src/info_storages/file_info_storage.rs index 461ca73..63d2980 100644 --- a/src/info_storages/file_info_storage.rs +++ b/src/info_storages/file_info_storage.rs @@ -16,6 +16,7 @@ use crate::{ info_storages::{FileInfo, InfoStorage}, }; +#[derive(Clone)] pub struct FileInfoStorage { info_dir: PathBuf, } diff --git a/src/info_storages/models/info_store.rs b/src/info_storages/models/info_store.rs index ec5ffe6..4ca3cf5 100644 --- a/src/info_storages/models/info_store.rs +++ b/src/info_storages/models/info_store.rs @@ -1,12 +1,13 @@ use crate::{errors::RustusResult, info_storages::FileInfo}; use async_trait::async_trait; +use dyn_clone::DynClone; /// Trait for every info storage. /// /// This trait defines required functions /// for building your own info storage. #[async_trait] -pub trait InfoStorage { +pub trait InfoStorage: DynClone { /// Prepare storage for storing files. /// /// In this function you can prepare @@ -39,3 +40,5 @@ pub trait InfoStorage { /// associated with the given `file_id`. async fn remove_info(&self, file_id: &str) -> RustusResult<()>; } + +dyn_clone::clone_trait_object!(InfoStorage); diff --git a/src/info_storages/redis_info_storage.rs b/src/info_storages/redis_info_storage.rs index 07adebe..dd9f495 100644 --- a/src/info_storages/redis_info_storage.rs +++ b/src/info_storages/redis_info_storage.rs @@ -7,6 +7,7 @@ use crate::{ info_storages::{FileInfo, InfoStorage}, }; +#[derive(Clone)] pub struct RedisStorage { pool: Pool, } diff --git a/src/main.rs b/src/main.rs index 26ab5eb..88da7a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,8 @@ #![cfg_attr(coverage, feature(no_coverage))] -use std::{str::FromStr, sync::Arc}; +use std::str::FromStr; +use actix_cors::Cors; use actix_web::{ dev::{Server, Service}, http::Method, @@ -14,6 +15,7 @@ use fern::{ use log::{error, LevelFilter}; use config::RustusConf; +use wildmatch::WildMatch; use crate::{ errors::{RustusError, RustusResult}, @@ -61,6 +63,41 @@ fn greeting(app_conf: &RustusConf) { eprintln!(); } +/// Create CORS rules for the server. +/// +/// CORS rules are applied to every handler. +/// +/// If the origins vector is empty all origins are +/// welcome, otherwise it will create a wildcard match for +/// every host. +fn create_cors(origins: Vec) -> Cors { + let mut cors = Cors::default() + .allowed_methods(vec!["OPTIONS", "GET", "HEAD", "POST", "PATCH", "DELETE"]) + .allowed_headers(vec![ + "Content-Type", + "Upload-Offset", + "Upload-Checksum", + "Upload-Length", + "Upload-Metadata", + "Upload-Concat", + "Upload-Defer-Length", + ]); + + // We allow any origin by default if no origin is specified. + if origins.is_empty() { + return cors.allow_any_origin(); + } + + // Adding origins. + for origin in origins { + cors = cors.allowed_origin_fn(move |request_origin, _| { + WildMatch::new(origin.clone().as_str()) == request_origin.to_str().unwrap_or_default() + }); + } + + cors +} + /// Creates Actix server. /// /// This function is parametrized with @@ -78,8 +115,8 @@ fn greeting(app_conf: &RustusConf) { pub fn create_server(state: State) -> RustusResult { let host = state.config.host.clone(); let port = state.config.port; + let cors_hosts = state.config.cors.clone(); let workers = state.config.workers; - let state_data: web::Data = web::Data::from(Arc::new(state)); let metrics = actix_web_prom::PrometheusMetricsBuilder::new("") .endpoint("/metrics") .build() @@ -104,9 +141,10 @@ pub fn create_server(state: State) -> RustusResult { App::new() .app_data(web::Data::new(active_uploads.clone())) .app_data(web::Data::new(file_sizes.clone())) - .configure(rustus_service(state_data.clone())) + .configure(rustus_service(state.clone())) .wrap(metrics.clone()) .wrap(middleware::Logger::new("\"%r\" \"-\" \"%s\" \"%a\" \"%D\"")) + .wrap(create_cors(cors_hosts.clone())) // Middleware that overrides method of a request if // "X-HTTP-Method-Override" header is provided. .wrap_fn(|mut req, srv| { diff --git a/src/notifiers/amqp_notifier.rs b/src/notifiers/amqp_notifier.rs index ea94fcc..ae91eb3 100644 --- a/src/notifiers/amqp_notifier.rs +++ b/src/notifiers/amqp_notifier.rs @@ -14,6 +14,7 @@ use strum::IntoEnumIterator; use tokio_amqp::LapinTokioExt; #[allow(clippy::struct_excessive_bools)] +#[derive(Clone)] pub struct DeclareOptions { pub declare_exchange: bool, pub durable_exchange: bool, @@ -21,6 +22,7 @@ pub struct DeclareOptions { pub durable_queues: bool, } +#[derive(Clone)] pub struct AMQPNotifier { exchange_name: String, pool: Pool, diff --git a/src/notifiers/dir_notifier.rs b/src/notifiers/dir_notifier.rs index 303b21b..2d1ef48 100644 --- a/src/notifiers/dir_notifier.rs +++ b/src/notifiers/dir_notifier.rs @@ -9,6 +9,7 @@ use log::debug; use std::path::PathBuf; use tokio::process::Command; +#[derive(Clone)] pub struct DirNotifier { pub dir: PathBuf, } diff --git a/src/notifiers/file_notifier.rs b/src/notifiers/file_notifier.rs index 911c279..91f2b3d 100644 --- a/src/notifiers/file_notifier.rs +++ b/src/notifiers/file_notifier.rs @@ -8,6 +8,7 @@ use async_trait::async_trait; use log::debug; use tokio::process::Command; +#[derive(Clone)] pub struct FileNotifier { pub command: String, } diff --git a/src/notifiers/http_notifier.rs b/src/notifiers/http_notifier.rs index a6887cc..4e7cb68 100644 --- a/src/notifiers/http_notifier.rs +++ b/src/notifiers/http_notifier.rs @@ -8,6 +8,7 @@ use log::debug; use reqwest::Client; use std::time::Duration; +#[derive(Clone)] pub struct HttpNotifier { urls: Vec, client: Client, diff --git a/src/notifiers/models/message_format.rs b/src/notifiers/models/message_format.rs index 64f27d7..6844009 100644 --- a/src/notifiers/models/message_format.rs +++ b/src/notifiers/models/message_format.rs @@ -1,11 +1,9 @@ -use crate::{errors::RustusResult, info_storages::FileInfo}; -use actix_web::HttpRequest; +use crate::{from_str, info_storages::FileInfo}; +use actix_web::{http::header::HeaderMap, HttpRequest}; use derive_more::{Display, From}; use serde::Serialize; -use serde_json::{Map, Value}; +use serde_json::{json, Value}; use std::collections::HashMap; - -use crate::from_str; use strum::EnumIter; #[derive(Clone, Debug, Eq, Display, From, PartialEq, EnumIter)] @@ -19,7 +17,7 @@ pub enum Format { from_str!(Format, "format"); impl Format { - pub fn format(&self, request: &HttpRequest, file_info: &FileInfo) -> RustusResult { + pub fn format(&self, request: &HttpRequest, file_info: &FileInfo) -> String { match self { Self::Default => default_format(request, file_info), Self::Tusd => tusd_format(request, file_info), @@ -70,30 +68,14 @@ impl From for TusdFileInfo { } } -/// Turn request into `serde_json::Value`. +/// Transforms headersmap to `HashMap`. /// -/// This function is used by different formats. -fn serialize_request( - request: &HttpRequest, - method_str: String, - remote_addr_str: String, - headers_str: String, - use_arrays: bool, -) -> Value { - let mut map = Map::new(); - map.insert("URI".into(), Value::String(request.uri().to_string())); - map.insert(method_str, Value::String(request.method().to_string())); - map.insert( - remote_addr_str, - Value::String( - request - .connection_info() - .realip_remote_addr() - .map_or_else(String::new, String::from), - ), - ); - let mut headers_map = Map::new(); - for (name, value) in request.headers() { +/// Keys of the resulting map are Strings, +/// Values are serde values. It ca be either string values or +/// arrays. +fn headers_to_value_map(headers: &HeaderMap, use_arrays: bool) -> HashMap { + let mut headers_map = HashMap::new(); + for (name, value) in headers.iter() { if let Ok(header_val) = value.to_str().map(String::from) { if use_arrays { headers_map.insert( @@ -105,27 +87,24 @@ fn serialize_request( } } } - map.insert(headers_str, Value::Object(headers_map)); - Value::Object(map) + headers_map } /// Default format is specific for Rustus. /// /// This format is a simple serialized `FileInfo` and some parts of the request. -pub fn default_format(request: &HttpRequest, file_info: &FileInfo) -> RustusResult { - let mut result_map = Map::new(); - result_map.insert("upload".into(), serde_json::to_value(file_info)?); - result_map.insert( - "request".into(), - serialize_request( - request, - "method".into(), - "remote_addr".into(), - "headers".into(), - false, - ), - ); - Ok(Value::Object(result_map).to_string()) +pub fn default_format(request: &HttpRequest, file_info: &FileInfo) -> String { + let remote_addr = request.connection_info().peer_addr().map(String::from); + let value = json!({ + "upload": file_info, + "request": { + "URI": request.uri().to_string(), + "method": request.method().to_string(), + "remote_addr": remote_addr, + "headers": headers_to_value_map(request.headers(), false) + } + }); + value.to_string() } /// This format follows TUSD hooks. @@ -135,22 +114,16 @@ pub fn default_format(request: &HttpRequest, file_info: &FileInfo) -> RustusResu /// /// Generally speaking, it's almost the same as the default format, /// but some variables are ommited and headers are added to the request. -pub fn tusd_format(request: &HttpRequest, file_info: &FileInfo) -> RustusResult { - let mut result_map = Map::new(); - - result_map.insert( - "Upload".into(), - serde_json::to_value(TusdFileInfo::from(file_info.clone()))?, - ); - result_map.insert( - "HTTPRequest".into(), - serialize_request( - request, - "Method".into(), - "RemoteAddr".into(), - "Header".into(), - true, - ), - ); - Ok(Value::Object(result_map).to_string()) +pub fn tusd_format(request: &HttpRequest, file_info: &FileInfo) -> String { + let remote_addr = request.connection_info().peer_addr().map(String::from); + let value = json!({ + "Upload": file_info, + "HTTPRequest": { + "URI": request.uri().to_string(), + "Method": request.method().to_string(), + "RemoteAddr": remote_addr, + "Header": headers_to_value_map(request.headers(), false) + } + }); + value.to_string() } diff --git a/src/notifiers/models/notification_manager.rs b/src/notifiers/models/notification_manager.rs index 521b493..8687fd2 100644 --- a/src/notifiers/models/notification_manager.rs +++ b/src/notifiers/models/notification_manager.rs @@ -10,6 +10,7 @@ use crate::{ use actix_web::http::header::HeaderMap; use log::debug; +#[derive(Clone)] pub struct NotificationManager { notifiers: Vec>, } diff --git a/src/notifiers/models/notifier.rs b/src/notifiers/models/notifier.rs index 272fa8c..8c52fa3 100644 --- a/src/notifiers/models/notifier.rs +++ b/src/notifiers/models/notifier.rs @@ -3,9 +3,10 @@ use actix_web::http::header::HeaderMap; use crate::notifiers::Hook; use async_trait::async_trait; +use dyn_clone::DynClone; #[async_trait] -pub trait Notifier { +pub trait Notifier: DynClone { async fn prepare(&mut self) -> RustusResult<()>; async fn send_message( &self, @@ -14,3 +15,5 @@ pub trait Notifier { headers_map: &HeaderMap, ) -> RustusResult<()>; } + +dyn_clone::clone_trait_object!(Notifier); diff --git a/src/protocol/core/get_info.rs b/src/protocol/core/get_info.rs index ddb014a..112184d 100644 --- a/src/protocol/core/get_info.rs +++ b/src/protocol/core/get_info.rs @@ -1,5 +1,8 @@ use crate::errors::RustusError; -use actix_web::{web, HttpRequest, HttpResponse}; +use actix_web::{ + http::header::{CacheControl, CacheDirective}, + web, HttpRequest, HttpResponse, +}; use futures::stream::empty; use crate::{RustusResult, State}; @@ -60,6 +63,7 @@ pub async fn get_file_info( if let Some(meta) = file_info.get_metadata_string() { builder.insert_header(("Upload-Metadata", meta)); } + builder.insert_header(CacheControl(vec![CacheDirective::NoCache])); Ok(builder.streaming(empty::>())) } @@ -70,16 +74,13 @@ mod tests { use crate::{rustus_service, State}; use actix_web::{ test::{call_service, init_service, TestRequest}, - web, App, + App, }; #[actix_rt::test] async fn success() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file_info = state.create_test_file().await; file_info.offset = 100; file_info.length = Some(100); @@ -106,10 +107,7 @@ mod tests { #[actix_rt::test] async fn success_metadata() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file_info = state.create_test_file().await; file_info.offset = 100; file_info.length = Some(100); @@ -138,10 +136,7 @@ mod tests { #[actix_rt::test] async fn success_defer_len() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file_info = state.create_test_file().await; file_info.deferred_size = true; file_info.length = None; @@ -168,10 +163,7 @@ mod tests { #[actix_rt::test] async fn test_get_file_info_partial() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file_info = state.create_test_file().await; file_info.is_partial = true; state @@ -197,10 +189,7 @@ mod tests { #[actix_rt::test] async fn success_final() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file_info = state.create_test_file().await; file_info.is_partial = false; file_info.is_final = true; @@ -233,10 +222,7 @@ mod tests { #[actix_rt::test] async fn no_file() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::with_uri(state.config.file_url("unknknown").as_str()) .method(Method::HEAD) .to_request(); @@ -247,10 +233,7 @@ mod tests { #[actix_rt::test] async fn test_get_file_info_wrong_storage() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file_info = state.create_test_file().await; file_info.storage = String::from("unknown"); state diff --git a/src/protocol/core/server_info.rs b/src/protocol/core/server_info.rs index 41d1e2f..a74cc8c 100644 --- a/src/protocol/core/server_info.rs +++ b/src/protocol/core/server_info.rs @@ -28,15 +28,12 @@ mod tests { use crate::{protocol::extensions::Extensions, rustus_service, State}; use actix_web::test::{call_service, init_service, TestRequest}; - use actix_web::{http::Method, web, App}; + use actix_web::{http::Method, App}; #[actix_rt::test] async fn test_server_info() { let mut state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; state.config.tus_extensions = vec![ Extensions::Creation, Extensions::Concatenation, diff --git a/src/protocol/core/write_bytes.rs b/src/protocol/core/write_bytes.rs index 422c0e4..32c0d59 100644 --- a/src/protocol/core/write_bytes.rs +++ b/src/protocol/core/write_bytes.rs @@ -1,4 +1,9 @@ -use actix_web::{web, web::Bytes, HttpRequest, HttpResponse}; +use actix_web::{ + http::header::{CacheControl, CacheDirective}, + web, + web::Bytes, + HttpRequest, HttpResponse, +}; #[cfg(feature = "hashers")] use crate::utils::hashes::verify_chunk_checksum; @@ -119,7 +124,7 @@ pub async fn write_bytes( .config .notification_opts .hooks_format - .format(&request, &file_info)?; + .format(&request, &file_info); let headers = request.headers().clone(); tokio::task::spawn_local(async move { state @@ -136,6 +141,7 @@ pub async fn write_bytes( Ok(HttpResponse::NoContent() .insert_header(("Upload-Offset", file_info.offset.to_string())) + .insert_header(CacheControl(vec![CacheDirective::NoCache])) .finish()) } @@ -145,7 +151,7 @@ mod tests { use actix_web::{ http::StatusCode, test::{call_service, init_service, TestRequest}, - web, App, + App, }; #[actix_rt::test] @@ -154,10 +160,7 @@ mod tests { /// This test creates file and writes bytes to it. async fn success() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.length = Some(100); file.offset = 0; @@ -195,10 +198,7 @@ mod tests { /// file's length while writing bytes to it. async fn success_update_file_length() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.length = None; file.deferred_size = true; @@ -238,10 +238,7 @@ mod tests { /// is less than current offset, error is thrown. async fn new_file_length_lt_offset() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.length = None; file.deferred_size = true; @@ -265,10 +262,7 @@ mod tests { /// error is thrown. async fn new_file_length_size_already_known() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.length = Some(100); file.deferred_size = false; @@ -291,10 +285,7 @@ mod tests { /// wrong status code is returned. async fn no_content_header() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.length = Some(100); file.offset = 0; @@ -312,10 +303,7 @@ mod tests { /// Tests that method will return error if no offset header specified. async fn no_offset_header() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.length = Some(100); file.offset = 0; @@ -333,10 +321,7 @@ mod tests { /// Tests that method will return error if wrong offset is passed. async fn wrong_offset_header() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.length = Some(100); file.offset = 0; @@ -355,10 +340,7 @@ mod tests { /// Tests that method would return error if file was already uploaded. async fn final_upload() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.is_final = true; state.info_storage.set_info(&file, false).await.unwrap(); @@ -376,10 +358,7 @@ mod tests { /// Tests that method would return 404 if file was saved in other storage. async fn wrong_storage() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.storage = "unknown".into(); state.info_storage.set_info(&file, false).await.unwrap(); @@ -398,10 +377,7 @@ mod tests { /// file if it's offset already equal to length. async fn frozen_file() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.offset = 10; file.length = Some(10); @@ -421,10 +397,7 @@ mod tests { /// unknown file_id is passed. async fn unknown_file_id() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::patch() .uri(state.config.file_url("unknown").as_str()) .insert_header(("Upload-Offset", "0")) @@ -439,10 +412,7 @@ mod tests { /// Tests checksum validation. async fn wrong_checksum() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file = state.create_test_file().await; file.offset = 0; file.length = Some(10); diff --git a/src/protocol/creation/routes.rs b/src/protocol/creation/routes.rs index 52fc2c7..d6a0f95 100644 --- a/src/protocol/creation/routes.rs +++ b/src/protocol/creation/routes.rs @@ -131,7 +131,7 @@ pub async fn create_file( .config .notification_opts .hooks_format - .format(&request, &file_info)?; + .format(&request, &file_info); let headers = request.headers(); state .notification_manager @@ -208,7 +208,7 @@ pub async fn create_file( .config .notification_opts .hooks_format - .format(&request, &file_info)?; + .format(&request, &file_info); let headers = request.headers().clone(); // Adding send_message task to tokio reactor. // Thin function would be executed in background. @@ -241,10 +241,7 @@ mod tests { #[actix_rt::test] async fn success() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::post() .uri(state.config.base_url().as_str()) .insert_header(("Upload-Length", 100)) @@ -269,10 +266,7 @@ mod tests { #[actix_rt::test] async fn success_with_bytes() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let test_data = "memes"; let request = TestRequest::post() .uri(state.config.base_url().as_str()) @@ -300,10 +294,7 @@ mod tests { #[actix_rt::test] async fn with_bytes_wrong_content_type() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let test_data = "memes"; let request = TestRequest::post() .uri(state.config.base_url().as_str()) @@ -331,10 +322,7 @@ mod tests { #[actix_rt::test] async fn success_defer_size() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::post() .uri(state.config.base_url().as_str()) .insert_header(("Upload-Defer-Length", "1")) @@ -359,10 +347,7 @@ mod tests { #[actix_rt::test] async fn success_partial_upload() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::post() .uri(state.config.base_url().as_str()) .insert_header(("Upload-Length", 100)) @@ -389,10 +374,7 @@ mod tests { #[actix_rt::test] async fn success_final_upload() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut part1 = state.create_test_file().await; let mut part2 = state.create_test_file().await; part1.is_partial = true; @@ -434,10 +416,7 @@ mod tests { #[actix_rt::test] async fn success_with_metadata() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::post() .uri(state.config.base_url().as_str()) .insert_header(("Upload-Length", 100)) @@ -472,10 +451,7 @@ mod tests { #[actix_rt::test] async fn success_with_metadata_wrong_encoding() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::post() .uri(state.config.base_url().as_str()) .insert_header(("Upload-Length", 100)) @@ -506,10 +482,7 @@ mod tests { #[actix_rt::test] async fn no_length_header() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::post() .uri(state.config.base_url().as_str()) .to_request(); diff --git a/src/protocol/getting/routes.rs b/src/protocol/getting/routes.rs index 6371d6e..37c51f1 100644 --- a/src/protocol/getting/routes.rs +++ b/src/protocol/getting/routes.rs @@ -25,17 +25,14 @@ mod test { use actix_web::{ http::StatusCode, test::{call_service, init_service, TestRequest}, - web, App, + App, }; use bytes::Bytes; #[actix_rt::test] async fn success() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let file_info = state.create_test_file().await; state .data_storage @@ -52,10 +49,7 @@ mod test { #[actix_rt::test] async fn unknown_file_id() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::get() .uri(state.config.file_url("random_str").as_str()) .to_request(); @@ -66,10 +60,7 @@ mod test { #[actix_rt::test] async fn unknown_storage() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file_info = state.create_test_file().await; file_info.storage = "unknown_storage".into(); state diff --git a/src/protocol/termination/routes.rs b/src/protocol/termination/routes.rs index 31a5df3..d024c80 100644 --- a/src/protocol/termination/routes.rs +++ b/src/protocol/termination/routes.rs @@ -27,7 +27,7 @@ pub async fn terminate( .config .notification_opts .hooks_format - .format(&request, &file_info)?; + .format(&request, &file_info); let headers = request.headers().clone(); tokio::task::spawn_local(async move { state @@ -46,17 +46,14 @@ mod tests { use actix_web::{ http::StatusCode, test::{call_service, init_service, TestRequest}, - web, App, + App, }; use std::path::PathBuf; #[actix_rt::test] async fn success() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let file_info = state.create_test_file().await; let request = TestRequest::delete() .uri(state.config.file_url(file_info.id.as_str()).as_str()) @@ -74,10 +71,7 @@ mod tests { #[actix_rt::test] async fn unknown_file_id() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let request = TestRequest::delete() .param("file_id", "not_exists") .to_request(); @@ -88,10 +82,7 @@ mod tests { #[actix_rt::test] async fn wrong_storage() { let state = State::test_new().await; - let mut rustus = init_service( - App::new().configure(rustus_service(web::Data::new(state.test_clone().await))), - ) - .await; + let mut rustus = init_service(App::new().configure(rustus_service(state.clone()))).await; let mut file_info = state.create_test_file().await; file_info.storage = "unknown_storage".into(); state diff --git a/src/server.rs b/src/server.rs index 02496d3..f7e149a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,11 +1,11 @@ use crate::{protocol, State}; use actix_web::{middleware, web, web::PayloadConfig}; -pub fn rustus_service(state: web::Data) -> Box { +pub fn rustus_service(state: State) -> Box { Box::new(move |web_app| { web_app.service( web::scope(state.config.base_url().as_str()) - .app_data(state.clone()) + .app_data(web::Data::new(state.clone())) .app_data(PayloadConfig::new(state.config.max_body_size)) // Main middleware that appends TUS headers. .wrap( diff --git a/src/state.rs b/src/state.rs index f74a2d6..c67ff1b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -2,6 +2,7 @@ use crate::info_storages::FileInfo; use crate::{InfoStorage, NotificationManager, RustusConf, Storage}; +#[derive(Clone)] pub struct State { pub config: RustusConf, pub data_storage: Box, @@ -59,12 +60,6 @@ impl State { Self::from_config_test(config).await } - #[cfg(test)] - pub async fn test_clone(&self) -> Self { - let config = self.config.clone(); - Self::from_config_test(config).await - } - #[cfg(test)] pub async fn create_test_file(&self) -> FileInfo { let mut new_file = FileInfo::new( diff --git a/src/storages/file_storage.rs b/src/storages/file_storage.rs index 29c431b..af6757b 100644 --- a/src/storages/file_storage.rs +++ b/src/storages/file_storage.rs @@ -17,7 +17,7 @@ use crate::{ }; use derive_more::Display; -#[derive(Display)] +#[derive(Display, Clone)] #[display(fmt = "file_storage")] pub struct FileStorage { data_dir: PathBuf, @@ -87,7 +87,7 @@ impl Storage for FileStorage { if file_info.path.is_none() { return Err(RustusError::FileNotFound); } - let path = String::from(file_info.path.as_ref().unwrap()); + let path = file_info.path.as_ref().unwrap().clone(); let force_sync = self.force_fsync; tokio::task::spawn_blocking(move || { // Opening file in w+a mode. @@ -104,13 +104,11 @@ impl Storage for FileStorage { error!("{:?}", err); RustusError::UnableToWrite(err.to_string()) })?; - { - let mut writer = BufWriter::new(file); - writer.write_all(bytes.as_ref())?; - writer.flush()?; - if force_sync { - writer.get_ref().sync_data()?; - } + let mut writer = BufWriter::new(file); + writer.write_all(bytes.as_ref())?; + writer.flush()?; + if force_sync { + writer.get_ref().sync_data()?; } Ok(()) }) @@ -143,14 +141,15 @@ impl Storage for FileStorage { file_info: &FileInfo, parts_info: Vec, ) -> RustusResult<()> { - let info = file_info.clone(); + // let info = file_info.clone(); let force_fsync = self.force_fsync; + let path = file_info.path.as_ref().unwrap().clone(); tokio::task::spawn_blocking(move || { let file = OpenOptions::new() .write(true) .append(true) .create(true) - .open(info.path.as_ref().unwrap().clone()) + .open(path) .map_err(|err| { error!("{:?}", err); RustusError::UnableToWrite(err.to_string()) diff --git a/src/storages/models/storage.rs b/src/storages/models/storage.rs index 2ef0f6b..9cfff4a 100644 --- a/src/storages/models/storage.rs +++ b/src/storages/models/storage.rs @@ -2,10 +2,11 @@ use crate::{errors::RustusResult, info_storages::FileInfo}; use actix_files::NamedFile; use async_trait::async_trait; use bytes::Bytes; +use dyn_clone::DynClone; use std::fmt::Display; #[async_trait] -pub trait Storage: Display { +pub trait Storage: Display + DynClone { /// Prepare storage before starting up server. /// /// Function to check if configuration is correct @@ -77,3 +78,5 @@ pub trait Storage: Display { /// `file_info` - info about current file. async fn remove_file(&self, file_info: &FileInfo) -> RustusResult<()>; } + +dyn_clone::clone_trait_object!(Storage); diff --git a/src/utils/dir_struct.rs b/src/utils/dir_struct.rs index 96bb690..b1c3bef 100644 --- a/src/utils/dir_struct.rs +++ b/src/utils/dir_struct.rs @@ -1,32 +1,14 @@ use chrono::{Datelike, Timelike}; -use lazy_static::lazy_static; -use log::error; -use std::{collections::HashMap, env}; - -lazy_static! { - /// Freezing ENVS on startup. - static ref ENV_MAP: HashMap = { - let mut m = HashMap::new(); - for (key, value) in env::vars() { - m.insert(format!("env[{}]", key), value); - } - m - }; -} /// Generate directory name with user template. pub fn dir_struct(dir_structure: &str) -> String { let now = chrono::Utc::now(); - let mut vars: HashMap = ENV_MAP.clone(); - vars.insert("day".into(), now.day().to_string()); - vars.insert("month".into(), now.month().to_string()); - vars.insert("year".into(), now.year().to_string()); - vars.insert("hour".into(), now.hour().to_string()); - vars.insert("minute".into(), now.minute().to_string()); - strfmt::strfmt(dir_structure, &vars).unwrap_or_else(|err| { - error!("{}", err); - "".into() - }) + dir_structure + .replace("{day}", now.day().to_string().as_str()) + .replace("{month}", now.month().to_string().as_str()) + .replace("{year}", now.year().to_string().as_str()) + .replace("{hour}", now.hour().to_string().as_str()) + .replace("{minute}", now.minute().to_string().as_str()) } #[cfg(test)] @@ -44,6 +26,6 @@ mod tests { #[test] pub fn test_unknown_var() { let dir = dir_struct("test/{quake}"); - assert_eq!(dir, String::from("")); + assert_eq!(dir, String::from("test/{quake}")); } }