Skip to content

Commit

Permalink
Support custom ACL policies, closes durch#317
Browse files Browse the repository at this point in the history
  • Loading branch information
durch committed Apr 11, 2023
1 parent 92d86bf commit bea733a
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions s3/src/bucket_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use crate::{Bucket, Region};
/// [AWS Documentation](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#CannedACL)
#[allow(dead_code)]
#[derive(Clone, Debug)]
enum CannedBucketAcl {
pub enum CannedBucketAcl {
Private,
PublicRead,
PublicReadWrite,
AuthenticatedRead,
Custom(String),
}

use http::header::HeaderName;
Expand All @@ -22,14 +23,15 @@ impl fmt::Display for CannedBucketAcl {
CannedBucketAcl::PublicRead => write!(f, "public-read"),
CannedBucketAcl::PublicReadWrite => write!(f, "public-read-write"),
CannedBucketAcl::AuthenticatedRead => write!(f, "authenticated-read"),
CannedBucketAcl::Custom(policy) => write!(f, "{policy}"),
}
}
}

/// [AWS Documentation](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html)
#[allow(dead_code)]
#[derive(Clone, Debug)]
enum BucketAcl {
pub enum BucketAcl {
Id { id: String },
Uri { uri: String },
Email { email: String },
Expand Down Expand Up @@ -71,6 +73,29 @@ fn acl_list(acl: &[BucketAcl]) -> String {
}

impl BucketConfiguration {
#[allow(clippy::too_many_arguments)]
pub fn new(
acl: CannedBucketAcl,
object_lock_enabled: bool,
grant_full_control: Option<Vec<BucketAcl>>,
grant_read: Option<Vec<BucketAcl>>,
grant_read_acp: Option<Vec<BucketAcl>>,
grant_write: Option<Vec<BucketAcl>>,
grant_write_acp: Option<Vec<BucketAcl>>,
location_constraint: Option<Region>,
) -> Self {
Self {
acl,
object_lock_enabled,
grant_full_control,
grant_read,
grant_read_acp,
grant_write,
grant_write_acp,
location_constraint,
}
}

pub fn public() -> Self {
BucketConfiguration {
acl: CannedBucketAcl::PublicReadWrite,
Expand Down

0 comments on commit bea733a

Please sign in to comment.