Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deprecated lifetime; update example file-uploader #71

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
48 changes: 34 additions & 14 deletions examples/file-uploader.rs
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -21,36 +28,49 @@ 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())
.await
.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(())
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 3 additions & 3 deletions src/s3/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
7 changes: 1 addition & 6 deletions src/s3/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,17 @@ 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;

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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/s3/client/listen_bucket_notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
1 change: 0 additions & 1 deletion src/s3/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ impl BaseUrl {
port: self.port,
path: String::from("/"),
query: query.clone(),
..Default::default()
};

if bucket_name.is_none() {
Expand Down
4 changes: 2 additions & 2 deletions src/s3/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ pub struct PrefixFilterRule {
}

impl PrefixFilterRule {
pub const NAME: &str = "prefix";
pub const NAME: &'static str = "prefix";
}

#[derive(Clone, Debug)]
Expand All @@ -1208,7 +1208,7 @@ pub struct SuffixFilterRule {
}

impl SuffixFilterRule {
pub const NAME: &str = "suffix";
pub const NAME: &'static str = "suffix";
}

#[derive(Clone, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions tests/start-server.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

#Note start this script from minio-rs, not from directory tests

set -x
set -e

Expand Down
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down