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