aliyun_oss_rs/bucket/
get_bucket_encryption.rs

1use crate::{
2    Error,
3    common::body_to_bytes,
4    error::normal_error,
5    request::{Oss, OssRequest},
6};
7use http::Method;
8
9use super::BucketEncryption;
10
11/// Retrieve the default server-side encryption configuration for the bucket.
12///
13/// See the [Alibaba Cloud documentation](https://help.aliyun.com/zh/oss/developer-reference/getbucketencryption) for details.
14pub struct GetBucketEncryption {
15    req: OssRequest,
16}
17
18impl GetBucketEncryption {
19    pub(super) fn new(oss: Oss) -> Self {
20        let mut req = OssRequest::new(oss, Method::GET);
21        req.insert_query("encryption", "");
22        GetBucketEncryption { req }
23    }
24
25    /// Send the request and return the parsed configuration.
26    pub async fn send(self) -> Result<BucketEncryption, Error> {
27        let response = self.req.send_to_oss()?.await?;
28        match response.status() {
29            code if code.is_success() => {
30                let bytes = body_to_bytes(response.into_body()).await?;
31                let encryption: BucketEncryption = serde_xml_rs::from_reader(bytes.as_ref())
32                    .map_err(|_| Error::OssInvalidResponse(Some(bytes)))?;
33                Ok(encryption)
34            }
35            _ => Err(normal_error(response).await),
36        }
37    }
38}