xt_oss/oss/api/bucket/
lifecycle.rs1use crate::oss;
2
3use self::builders::{
4 DeleteBucketLifecycleBuilder, GetBucketLifecycleBuilder, PutBucketLifecycleBuilder,
5};
6
7pub mod builders {
8
9 use crate::oss::{
10 self,
11 api::{self, ApiResponseFrom},
12 entities::lifecycle::LifecycleConfiguration,
13 http,
14 };
15
16 pub struct PutBucketLifecycleBuilder<'a> {
17 client: &'a oss::Client<'a>,
18 config: LifecycleConfiguration,
19 }
20
21 impl<'a> PutBucketLifecycleBuilder<'a> {
22 pub(crate) fn new(client: &'a oss::Client) -> Self {
23 Self {
24 client,
25 config: LifecycleConfiguration::default(),
26 }
27 }
28
29 pub fn with_config(mut self, value: LifecycleConfiguration) -> Self {
30 self.config = value;
31 self
32 }
33
34 pub async fn execute(&self) -> api::ApiResult {
35 let res = format!("/{}/?{}", self.client.bucket(), "lifecycle");
36 let url = format!("{}/?{}", self.client.base_url(), "lifecycle");
37
38 let config = quick_xml::se::to_string(&self.config).unwrap();
39 let data = oss::Bytes::from(config);
40
41 let resp = self
42 .client
43 .request
44 .task()
45 .with_url(&url)
46 .with_method(http::Method::PUT)
47 .with_resource(&res)
48 .with_body(data)
49 .execute()
50 .await?;
51 Ok(ApiResponseFrom(resp).to_empty().await)
52 }
53 }
54
55 pub struct GetBucketLifecycleBuilder<'a> {
56 client: &'a oss::Client<'a>,
57 }
58
59 impl<'a> GetBucketLifecycleBuilder<'a> {
60 pub(crate) fn new(client: &'a oss::Client) -> Self {
61 Self { client }
62 }
63
64 pub async fn execute(&self) -> api::ApiResult<LifecycleConfiguration> {
65 let res = format!("/{}/?{}", self.client.bucket(), "lifecycle");
66 let url = format!("{}/?{}", self.client.base_url(), "lifecycle");
67
68 let resp = self
69 .client
70 .request
71 .task()
72 .with_url(&url)
73 .with_resource(&res)
74 .execute()
75 .await?;
76 Ok(ApiResponseFrom(resp).to_type().await)
77 }
78 }
79
80 pub struct DeleteBucketLifecycleBuilder<'a> {
81 client: &'a oss::Client<'a>,
82 }
83
84 impl<'a> DeleteBucketLifecycleBuilder<'a> {
85 pub(crate) fn new(client: &'a oss::Client) -> Self {
86 Self { client }
87 }
88
89 pub async fn execute(&self) -> api::ApiResult {
90 let res = format!("/{}/?{}", self.client.bucket(), "lifecycle");
91 let url = format!("{}/?{}", self.client.base_url(), "lifecycle");
92
93 let resp = self
94 .client
95 .request
96 .task()
97 .with_url(&url)
98 .with_resource(&res)
99 .with_method(http::Method::DELETE)
100 .execute()
101 .await?;
102
103 Ok(ApiResponseFrom(resp).to_empty().await)
104 }
105 }
106}
107
108#[allow(non_snake_case)]
110impl<'a> oss::Client<'a> {
111 pub fn PutBucketLifecycle(&self) -> PutBucketLifecycleBuilder {
120 PutBucketLifecycleBuilder::new(&self)
121 }
122
123 #[allow(non_snake_case)]
128 pub fn GetBucketLifecycle(&self) -> GetBucketLifecycleBuilder {
129 GetBucketLifecycleBuilder::new(&self)
130 }
131
132 pub fn DeleteBucketLifecycle(&self) -> DeleteBucketLifecycleBuilder {
140 DeleteBucketLifecycleBuilder::new(&self)
141 }
142}