fix deprecated lifetime; update example file-uploader (#71)

* fix: deprecated elided_lifetimes_in_associated_constant

* fix warnings

* update: example file-file-uploader
This commit is contained in:
Henk-Jan Lebbink 2024-03-15 17:24:44 +01:00 committed by GitHub
parent 8fb211ae0e
commit 75ea23aaf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 51 additions and 29 deletions

View File

@ -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"
@ -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"

View File

@ -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<dyn std::error::Error + Send + Sync>> {
let base_url = "https://play.min.io".parse::<BaseUrl>()?;
env_logger::init(); // Note: set environment variable RUST_LOG="INFO" to log info and higher
//let base_url = "https://play.min.io".parse::<BaseUrl>()?;
let base_url: BaseUrl = "http://192.168.178.227:9000".parse::<BaseUrl>()?;
info!("Trying to connect to MinIO at: `{:?}`", base_url);
let static_provider = StaticProvider::new(
"Q3AM3UQ867SPQQA43P2F",
@ -21,15 +28,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
)
.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<dyn std::error::Error + Send + Sync>> {
.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",
)
&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(())
}

View File

@ -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;

View File

@ -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
///

View File

@ -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<ComposeSource<'_>>,
sources: &'a mut [ComposeSource<'_>],
) -> Result<u16, Error> {
let mut object_size = 0_usize;
let mut i = 0;

View File

@ -117,7 +117,7 @@ impl Client {
continue;
}
let records_res: Result<NotificationRecords, Error> =
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)),

View File

@ -418,7 +418,6 @@ impl BaseUrl {
port: self.port,
path: String::from("/"),
query: query.clone(),
..Default::default()
};
if bucket_name.is_none() {

View File

@ -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)]

View File

@ -1,5 +1,7 @@
#!/bin/bash
#Note start this script from minio-rs, not from directory tests
set -x
set -e

View File

@ -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,