Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing custom client arguments to S3 client #146

Merged
merged 2 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {};
module.exports.s3 = function(config, key, args, callback) {
AWS.config.region = config.region;

var s3config = {};
var s3config = Object.assign( {}, config.clientArgs );
if (config.endpoint) {
s3config.endpoint = config.endpoint;
}
Expand Down
2 changes: 1 addition & 1 deletion proxy-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const AWS = require( 'aws-sdk' );
const authenticatedRequest = !!process.env.S3_AUTHENTICATED_REQUEST ? process.env.S3_AUTHENTICATED_REQUEST.toLowerCase() === 'true' : false;

function sendOriginal( config, bucket, key, callback ) {
const s3 = new AWS.S3(config);
const s3 = new AWS.S3( Object.assign( {}, config, config.clientArgs ) );

let request;
if ( authenticatedRequest ) {
Expand Down
5 changes: 5 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if ( process.env.AWS_REGION && process.env.AWS_S3_BUCKET ) {
config = JSON.parse( fs.readFileSync( 'config.json' ) );
}

config.clientArgs = config.clientArgs || {};
if ( process.env.AWS_S3_CLIENT_ARGS ) {
( new url.URLSearchParams( process.env.AWS_S3_CLIENT_ARGS ) ).forEach( ( value, key ) => config.clientArgs[ key ] = value );
}

http.createServer( function( request, response ) {
var params = url.parse( request.url, true );

Expand Down