aliyun_oss_rs/bucket/
extend_bucket_worm.rs

1use crate::{
2    Error,
3    error::normal_error,
4    request::{Oss, OssRequest},
5};
6use bytes::Bytes;
7use http::Method;
8use http_body_util::Full;
9
10/// Extend the retention period of an existing WORM configuration.
11///
12/// See the [Alibaba Cloud documentation](https://help.aliyun.com/zh/oss/developer-reference/extendbucketworm) for details.
13pub struct ExtendBucketWorm {
14    req: OssRequest,
15    retention_days: Option<u32>,
16}
17
18impl ExtendBucketWorm {
19    pub(super) fn new(oss: Oss, worm_id: impl ToString) -> Self {
20        let mut req = OssRequest::new(oss, Method::POST);
21        req.insert_query("wormId", worm_id.to_string());
22        req.insert_query("comp", "extend");
23        ExtendBucketWorm {
24            req,
25            retention_days: None,
26        }
27    }
28
29    /// Set the new retention period in days.
30    pub fn set_retention_days(mut self, days: u32) -> Self {
31        self.retention_days = Some(days);
32        self
33    }
34
35    /// Send the request.
36    pub async fn send(mut self) -> Result<(), Error> {
37        let days = self.retention_days.ok_or(Error::MissingRequestBody)?;
38        let body = format!(
39            "<ExtendWormConfiguration><RetentionPeriodInDays>{}</RetentionPeriodInDays></ExtendWormConfiguration>",
40            days
41        );
42        self.req.set_body(Full::new(Bytes::from(body)));
43        let response = self.req.send_to_oss()?.await?;
44        match response.status() {
45            code if code.is_success() => Ok(()),
46            _ => Err(normal_error(response).await),
47        }
48    }
49}