cloud_storage/sync/default_object_access_control.rs
1use crate::{
2 bucket_access_control::Entity,
3 default_object_access_control::{DefaultObjectAccessControl, NewDefaultObjectAccessControl},
4};
5
6/// Operations on [`DefaultObjectAccessControl`](DefaultObjectAccessControl)s.
7#[derive(Debug)]
8pub struct DefaultObjectAccessControlClient<'a>(pub(super) &'a super::Client);
9
10impl<'a> DefaultObjectAccessControlClient<'a> {
11 /// Create a new `DefaultObjectAccessControl` entry on the specified bucket.
12 /// ### Important
13 /// Important: This method fails with a `400 Bad Request` response for buckets with uniform
14 /// bucket-level access enabled. Use `Bucket::get_iam_policy` and `Bucket::set_iam_policy` to
15 /// control access instead.
16 /// ### Example
17 /// ```no_run
18 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
19 /// use cloud_storage::sync::Client;
20 /// use cloud_storage::default_object_access_control::{
21 /// DefaultObjectAccessControl, NewDefaultObjectAccessControl, Role, Entity,
22 /// };
23 ///
24 /// let client = Client::new()?;
25 /// let new_acl = NewDefaultObjectAccessControl {
26 /// entity: Entity::AllAuthenticatedUsers,
27 /// role: Role::Reader,
28 /// };
29 /// let default_acl = client.default_object_access_control().create("mybucket", &new_acl)?;
30 /// # client.default_object_access_control().delete(default_acl)?;
31 /// # Ok(())
32 /// # }
33 /// ```
34 pub fn create(
35 &self,
36 bucket: &str,
37 new_acl: &NewDefaultObjectAccessControl,
38 ) -> crate::Result<DefaultObjectAccessControl> {
39 self.0.runtime.block_on(
40 self.0
41 .client
42 .default_object_access_control()
43 .create(bucket, new_acl),
44 )
45 }
46
47 /// Retrieves default object ACL entries on the specified bucket.
48 /// ### Important
49 /// Important: This method fails with a `400 Bad Request` response for buckets with uniform
50 /// bucket-level access enabled. Use `Bucket::get_iam_policy` and `Bucket::set_iam_policy` to
51 /// control access instead.
52 /// ### Example
53 /// ```no_run
54 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
55 /// use cloud_storage::sync::Client;
56 /// use cloud_storage::default_object_access_control::DefaultObjectAccessControl;
57 ///
58 /// let client = Client::new()?;
59 /// let default_acls = client.default_object_access_control().list("mybucket")?;
60 /// # Ok(())
61 /// # }
62 /// ```
63 pub fn list(&self, bucket: &str) -> crate::Result<Vec<DefaultObjectAccessControl>> {
64 self.0
65 .runtime
66 .block_on(self.0.client.default_object_access_control().list(bucket))
67 }
68
69 /// Read a single `DefaultObjectAccessControl`.
70 /// The `bucket` argument is the name of the bucket whose `DefaultObjectAccessControl` is to be
71 /// read, and the `entity` argument is the entity holding the permission. Options are
72 /// Can be "user-`userId`", "user-`email_address`", "group-`group_id`", "group-`email_address`",
73 /// "allUsers", or "allAuthenticatedUsers".
74 /// ### Important
75 /// Important: This method fails with a `400 Bad Request` response for buckets with uniform
76 /// bucket-level access enabled. Use `Bucket::get_iam_policy` and `Bucket::set_iam_policy` to
77 /// control access instead.
78 /// ### Example
79 /// ```no_run
80 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
81 /// use cloud_storage::sync::Client;
82 /// use cloud_storage::default_object_access_control::{DefaultObjectAccessControl, Entity};
83 ///
84 /// let client = Client::new()?;
85 /// let default_acl = client.default_object_access_control().read("mybucket", &Entity::AllUsers)?;
86 /// # Ok(())
87 /// # }
88 /// ```
89 pub fn read(&self, bucket: &str, entity: &Entity) -> crate::Result<DefaultObjectAccessControl> {
90 self.0.runtime.block_on(
91 self.0
92 .client
93 .default_object_access_control()
94 .read(bucket, entity),
95 )
96 }
97
98 /// Update the current `DefaultObjectAccessControl`.
99 /// ### Important
100 /// Important: This method fails with a `400 Bad Request` response for buckets with uniform
101 /// bucket-level access enabled. Use `Bucket::get_iam_policy` and `Bucket::set_iam_policy` to
102 /// control access instead.
103 /// ### Example
104 /// ```no_run
105 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
106 /// use cloud_storage::sync::Client;
107 /// use cloud_storage::default_object_access_control::{DefaultObjectAccessControl, Entity};
108 ///
109 /// let client = Client::new()?;
110 /// let mut default_acl = client.default_object_access_control().read("my_bucket", &Entity::AllUsers)?;
111 /// default_acl.entity = Entity::AllAuthenticatedUsers;
112 /// client.default_object_access_control().update(&default_acl)?;
113 /// # Ok(())
114 /// # }
115 /// ```
116 pub fn update(
117 &self,
118 default_object_access_control: &DefaultObjectAccessControl,
119 ) -> crate::Result<DefaultObjectAccessControl> {
120 self.0.runtime.block_on(
121 self.0
122 .client
123 .default_object_access_control()
124 .update(default_object_access_control),
125 )
126 }
127
128 /// Delete this 'DefaultObjectAccessControl`.
129 /// ### Important
130 /// Important: This method fails with a `400 Bad Request` response for buckets with uniform
131 /// bucket-level access enabled. Use `Bucket::get_iam_policy` and `Bucket::set_iam_policy` to
132 /// control access instead.
133 /// ### Example
134 /// ```no_run
135 /// # fn main() -> Result<(), Box<dyn std::error::Error>> {
136 /// use cloud_storage::sync::Client;
137 /// use cloud_storage::default_object_access_control::{DefaultObjectAccessControl, Entity};
138 ///
139 /// let client = Client::new()?;
140 /// let mut default_acl = client.default_object_access_control().read("my_bucket", &Entity::AllUsers)?;
141 /// client.default_object_access_control().delete(default_acl)?;
142 /// # Ok(())
143 /// # }
144 /// ```
145 pub fn delete(
146 &self,
147 default_object_access_control: DefaultObjectAccessControl,
148 ) -> Result<(), crate::Error> {
149 self.0.runtime.block_on(
150 self.0
151 .client
152 .default_object_access_control()
153 .delete(default_object_access_control),
154 )
155 }
156}