Skip to content

Commit 317e131

Browse files
authored
Merge branch 'apache:main' into wip_opfs_3
2 parents 0aa51c5 + 77e74d0 commit 317e131

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

core/services/s3/src/backend.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,12 @@ impl S3Builder {
682682

683683
None
684684
}
685+
686+
/// Set default ACL for new objects.
687+
pub fn default_acl(mut self, acl: &str) -> Self {
688+
self.config.default_acl = Some(acl.to_string());
689+
self
690+
}
685691
}
686692

687693
impl Builder for S3Builder {
@@ -960,6 +966,7 @@ impl Builder for S3Builder {
960966
enable_request_payer: config.enable_request_payer,
961967
signer,
962968
checksum_algorithm,
969+
default_acl: config.default_acl,
963970
}),
964971
})
965972
}

core/services/s3/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ pub struct S3Config {
221221
/// Indicates whether the client agrees to pay for the requests made to the S3 bucket.
222222
#[serde(alias = "aws_request_payer", alias = "request_payer")]
223223
pub enable_request_payer: bool,
224+
225+
/// Default ACL for new objects.
226+
/// Note that some s3 services like minio do not support this option.
227+
pub default_acl: Option<String>,
224228
}
225229

226230
impl Debug for S3Config {

core/services/s3/src/core.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ pub mod constants {
7575
pub const X_AMZ_VERSION_ID: &str = "x-amz-version-id";
7676
pub const X_AMZ_OBJECT_SIZE: &str = "x-amz-object-size";
7777

78+
pub const X_AMZ_ACL: &str = "x-amz-acl";
79+
7880
pub const RESPONSE_CONTENT_DISPOSITION: &str = "response-content-disposition";
7981
pub const RESPONSE_CONTENT_TYPE: &str = "response-content-type";
8082
pub const RESPONSE_CACHE_CONTROL: &str = "response-cache-control";
@@ -97,6 +99,7 @@ pub struct S3Core {
9799
pub allow_anonymous: bool,
98100
pub disable_list_objects_v2: bool,
99101
pub enable_request_payer: bool,
102+
pub default_acl: Option<String>,
100103

101104
pub signer: Signer<Credential>,
102105
pub checksum_algorithm: Option<ChecksumAlgorithm>,
@@ -330,6 +333,11 @@ impl S3Core {
330333
req = req.header(format!("{X_AMZ_META_PREFIX}{key}"), value)
331334
}
332335
}
336+
337+
// Set ACL header.
338+
if let Some(acl) = &self.default_acl {
339+
req = req.header(constants::X_AMZ_ACL, acl);
340+
}
333341
req
334342
}
335343

core/services/s3/src/docs.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This service can be used to:
3131
- `enable_virtual_host_style`: Enable virtual host style.
3232
- `disable_write_with_if_match`: Disable write with if match.
3333
- `enable_request_payer`: Enable the request payer for backend.
34+
- `default_acl`: Define the default access control list (ACL) when creating a new object. Note that some s3 services like minio do not support this option.
3435

3536
Refer to [`S3Builder`]'s public API docs for more information.
3637

@@ -237,3 +238,33 @@ async fn main() -> Result<()> {
237238
Ok(())
238239
}
239240
```
241+
242+
### S3 with default ACL
243+
244+
```rust,no_run
245+
use log::info;
246+
use opendal_core::Operator;
247+
use opendal_core::Result;
248+
use opendal_service_s3::S3;
249+
250+
#[tokio::main]
251+
async fn main() -> Result<()> {
252+
let mut builder = S3::default()
253+
// Setup builders
254+
.root("/path/to/dir")
255+
.bucket("test")
256+
.region("us-east-1")
257+
.endpoint("https://s3.amazonaws.com")
258+
.access_key_id("access_key_id")
259+
.secret_access_key("secret_access_key")
260+
// Enable public-read ACL
261+
.default_acl("public-read");
262+
263+
let op = Operator::new(builder)?.finish();
264+
info!("operator: {:?}", op);
265+
266+
// New objects will be created with public-read ACL
267+
268+
Ok(())
269+
}
270+
```

0 commit comments

Comments
 (0)