xt_oss/oss/api/objects/
acl.rs1use crate::oss;
2use builders::{GetObjectAclBuilder, PutObjectACLBuilder};
3
4pub mod builders {
5 use crate::oss::{
6 self,
7 api::{self, ApiResponseFrom},
8 entities::{acl::AccessControlPolicy, ObjectACL},
9 http,
10 };
11
12 pub struct PutObjectACLBuilder<'a> {
13 client: &'a oss::Client<'a>,
14 object: &'a str,
15 version_id: Option<&'a str>,
16 acl: ObjectACL,
17 }
18
19 #[allow(unused)]
20 impl<'a> PutObjectACLBuilder<'a> {
21 pub(crate) fn new(client: &'a oss::Client, object: &'a str) -> Self {
22 Self {
23 client,
24 object,
25 version_id: None,
26 acl: ObjectACL::Default,
27 }
28 }
29
30 pub fn with_acl(mut self, acl: ObjectACL) -> Self {
31 self.acl = acl;
32 self
33 }
34
35 pub fn with_version_id(mut self, value: &'a str) -> Self {
36 self.version_id = Some(value);
37 self
38 }
39
40 pub async fn execute(&self) -> api::ApiResult {
41 let mut res = format!("/{}/{}?{}", self.client.bucket(), self.object, "acl");
42 let mut url = { format!("{}?{}", self.client.object_url(self.object), "acl") };
43 if let Some(version_id) = self.version_id {
44 res = format!("{}&versionId={}", res, version_id);
45 url = format!("{}&versionId={}", url, version_id);
46 }
47
48 let mut headers = http::HeaderMap::new();
49 headers.insert("x-oss-object-acl", self.acl.to_string().parse().unwrap());
50
51 let resp = self
52 .client
53 .request
54 .task()
55 .with_url(&url)
56 .with_method(http::Method::PUT)
57 .with_headers(headers)
58 .with_resource(&res)
59 .execute()
60 .await?;
61 Ok(ApiResponseFrom(resp).to_empty().await)
62 }
63 }
64
65 pub struct GetObjectAclBuilder<'a> {
66 client: &'a oss::Client<'a>,
67 object: &'a str,
68 version_id: Option<&'a str>,
69 }
70
71 impl<'a> GetObjectAclBuilder<'a> {
72 pub(crate) fn new(client: &'a oss::Client, object: &'a str) -> Self {
73 Self {
74 client,
75 object,
76 version_id: None,
77 }
78 }
79
80 pub fn with_version_id(mut self, value: &'a str) -> Self {
81 self.version_id = Some(value);
82 self
83 }
84
85 pub async fn execute(&self) -> api::ApiResult<AccessControlPolicy> {
86 let mut res = format!("/{}/{}?{}", self.client.bucket(), self.object, "acl");
87 let mut url = { format!("{}?{}", self.client.object_url(self.object), "acl") };
88 if let Some(version_id) = self.version_id {
89 res = format!("{}&versionId={}", res, version_id);
90 url = format!("{}&versionId={}", url, version_id);
91 }
92
93 let resp = self
94 .client
95 .request
96 .task()
97 .with_url(&url)
98 .with_resource(&res)
99 .execute()
100 .await?;
101 Ok(ApiResponseFrom(resp).to_type().await)
102 }
103 }
104}
105
106#[allow(non_snake_case)]
108impl<'a> oss::Client<'a> {
109 pub fn PutObjectACL(&self, object: &'a str) -> PutObjectACLBuilder {
115 PutObjectACLBuilder::new(self, object)
116 }
117
118 pub fn GetObjectACL(&self, object: &'a str) -> GetObjectAclBuilder {
123 GetObjectAclBuilder::new(self, object)
124 }
125}