Update rust-s3 dependency and move Cargo.toml dependencies

This commit is contained in:
Alex Auvolat 2023-05-12 12:12:32 +02:00
parent 30a3cec87e
commit 10e06737cf
6 changed files with 120 additions and 110 deletions

195
Cargo.lock generated
View File

@ -115,12 +115,6 @@ dependencies = [
"const-random", "const-random",
] ]
[[package]]
name = "ahash"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.6" version = "0.7.6"
@ -172,12 +166,6 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "anyhow"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]] [[package]]
name = "arc-swap" name = "arc-swap"
version = "1.6.0" version = "1.6.0"
@ -255,18 +243,16 @@ dependencies = [
[[package]] [[package]]
name = "attohttpc" name = "attohttpc"
version = "0.18.0" version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e69e13a99a7e6e070bb114f7ff381e58c7ccc188630121fc4c2fe4bcf24cd072" checksum = "1fcf00bc6d5abb29b5f97e3c61a90b6d3caa12f3faf897d4a3e3607c050a35a7"
dependencies = [ dependencies = [
"http 0.2.8", "http 0.2.8",
"log 0.4.17", "log 0.4.17",
"native-tls", "native-tls",
"openssl",
"serde 1.0.152", "serde 1.0.152",
"serde_json", "serde_json",
"url 2.3.1", "url 2.3.1",
"wildmatch",
] ]
[[package]] [[package]]
@ -297,27 +283,28 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]] [[package]]
name = "aws-creds" name = "aws-creds"
version = "0.27.1" version = "0.34.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "460a75eac8f3cb7683e0a9a588a83c3ff039331ea7bfbfbfcecf1dacab276e11" checksum = "3776743bb68d4ad02ba30ba8f64373f1be4e082fe47651767171ce75bb2f6cf5"
dependencies = [ dependencies = [
"anyhow",
"attohttpc", "attohttpc",
"dirs", "dirs",
"rust-ini 0.17.0", "log 0.4.17",
"quick-xml 0.26.0",
"rust-ini 0.18.0",
"serde 1.0.152", "serde 1.0.152",
"serde-xml-rs", "thiserror",
"serde_derive", "time 0.3.17",
"url 2.3.1", "url 2.3.1",
] ]
[[package]] [[package]]
name = "aws-region" name = "aws-region"
version = "0.23.5" version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10110ddbd800fb47e6bef95e88fc13495795d252f585272a4fa3ac4f5b2e0a4d" checksum = "056557a61427d0e5ba29dd931031c8ffed4ee7a550e7cd55692a9d8deb0a9dba"
dependencies = [ dependencies = [
"anyhow", "thiserror",
] ]
[[package]] [[package]]
@ -442,6 +429,15 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]] [[package]]
name = "block_on_proc" name = "block_on_proc"
version = "0.2.0" version = "0.2.0"
@ -702,7 +698,7 @@ dependencies = [
"hmac 0.10.1", "hmac 0.10.1",
"percent-encoding 2.2.0", "percent-encoding 2.2.0",
"rand 0.8.5", "rand 0.8.5",
"sha2", "sha2 0.9.9",
"time 0.1.45", "time 0.1.45",
] ]
@ -939,16 +935,6 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "crypto-mac"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714"
dependencies = [
"generic-array",
"subtle",
]
[[package]] [[package]]
name = "ctr" name = "ctr"
version = "0.6.0" version = "0.6.0"
@ -1214,6 +1200,17 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "digest"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f"
dependencies = [
"block-buffer 0.10.4",
"crypto-common",
"subtle",
]
[[package]] [[package]]
name = "diligent-date-parser" name = "diligent-date-parser"
version = "0.1.4" version = "0.1.4"
@ -1245,12 +1242,9 @@ dependencies = [
[[package]] [[package]]
name = "dlv-list" name = "dlv-list"
version = "0.2.3" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68df3f2b690c1b86e65ef7830956aededf3cb0a16f898f79b9a6f421a7b6211b" checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
dependencies = [
"rand 0.8.5",
]
[[package]] [[package]]
name = "dotenv" name = "dotenv"
@ -1847,15 +1841,6 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
dependencies = [
"ahash 0.4.7",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.11.2" version = "0.11.2"
@ -1904,7 +1889,7 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f"
dependencies = [ dependencies = [
"digest", "digest 0.9.0",
"hmac 0.10.1", "hmac 0.10.1",
] ]
@ -1914,18 +1899,17 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15"
dependencies = [ dependencies = [
"crypto-mac 0.10.1", "crypto-mac",
"digest", "digest 0.9.0",
] ]
[[package]] [[package]]
name = "hmac" name = "hmac"
version = "0.11.0" version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [ dependencies = [
"crypto-mac 0.11.1", "digest 0.10.6",
"digest",
] ]
[[package]] [[package]]
@ -2775,11 +2759,11 @@ dependencies = [
[[package]] [[package]]
name = "minidom" name = "minidom"
version = "0.13.0" version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "332592c2149fc7dd40a64fc9ef6f0d65607284b474cef9817d1fc8c7e7b3608e" checksum = "2e9ce45d459e358790a285e7609ff5ae4cfab88b75f237e8838e62029dda397b"
dependencies = [ dependencies = [
"quick-xml 0.20.0", "rxml",
] ]
[[package]] [[package]]
@ -3206,12 +3190,12 @@ dependencies = [
[[package]] [[package]]
name = "ordered-multimap" name = "ordered-multimap"
version = "0.3.1" version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485" checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a"
dependencies = [ dependencies = [
"dlv-list", "dlv-list",
"hashbrown 0.9.1", "hashbrown 0.12.3",
] ]
[[package]] [[package]]
@ -3445,7 +3429,6 @@ dependencies = [
"rocket_i18n", "rocket_i18n",
"rsass", "rsass",
"ructe", "ructe",
"rust-s3",
"scheduled-thread-pool", "scheduled-thread-pool",
"serde 1.0.152", "serde 1.0.152",
"serde_json", "serde_json",
@ -3707,11 +3690,12 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]] [[package]]
name = "quick-xml" name = "quick-xml"
version = "0.20.0" version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26aab6b48e2590e4a64d1ed808749ba06257882b461d01ca71baeb747074a6dd" checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd"
dependencies = [ dependencies = [
"memchr", "memchr",
"serde 1.0.152",
] ]
[[package]] [[package]]
@ -4335,9 +4319,9 @@ checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2"
[[package]] [[package]]
name = "rust-ini" name = "rust-ini"
version = "0.17.0" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63471c4aa97a1cf8332a5f97709a79a4234698de6a1f5087faf66f2dae810e22" checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"ordered-multimap", "ordered-multimap",
@ -4345,30 +4329,32 @@ dependencies = [
[[package]] [[package]]
name = "rust-s3" name = "rust-s3"
version = "0.29.0" version = "0.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a4e82923ed07143871571852a390742200607e5058ce633afec89752f9c3f82" checksum = "1b2ac5ff6acfbe74226fa701b5ef793aaa054055c13ebb7060ad36942956e027"
dependencies = [ dependencies = [
"anyhow",
"async-trait", "async-trait",
"aws-creds", "aws-creds",
"aws-region", "aws-region",
"base64 0.13.1", "base64 0.13.1",
"block_on_proc", "block_on_proc",
"bytes 1.3.0",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"futures 0.3.25",
"hex", "hex",
"hmac 0.11.0", "hmac 0.12.1",
"http 0.2.8", "http 0.2.8",
"log 0.4.17", "log 0.4.17",
"maybe-async", "maybe-async",
"md5", "md5",
"minidom", "minidom",
"percent-encoding 2.2.0", "percent-encoding 2.2.0",
"quick-xml 0.26.0",
"reqwest 0.11.13", "reqwest 0.11.13",
"serde 1.0.152", "serde 1.0.152",
"serde-xml-rs",
"serde_derive", "serde_derive",
"sha2", "sha2 0.10.6",
"thiserror",
"time 0.3.17", "time 0.3.17",
"tokio 1.24.1", "tokio 1.24.1",
"tokio-stream", "tokio-stream",
@ -4400,6 +4386,25 @@ dependencies = [
"semver", "semver",
] ]
[[package]]
name = "rxml"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a071866b8c681dc2cfffa77184adc32b57b0caad4e620b6292609703bceb804"
dependencies = [
"bytes 1.3.0",
"pin-project-lite 0.2.9",
"rxml_validation",
"smartstring",
"tokio 1.24.1",
]
[[package]]
name = "rxml_validation"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53bc79743f9a66c2fb1f951cd83735f275d46bfe466259fbc5897bb60a0d00ee"
[[package]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.12" version = "1.0.12"
@ -4518,18 +4523,6 @@ dependencies = [
"serde 0.8.23", "serde 0.8.23",
] ]
[[package]]
name = "serde-xml-rs"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65162e9059be2f6a3421ebbb4fef3e74b7d9e7c60c50a0e292c6239f19f1edfa"
dependencies = [
"log 0.4.17",
"serde 1.0.152",
"thiserror",
"xml-rs",
]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.152" version = "1.0.152"
@ -4591,13 +4584,24 @@ version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [ dependencies = [
"block-buffer", "block-buffer 0.9.0",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"cpufeatures", "cpufeatures",
"digest", "digest 0.9.0",
"opaque-debug", "opaque-debug",
] ]
[[package]]
name = "sha2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0"
dependencies = [
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.10.6",
]
[[package]] [[package]]
name = "sharded-slab" name = "sharded-slab"
version = "0.1.4" version = "0.1.4"
@ -4687,6 +4691,15 @@ version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "smartstring"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e714dff2b33f2321fdcd475b71cec79781a692d846f37f415fb395a1d2bcd48e"
dependencies = [
"static_assertions",
]
[[package]] [[package]]
name = "snap" name = "snap"
version = "1.1.0" version = "1.1.0"
@ -5907,12 +5920,6 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "wildmatch"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee583bdc5ff1cf9db20e9db5bb3ff4c3089a8f6b8b31aff265c9aba85812db86"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.2.8" version = "0.2.8"

View File

@ -19,7 +19,7 @@ rocket = "0.4.11"
rocket_contrib = { version = "0.4.11", features = ["json"] } rocket_contrib = { version = "0.4.11", features = ["json"] }
rocket_i18n = "0.4.1" rocket_i18n = "0.4.1"
scheduled-thread-pool = "0.2.6" scheduled-thread-pool = "0.2.6"
rust-s3 = { version = "0.29.0", no-default-features = true, features = ["blocking"], optional = true} #aws-creds = { version = "0.34", default-features = false, features = ["native-tls"] }
serde = "1.0.137" serde = "1.0.137"
serde_json = "1.0.81" serde_json = "1.0.81"
shrinkwraprs = "0.3.0" shrinkwraprs = "0.3.0"
@ -69,13 +69,13 @@ ructe = "0.15.0"
rsass = "0.26" rsass = "0.26"
[features] [features]
default = ["postgres"] default = ["postgres", "s3"]
postgres = ["plume-models/postgres", "diesel/postgres"] postgres = ["plume-models/postgres", "diesel/postgres"]
sqlite = ["plume-models/sqlite", "diesel/sqlite"] sqlite = ["plume-models/sqlite", "diesel/sqlite"]
debug-mailer = [] debug-mailer = []
test = [] test = []
search-lindera = ["plume-models/search-lindera"] search-lindera = ["plume-models/search-lindera"]
s3 = ["rust-s3"] s3 = ["plume-models/s3"]
[workspace] [workspace]
members = ["plume-api", "plume-cli", "plume-models", "plume-common", "plume-front", "plume-macro"] members = ["plume-api", "plume-cli", "plume-models", "plume-common", "plume-front", "plume-macro"]

View File

@ -18,7 +18,8 @@ rocket_i18n = "0.4.1"
reqwest = "0.11.11" reqwest = "0.11.11"
scheduled-thread-pool = "0.2.6" scheduled-thread-pool = "0.2.6"
serde = "1.0.137" serde = "1.0.137"
rust-s3 = { version = "0.29.0", no-default-features = true, features = ["blocking"] } #rust-s3 = { version = "0.29.0", default-features = false, features = ["blocking"] }
rust-s3 = { version = "0.33.0", optional = true, features = ["blocking"] }
serde_derive = "1.0" serde_derive = "1.0"
serde_json = "1.0.81" serde_json = "1.0.81"
tantivy = "0.13.3" tantivy = "0.13.3"
@ -62,3 +63,4 @@ diesel_migrations = "1.3.0"
postgres = ["diesel/postgres", "plume-macro/postgres" ] postgres = ["diesel/postgres", "plume-macro/postgres" ]
sqlite = ["diesel/sqlite", "plume-macro/sqlite" ] sqlite = ["diesel/sqlite", "plume-macro/sqlite" ]
search-lindera = ["lindera-tantivy"] search-lindera = ["lindera-tantivy"]
s3 = ["rust-s3"]

View File

@ -392,13 +392,15 @@ impl S3Config {
secret_key: Some(self.access_key_secret.clone()), secret_key: Some(self.access_key_secret.clone()),
security_token: None, security_token: None,
session_token: None, session_token: None,
expiration: None,
}; };
let bucket = Bucket::new(&self.bucket, region, credentials).unwrap();
if self.path_style { if self.path_style {
Bucket::new_with_path_style(&self.bucket, region, credentials) bucket.with_path_style()
} else { } else {
Bucket::new(&self.bucket, region, credentials) bucket
}.unwrap() }
} }
} }

View File

@ -69,7 +69,8 @@ pub enum Error {
Webfinger, Webfinger,
Expired, Expired,
UserAlreadyExists, UserAlreadyExists,
Anyhow(anyhow::Error), #[cfg(feature = "s3")]
S3(s3::error::S3Error),
} }
impl From<bcrypt::BcryptError> for Error { impl From<bcrypt::BcryptError> for Error {
@ -171,9 +172,10 @@ impl From<request::Error> for Error {
} }
} }
impl From<anyhow::Error> for Error { #[cfg(feature = "s3")]
fn from(err: anyhow::Error) -> Error { impl From<s3::error::S3Error> for Error {
Error::Anyhow(err) fn from(err: s3::error::S3Error) -> Error {
Error::S3(err)
} }
} }

View File

@ -264,14 +264,11 @@ pub fn plume_media_files(file: PathBuf) -> Option<CachedFile> {
.and_then(|ext| ContentType::from_extension(&ext.to_string_lossy())) .and_then(|ext| ContentType::from_extension(&ext.to_string_lossy()))
.unwrap_or(ContentType::Binary); .unwrap_or(ContentType::Binary);
let (data, code) = config.get_bucket() let data = config.get_bucket()
.get_object_blocking(format!("plume-media/{}", file.to_string_lossy())).ok()?; .get_object_blocking(format!("plume-media/{}", file.to_string_lossy())).ok()?;
if code != 200 {
return None;
}
Some(CachedFile { Some(CachedFile {
inner: FileKind::S3 ( data, ct), inner: FileKind::S3 ( data.to_vec(), ct),
cache_control: CacheControl(vec![CacheDirective::MaxAge(60 * 60 * 24 * 30)]), cache_control: CacheControl(vec![CacheDirective::MaxAge(60 * 60 * 24 * 30)]),
}) })
} else { } else {