xt_oss/oss/api/bucket/
acl.rs1use crate::oss::{
2 self,
3 api::{self, insert_custom_header, ApiResponseFrom},
4 entities::{acl::AccessControlPolicy, OssAcl},
5 http,
6};
7
8#[derive(Debug)]
9pub struct PutBucketAclBuilder<'a> {
10 client: &'a oss::Client<'a>,
11 acl: OssAcl,
12}
13
14#[allow(unused)]
15impl<'a> PutBucketAclBuilder<'a> {
16 pub fn new(client: &'a oss::Client, acl: OssAcl) -> Self {
17 Self { client, acl }
18 }
19
20 pub async fn execute(&self) -> api::ApiResult<()> {
21 let res = format!("/{}/?{}", self.client.bucket(), "acl");
22 let url = { format!("{}/?{}", self.client.base_url(), "acl") };
23
24 let mut headers = http::HeaderMap::new();
25 insert_custom_header(&mut headers, "x-oss-acl", self.acl.to_string());
26
27 let resp = self
28 .client
29 .request
30 .task()
31 .with_url(&url)
32 .with_method(http::Method::PUT)
33 .with_headers(headers)
34 .with_resource(&res)
35 .execute_timeout(self.client.timeout())
36 .await?;
37
38 Ok(ApiResponseFrom(resp).to_empty().await)
39 }
40}
41
42pub struct GetBucketAclBuilder<'a> {
43 client: &'a oss::Client<'a>,
44}
45
46impl<'a> GetBucketAclBuilder<'a> {
47 pub(crate) fn new(client: &'a oss::Client) -> Self {
48 Self { client }
49 }
50
51 pub async fn execute(&self) -> api::ApiResult<AccessControlPolicy> {
52 let res = format!("/{}/?{}", self.client.bucket(), "acl");
53 let url = format!("{}/?{}", self.client.base_url(), "acl");
54
55 let resp = self
56 .client
57 .request
58 .task()
59 .with_url(&url)
60 .with_resource(&res)
61 .execute_timeout(self.client.timeout())
62 .await?;
63 Ok(ApiResponseFrom(resp).to_type().await)
64 }
65}
66
67#[allow(non_snake_case)]
69impl<'a> oss::Client<'a> {
70 pub fn PutBucketAcl(&self, acl: OssAcl) -> PutBucketAclBuilder {
75 PutBucketAclBuilder::new(self, acl)
76 }
77
78 pub fn GetBucketAcl(&self) -> GetBucketAclBuilder {
84 GetBucketAclBuilder::new(&self)
85 }
86}