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