mirror of
https://github.com/minio/minio-rs.git
synced 2025-12-06 15:26:51 +08:00
* updated inline doc * updated inline doc * API naming conform AWS * fixed clippy issues * fixed minor API naming issues
57 lines
1.8 KiB
Rust
57 lines
1.8 KiB
Rust
use minio::s3::creds::StaticProvider;
|
|
use minio::s3::http::BaseUrl;
|
|
use minio::s3::response::BucketExistsResponse;
|
|
use minio::s3::types::S3Api;
|
|
use minio::s3::{Client, ClientBuilder};
|
|
|
|
#[allow(dead_code)]
|
|
pub fn create_client_on_play() -> Result<Client, Box<dyn std::error::Error + Send + Sync>> {
|
|
let base_url = "https://play.min.io".parse::<BaseUrl>()?;
|
|
log::info!("Trying to connect to MinIO at: `{:?}`", base_url);
|
|
|
|
let static_provider = StaticProvider::new(
|
|
"Q3AM3UQ867SPQQA43P2F",
|
|
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
|
|
None,
|
|
);
|
|
|
|
let client = ClientBuilder::new(base_url.clone())
|
|
.provider(Some(Box::new(static_provider)))
|
|
.build()?;
|
|
Ok(client)
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn create_client_on_localhost() -> Result<Client, Box<dyn std::error::Error + Send + Sync>> {
|
|
let base_url = "http://localhost:9000/".parse::<BaseUrl>()?;
|
|
log::info!("Trying to connect to MinIO at: `{:?}`", base_url);
|
|
|
|
let static_provider = StaticProvider::new("minioadmin", "minioadmin", None);
|
|
|
|
let client = ClientBuilder::new(base_url.clone())
|
|
.provider(Some(Box::new(static_provider)))
|
|
.build()?;
|
|
Ok(client)
|
|
}
|
|
|
|
pub async fn create_bucket_if_not_exists(
|
|
bucket_name: &str,
|
|
client: &Client,
|
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
// Check 'bucket_name' bucket exist or not.
|
|
let resp: BucketExistsResponse = client.bucket_exists(bucket_name).send().await?;
|
|
|
|
// Make 'bucket_name' bucket if not exist.
|
|
if !resp.exists {
|
|
client.create_bucket(bucket_name).send().await.unwrap();
|
|
};
|
|
Ok(())
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
// dummy code just to prevent an error because files in examples need to have a main
|
|
Ok(())
|
|
}
|