1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! `cargo run --example api_service_list_buckets -q`
//!
//! 调用ListBuckets(GetService)接口列举请求者拥有的所有存储空间(Bucket)。
//! 您还可以通过设置prefix、marker或者max-keys参数列举满足指定条件的存储空间。
//!
//! - [official docs](https://help.aliyun.com/zh/oss/developer-reference/listbuckets)
//! - [xtoss example](https://github.com/isme-sun/xt_oss/blob/main/examples/api_service_list_buckets.rs)
use dotenv;
use std::process;
use xt_oss::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv::dotenv().ok();
let options = util::options_from_env();
let client = oss::Client::new(options);
let result = client
.ListBuckets()
// .with_marker("marker")
// .with_max_keys(5)
.with_prefix("xtoss")
// .with_resource_group_id("group_id")
.execute()
.await
.unwrap_or_else(|error| {
println!("reqwest error: {}", error);
process::exit(-1);
});
match result {
Ok(data) => {
let all_buckets = data.content();
// println!("{:#?}", all_buckets);
if let Some(buckets) = &all_buckets.buckets.bucket {
for bucket in buckets {
println!("{}", bucket.name);
println!("{}", "-".repeat(42));
println!(" - storage_class: {}", bucket.storage_class);
println!(" - creation_date: {}", bucket.creation_date);
println!(" - location: {}", bucket.location);
println!(" - comment: {}",
bucket.comment.as_deref().unwrap_or_default()
);
println!()
}
} else {
// println!("{:#?}", all_buckets);
println!("no buckets");
}
}
Err(message) => println!("oss error: {}", message.content()),
}
Ok(())
}