Skip to content

Commit

Permalink
Allow setting no ACL (#3577)
Browse files Browse the repository at this point in the history
not all people use buckets with ACL

until next major you can use COMPANION_AWS_DISABLE_ACL=true
to disable setting of ACL in s3

fixes #3570
  • Loading branch information
mifi committed Mar 22, 2022
1 parent c140707 commit 431790e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/config/companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const defaultOptions = {
},
providerOptions: {
s3: {
acl: 'public-read',
acl: 'public-read', // todo default to no ACL in next major
endpoint: 'https://{service}.{region}.amazonaws.com',
conditions: [],
useAccelerateEndpoint: false,
Expand Down
8 changes: 6 additions & 2 deletions packages/@uppy/companion/src/server/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,18 @@ class Uploader {
return chunkSize
}

const upload = client.upload({
const params = {
Bucket: options.bucket,
Key: options.getKey(null, filename, this.options.metadata),
ACL: options.acl,
ContentType: this.options.metadata.type,
Metadata: this.options.metadata,
Body: stream,
}, {
}

if (options.acl != null) params.ACL = options.acl

const upload = client.upload(params, {
partSize: getPartSize(this.options.chunkSize),
})

Expand Down
16 changes: 10 additions & 6 deletions packages/@uppy/companion/src/server/controllers/s3.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const router = require('express').Router

module.exports = function s3 (config) {
if (typeof config.acl !== 'string') {
throw new TypeError('s3: The `acl` option must be a string')
if (typeof config.acl !== 'string' && config.acl != null) {
throw new TypeError('s3: The `acl` option must be a string or null')
}
if (typeof config.getKey !== 'function') {
throw new TypeError('s3: The `getKey` option must be a function')
Expand Down Expand Up @@ -38,12 +38,13 @@ module.exports = function s3 (config) {
}

const fields = {
acl: config.acl,
key,
success_action_status: '201',
'content-type': req.query.type,
}

if (config.acl != null) fields.acl = config.acl

Object.keys(metadata).forEach((key) => {
fields[`x-amz-meta-${key}`] = metadata[key]
})
Expand Down Expand Up @@ -92,13 +93,16 @@ module.exports = function s3 (config) {
return res.status(400).json({ error: 's3: content type must be a string' })
}

client.createMultipartUpload({
const params = {
Bucket: config.bucket,
Key: key,
ACL: config.acl,
ContentType: type,
Metadata: metadata,
}, (err, data) => {
}

if (config.acl != null) params.ACL = config.acl

client.createMultipartUpload(params, (err, data) => {
if (err) {
next(err)
return
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/standalone/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const getConfigFromEnv = () => {
useAccelerateEndpoint:
process.env.COMPANION_AWS_USE_ACCELERATE_ENDPOINT === 'true',
expires: parseInt(process.env.COMPANION_AWS_EXPIRES || '300', 10),
acl: process.env.COMPANION_AWS_ACL || 'public-read',
acl: process.env.COMPANION_AWS_DISABLE_ACL === 'true' ? null : (process.env.COMPANION_AWS_ACL || 'public-read'), // todo default to no ACL in next major and remove COMPANION_AWS_DISABLE_ACL
},
},
server: {
Expand Down

0 comments on commit 431790e

Please sign in to comment.