From 0c852d84da59da015192f4f0862b87ad3a8b211a Mon Sep 17 00:00:00 2001 From: Henk-Jan Lebbink Date: Tue, 27 Feb 2024 13:55:11 +0100 Subject: [PATCH 1/3] fix: deprecated elided_lifetimes_in_associated_constant --- src/s3/args.rs | 6 +++--- src/s3/types.rs | 4 ++-- tests/tests.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/s3/args.rs b/src/s3/args.rs index f9640afa..c786d998 100644 --- a/src/s3/args.rs +++ b/src/s3/args.rs @@ -2333,9 +2333,9 @@ pub struct PostPolicy<'a> { } impl<'a> PostPolicy<'a> { - const EQ: &str = "eq"; - const STARTS_WITH: &str = "starts-with"; - const ALGORITHM: &str = "AWS4-HMAC-SHA256"; + const EQ: &'static str = "eq"; + const STARTS_WITH: &'static str = "starts-with"; + const ALGORITHM: &'static str = "AWS4-HMAC-SHA256"; /// Returns post policy with given bucket name and expiration /// diff --git a/src/s3/types.rs b/src/s3/types.rs index 7b5e2f53..ada3371c 100644 --- a/src/s3/types.rs +++ b/src/s3/types.rs @@ -1198,7 +1198,7 @@ pub struct PrefixFilterRule { } impl PrefixFilterRule { - pub const NAME: &str = "prefix"; + pub const NAME: &'static str = "prefix"; } #[derive(Clone, Debug)] @@ -1208,7 +1208,7 @@ pub struct SuffixFilterRule { } impl SuffixFilterRule { - pub const NAME: &str = "suffix"; + pub const NAME: &'static str = "suffix"; } #[derive(Clone, Debug)] diff --git a/tests/tests.rs b/tests/tests.rs index 01f1d132..7c63ea4a 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -86,7 +86,7 @@ struct ClientTest { } impl ClientTest { - const SQS_ARN: &str = "arn:minio:sqs::miniojavatest:webhook"; + const SQS_ARN: &'static str = "arn:minio:sqs::miniojavatest:webhook"; fn new( base_url: BaseUrl, From cfdf41c7d8fb4bf681884544c111317840f3eba7 Mon Sep 17 00:00:00 2001 From: Henk-Jan Lebbink Date: Tue, 27 Feb 2024 14:02:36 +0100 Subject: [PATCH 2/3] fix warnings --- Cargo.toml | 2 +- src/lib.rs | 3 +++ src/s3/client.rs | 7 +------ src/s3/client/listen_bucket_notification.rs | 2 +- src/s3/http.rs | 3 +-- tests/start-server.sh | 2 ++ 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68c2de9a..617a2a33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ http = "0.2.9" hyper = { version = "0.14.27", features = ["full"] } lazy_static = "1.4.0" md5 = "0.7.0" -multimap = "0.9.0" +multimap = "0.10.0" os_info = "3.7.0" rand = "0.8.5" regex = "1.9.4" diff --git a/src/lib.rs b/src/lib.rs index b0e6bae9..bafe378c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,4 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![allow(clippy::tabs_in_doc_comments)] +#![allow(clippy::result_large_err)] +#![allow(clippy::too_many_arguments)] pub mod s3; diff --git a/src/s3/client.rs b/src/s3/client.rs index 46d5c30d..8b87ac3b 100644 --- a/src/s3/client.rs +++ b/src/s3/client.rs @@ -35,12 +35,10 @@ use async_recursion::async_recursion; use bytes::{Buf, Bytes}; use dashmap::DashMap; use hyper::http::Method; -use os_info; use reqwest::header::HeaderMap; use std::collections::HashMap; use std::fs::File; use std::io::prelude::*; -use std::io::Read; use std::path::{Path, PathBuf}; use std::sync::Arc; use xmltree::Element; @@ -48,9 +46,6 @@ use xmltree::Element; mod list_objects; mod listen_bucket_notification; -pub use list_objects::*; -pub use listen_bucket_notification::*; - /// Client Builder manufactures a Client using given parameters. #[derive(Debug, Default)] pub struct ClientBuilder { @@ -706,7 +701,7 @@ impl Client { async fn calculate_part_count<'a>( &self, - sources: &'a mut Vec>, + sources: &'a mut [ComposeSource<'_>], ) -> Result { let mut object_size = 0_usize; let mut i = 0; diff --git a/src/s3/client/listen_bucket_notification.rs b/src/s3/client/listen_bucket_notification.rs index 881cd68a..e58c800b 100644 --- a/src/s3/client/listen_bucket_notification.rs +++ b/src/s3/client/listen_bucket_notification.rs @@ -117,7 +117,7 @@ impl Client { continue; } let records_res: Result = - serde_json::from_str(&s).map_err(|e| e.into()); + serde_json::from_str(s).map_err(|e| e.into()); return Some((records_res, reader)); } Err(e) => return Some((Err(e.into()), reader)), diff --git a/src/s3/http.rs b/src/s3/http.rs index 008c9bfd..deb7b146 100644 --- a/src/s3/http.rs +++ b/src/s3/http.rs @@ -417,8 +417,7 @@ impl BaseUrl { host: self.host.clone(), port: self.port, path: String::from("/"), - query: query.clone(), - ..Default::default() + query: query.clone() }; if bucket_name.is_none() { diff --git a/tests/start-server.sh b/tests/start-server.sh index 0a3d3307..741747e8 100755 --- a/tests/start-server.sh +++ b/tests/start-server.sh @@ -1,5 +1,7 @@ #!/bin/bash +#Note start this script from minio-rs, not from directory tests + set -x set -e From 28da7b697df1d14028291517f901c86faaa753db Mon Sep 17 00:00:00 2001 From: Henk-Jan Lebbink Date: Tue, 27 Feb 2024 20:36:17 +0100 Subject: [PATCH 3/3] update: example file-file-uploader --- Cargo.toml | 3 +++ examples/file-uploader.rs | 48 +++++++++++++++++++++++++++------------ src/s3/http.rs | 2 +- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 617a2a33..0930f666 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,9 @@ tokio-stream = "0.1.14" tokio-util = { version = "0.7.8", features = ["io"] } urlencoding = "2.1.3" xmltree = "0.10.3" +log = "0.4.20" +env_logger = "0.11.2" +home = "0.5.9" [dependencies.reqwest] version = "0.11.20" diff --git a/examples/file-uploader.rs b/examples/file-uploader.rs index fe1b519d..8022b148 100644 --- a/examples/file-uploader.rs +++ b/examples/file-uploader.rs @@ -1,11 +1,18 @@ +use log::{error, info}; use minio::s3::args::{BucketExistsArgs, MakeBucketArgs, UploadObjectArgs}; use minio::s3::client::Client; use minio::s3::creds::StaticProvider; use minio::s3::http::BaseUrl; +use std::path::Path; #[tokio::main] async fn main() -> Result<(), Box> { - let base_url = "https://play.min.io".parse::()?; + env_logger::init(); // Note: set environment variable RUST_LOG="INFO" to log info and higher + + //let base_url = "https://play.min.io".parse::()?; + let base_url: BaseUrl = "http://192.168.178.227:9000".parse::()?; + + info!("Trying to connect to MinIO at: `{:?}`", base_url); let static_provider = StaticProvider::new( "Q3AM3UQ867SPQQA43P2F", @@ -21,15 +28,15 @@ async fn main() -> Result<(), Box> { ) .unwrap(); - let bucket_name = "asiatrip"; + let bucket_name: &str = "asiatrip"; - // Check 'asiatrip' bucket exist or not. - let exists = client + // Check 'bucket_name' bucket exist or not. + let exists: bool = client .bucket_exists(&BucketExistsArgs::new(&bucket_name).unwrap()) .await .unwrap(); - // Make 'asiatrip' bucket if not exist. + // Make 'bucket_name' bucket if not exist. if !exists { client .make_bucket(&MakeBucketArgs::new(&bucket_name).unwrap()) @@ -37,20 +44,33 @@ async fn main() -> Result<(), Box> { .unwrap(); } - // Upload '/home/user/Photos/asiaphotos.zip' as object name - // 'asiaphotos-2015.zip' to bucket 'asiatrip'. + // File we are going to upload to the bucket + let filename: &Path = Path::new("/home/user/Photos/asiaphotos.zip"); + + // Name of the object that will be stored in the bucket + let object_name: &str = "asiaphotos-2015.zip"; + + info!("filename {}", &filename.to_str().unwrap()); + + // Check if the file exists + let file_exists: bool = filename.exists(); + if !file_exists { + error!("File `{}` does not exist!", filename.display()); + () + } + + // Upload 'filename' as 'object_name' to bucket 'bucket_name'. client .upload_object( - &mut UploadObjectArgs::new( - &bucket_name, - "asiaphotos-2015.zip", - "/home/user/Photos/asiaphotos.zip", - ) - .unwrap(), + &mut UploadObjectArgs::new(&bucket_name, &object_name, &filename.to_str().unwrap()) + .unwrap(), ) .await .unwrap(); - println!("'/home/user/Photos/asiaphotos.zip' is successfully uploaded as object 'asiaphotos-2015.zip' to bucket 'asiatrip'."); + info!( + "file `{}` is successfully uploaded as object `{object_name}` to bucket `{bucket_name}`.", + filename.display() + ); Ok(()) } diff --git a/src/s3/http.rs b/src/s3/http.rs index deb7b146..9d5e0912 100644 --- a/src/s3/http.rs +++ b/src/s3/http.rs @@ -417,7 +417,7 @@ impl BaseUrl { host: self.host.clone(), port: self.port, path: String::from("/"), - query: query.clone() + query: query.clone(), }; if bucket_name.is_none() {