Skip to content

Commit 79ed8e8

Browse files
committed
refactored get_bucket_encryption
1 parent 26d67b8 commit 79ed8e8

25 files changed

+633
-351
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ jobs:
2020
- name: Build
2121
run: |
2222
cargo fmt --all -- --check
23-
cargo clippy --all-targets --all-features -- -A clippy::result_large_err -A clippy::type_complexity -A clippy::too_many_arguments
23+
cargo clippy --all-targets --all-features
2424
cargo build --bins --examples --tests --benches --verbose
2525
2626
- name: Run tests
2727
run: |
28-
truncate --size=6M asiaphotos-2015.zip
2928
./tests/start-server.sh
3029
export SERVER_ENDPOINT=localhost:9000
3130
export ACCESS_KEY=minioadmin

examples/common.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use minio::s3::args::{BucketExistsArgs, MakeBucketArgs};
2+
use minio::s3::creds::StaticProvider;
3+
use minio::s3::http::BaseUrl;
4+
use minio::s3::{Client, ClientBuilder};
5+
6+
#[allow(dead_code)]
7+
pub fn create_client_on_play() -> Result<Client, Box<dyn std::error::Error + Send + Sync>> {
8+
let base_url = "https://play.min.io".parse::<BaseUrl>()?;
9+
log::info!("Trying to connect to MinIO at: `{:?}`", base_url);
10+
11+
let static_provider = StaticProvider::new(
12+
"Q3AM3UQ867SPQQA43P2F",
13+
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
14+
None,
15+
);
16+
17+
let client = ClientBuilder::new(base_url.clone())
18+
.provider(Some(Box::new(static_provider)))
19+
.build()?;
20+
Ok(client)
21+
}
22+
23+
pub async fn create_bucket_if_not_exists(
24+
bucket_name: &str,
25+
client: &Client,
26+
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
27+
// Check 'bucket_name' bucket exist or not.
28+
let exists: bool = client
29+
.bucket_exists(&BucketExistsArgs::new(bucket_name).unwrap())
30+
.await
31+
.unwrap();
32+
33+
// Make 'bucket_name' bucket if not exist.
34+
if !exists {
35+
client
36+
.make_bucket(&MakeBucketArgs::new(bucket_name).unwrap())
37+
.await
38+
.unwrap();
39+
};
40+
Ok(())
41+
}
42+
43+
#[allow(dead_code)]
44+
#[tokio::main]
45+
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
46+
// dummy code just to prevent an error because files in examples need to have a main
47+
Ok(())
48+
}

examples/file_downloader.rs

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
use minio::s3::args::{BucketExistsArgs, MakeBucketArgs};
1+
// MinIO Rust Library for Amazon S3 Compatible Cloud Storage
2+
// Copyright 2025 MinIO, Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
mod common;
17+
18+
use crate::common::{create_bucket_if_not_exists, create_client_on_play};
219
use minio::s3::builders::ObjectContent;
3-
use minio::s3::client::ClientBuilder;
4-
use minio::s3::creds::StaticProvider;
5-
use minio::s3::http::BaseUrl;
620
use minio::s3::types::S3Api;
21+
use minio::s3::Client;
722
use std::path::Path;
823

924
#[tokio::main]
1025
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
1126
env_logger::init(); // Note: set environment variable RUST_LOG="INFO" to log info and higher
12-
13-
let base_url = "https://play.min.io".parse::<BaseUrl>()?;
14-
log::info!("Trying to connect to MinIO at: `{:?}`", base_url);
15-
16-
let static_provider = StaticProvider::new(
17-
"Q3AM3UQ867SPQQA43P2F",
18-
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
19-
None,
20-
);
21-
22-
let client = ClientBuilder::new(base_url.clone())
23-
.provider(Some(Box::new(static_provider)))
24-
.build()?;
27+
let client: Client = create_client_on_play()?;
2528

2629
let bucket_name: &str = "file-download-rust-bucket";
2730
let object_name: &str = "cat.png";
@@ -30,19 +33,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
3033
let filename: &Path = Path::new("./examples/cat.png");
3134
let download_path: &str = &format!("/tmp/downloads/{object_name}");
3235

33-
// Check 'bucket_name' bucket exist or not.
34-
let exists: bool = client
35-
.bucket_exists(&BucketExistsArgs::new(bucket_name).unwrap())
36-
.await
37-
.unwrap();
38-
39-
// Make 'bucket_name' bucket if not exist.
40-
if !exists {
41-
client
42-
.make_bucket(&MakeBucketArgs::new(bucket_name).unwrap())
43-
.await
44-
.unwrap();
45-
}
36+
create_bucket_if_not_exists(bucket_name, &client).await?;
4637

4738
if filename.exists() {
4839
log::info!("File '{}' exists.", &filename.to_str().unwrap());
@@ -64,10 +55,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
6455

6556
let get_object = client.get_object(bucket_name, object_name).send().await?;
6657

67-
get_object
68-
.content
69-
.to_file(&Path::new(download_path))
70-
.await?;
58+
get_object.content.to_file(Path::new(download_path)).await?;
7159

7260
log::info!("Object '{object_name}' is successfully downloaded to file '{download_path}'.");
7361

examples/file_uploader.rs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,20 @@
1212
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15+
mod common;
1516

16-
use minio::s3::args::{BucketExistsArgs, MakeBucketArgs};
17+
use crate::common::{create_bucket_if_not_exists, create_client_on_play};
1718
use minio::s3::builders::ObjectContent;
18-
use minio::s3::client::ClientBuilder;
19-
use minio::s3::creds::StaticProvider;
20-
use minio::s3::http::BaseUrl;
19+
use minio::s3::Client;
2120
use std::path::Path;
2221

2322
#[tokio::main]
2423
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2524
env_logger::init(); // Note: set environment variable RUST_LOG="INFO" to log info and higher
26-
27-
let base_url = "https://play.min.io".parse::<BaseUrl>()?;
28-
log::info!("Trying to connect to MinIO at: `{:?}`", base_url);
29-
30-
let static_provider = StaticProvider::new(
31-
"Q3AM3UQ867SPQQA43P2F",
32-
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
33-
None,
34-
);
35-
36-
let client = ClientBuilder::new(base_url.clone())
37-
.provider(Some(Box::new(static_provider)))
38-
.build()?;
25+
let client: Client = create_client_on_play()?;
3926

4027
let bucket_name: &str = "file-upload-rust-bucket";
41-
42-
// Check 'bucket_name' bucket exist or not.
43-
let exists: bool = client
44-
.bucket_exists(&BucketExistsArgs::new(bucket_name).unwrap())
45-
.await
46-
.unwrap();
47-
48-
// Make 'bucket_name' bucket if not exist.
49-
if !exists {
50-
client
51-
.make_bucket(&MakeBucketArgs::new(bucket_name).unwrap())
52-
.await
53-
.unwrap();
54-
}
28+
create_bucket_if_not_exists(bucket_name, &client).await?;
5529

5630
// File we are going to upload to the bucket
5731
let filename: &Path = Path::new("./examples/cat.png");

examples/get_bucket_encryption.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// MinIO Rust Library for Amazon S3 Compatible Cloud Storage
2+
// Copyright 2025 MinIO, Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
use crate::common::{create_bucket_if_not_exists, create_client_on_play};
17+
use minio::s3::builders::GetBucketEncryption;
18+
use minio::s3::Client;
19+
20+
mod common;
21+
22+
#[tokio::main]
23+
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
24+
env_logger::init(); // Note: set environment variable RUST_LOG="INFO" to log info and higher
25+
let client: Client = create_client_on_play()?;
26+
27+
let bucket_name: &str = "encryption-rust-bucket";
28+
create_bucket_if_not_exists(bucket_name, &client).await?;
29+
30+
let be: GetBucketEncryption = client.get_bucket_encryption(bucket_name)?;
31+
32+
log::info!("{:?}", be);
33+
34+
Ok(())
35+
}

examples/get_bucket_versioning.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// MinIO Rust Library for Amazon S3 Compatible Cloud Storage
2+
// Copyright 2025 MinIO, Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
mod common;
17+
18+
use crate::common::{create_bucket_if_not_exists, create_client_on_play};
19+
use minio::s3::builders::GetBucketVersioning;
20+
use minio::s3::Client;
21+
22+
#[tokio::main]
23+
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
24+
env_logger::init(); // Note: set environment variable RUST_LOG="INFO" to log info and higher
25+
let client: Client = create_client_on_play()?;
26+
27+
let bucket_name: &str = "versioning-rust-bucket";
28+
create_bucket_if_not_exists(bucket_name, &client).await?;
29+
30+
let bv: GetBucketVersioning = client.get_bucket_versioning(bucket_name)?;
31+
32+
log::info!("{:?}", bv);
33+
34+
Ok(())
35+
}

examples/object_prompt.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
use minio::s3::args::{BucketExistsArgs, MakeBucketArgs};
16+
mod common;
17+
18+
use crate::common::create_bucket_if_not_exists;
1719
use minio::s3::builders::{ObjectContent, ObjectPrompt};
1820
use minio::s3::client::ClientBuilder;
1921
use minio::s3::creds::StaticProvider;
@@ -25,35 +27,19 @@ use std::path::Path;
2527
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2628
env_logger::init(); // Note: set environment variable RUST_LOG="INFO" to log info and higher
2729

28-
let base_url = "https://play.min.io".parse::<BaseUrl>()?;
30+
//Note: object prompt is not supported on play.min.io, you will need point to AIStor
31+
let base_url = "http://localhost:9000".parse::<BaseUrl>()?;
2932
log::info!("Trying to connect to MinIO at: `{:?}`", base_url);
3033

31-
let static_provider = StaticProvider::new(
32-
"Q3AM3UQ867SPQQA43P2F",
33-
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
34-
None,
35-
);
34+
let static_provider = StaticProvider::new("admin", "admin", None);
3635

3736
let client = ClientBuilder::new(base_url.clone())
3837
.provider(Some(Box::new(static_provider)))
3938
.ignore_cert_check(Some(true))
4039
.build()?;
4140

4241
let bucket_name: &str = "object-prompt-rust-bucket";
43-
44-
// Check 'bucket_name' bucket exist or not.
45-
let exists: bool = client
46-
.bucket_exists(&BucketExistsArgs::new(bucket_name).unwrap())
47-
.await
48-
.unwrap();
49-
50-
// Make 'bucket_name' bucket if not exist.
51-
if !exists {
52-
client
53-
.make_bucket(&MakeBucketArgs::new(bucket_name).unwrap())
54-
.await
55-
.unwrap();
56-
}
42+
create_bucket_if_not_exists(bucket_name, &client).await?;
5743

5844
// File we are going to upload to the bucket
5945
let filename: &Path = Path::new("./examples/cat.png");

src/s3/args.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,9 +1318,6 @@ impl<'a> ComposeObjectArgs<'a> {
13181318
/// Argument for [delete_bucket_encryption()](crate::s3::client::Client::delete_bucket_encryption) API
13191319
pub type DeleteBucketEncryptionArgs<'a> = BucketArgs<'a>;
13201320

1321-
/// Argument for [get_bucket_encryption()](crate::s3::client::Client::get_bucket_encryption) API
1322-
pub type GetBucketEncryptionArgs<'a> = BucketArgs<'a>;
1323-
13241321
#[derive(Clone, Debug)]
13251322
/// Argument for [set_bucket_encryption()](crate::s3::client::Client::set_bucket_encryption) API
13261323
pub struct SetBucketEncryptionArgs<'a> {

src/s3/builders.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@
1515

1616
//! Argument builders for [minio::s3::client::Client](crate::s3::client::Client) APIs
1717
18-
mod buckets;
18+
mod bucket_common;
19+
mod get_bucket_encryption;
20+
mod get_bucket_versioning;
1921
mod get_object;
22+
mod list_buckets;
2023
mod list_objects;
2124
mod listen_bucket_notification;
2225
mod object_content;
2326
mod object_prompt;
2427
mod put_object;
2528
mod remove_objects;
2629

27-
pub use buckets::*;
30+
pub use bucket_common::*;
31+
pub use get_bucket_encryption::*;
32+
pub use get_bucket_versioning::*;
2833
pub use get_object::*;
34+
pub use list_buckets::*;
2935
pub use list_objects::*;
3036
pub use listen_bucket_notification::*;
3137
pub use object_content::*;

0 commit comments

Comments
 (0)