aliyun_oss_rs/bucket/
get_bucket_policy.rs

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