Skip to content

Commit

Permalink
fix: managed upload not to resolve config repeatedly
Browse files Browse the repository at this point in the history
Previously the managed upload creates new S3 clients with the
constructor parameters of the S3 client used to create the managed
upload. That results in that the newly created S3 client needs to
resolve every config, including the credentials over and over
again.

This issue was introduced by #3109 to make sure the internal S3
client inside of managed upload has the same constructor parameters
of the S3 client used to create the managed upload. So that the
logic relies on the constructor parameters like access point
and endpoint discovery works properly.

This change supply the resolved client config to create the
managed upload internal S3 client so configs don't need to be
resolved again, like credentials. Meanwhile, we explicitly set
the constructor parameter to be the same as that of S3 client
used to create the managed upload.
  • Loading branch information
AllanZhengYP committed Apr 6, 2021
1 parent f9b1c36 commit f84ff26
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-ManagedUpload-2bd31158.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "ManagedUpload",
"description": "fix a bug that credentials refresh to frequently"
}
8 changes: 7 additions & 1 deletion lib/s3/managed_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,18 @@ AWS.S3.ManagedUpload = AWS.util.inherit({
if (!self.service) {
self.service = new AWS.S3({params: params});
} else {
// Create a new S3 client from the supplied client's constructor.
var service = self.service;
var config = AWS.util.copy(service._originalConfig || {});
var config = AWS.util.copy(service.config);
config.signatureVersion = service.getSignatureVersion();
self.service = new service.constructor.__super__(config);
self.service.config.params =
AWS.util.merge(self.service.config.params || {}, params);
Object.defineProperty(self.service, '_originalConfig', {
get: function() { return service._originalConfig; },
enumerable: false,
configurable: true
});
}
},

Expand Down
4 changes: 3 additions & 1 deletion scripts/changelog/change-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function generateRandomIdentifier() {
* Ref: https://github.com/aws/aws-sdk-js/issues/3691
*/
function sanitizeFileName(filename) {
return filename.replaceAll(/[^a-zA-Z0-9\\.]/g, '-');
console.log("||||", filename);
return filename.replace(/[^a-zA-Z0-9\\.]/g, '-');
}

var CHANGES_DIR = path.join(process.cwd(), '.changes');
Expand Down Expand Up @@ -177,6 +178,7 @@ ChangeCreator.prototype = {
return config['inFile'];
}
// Determine default location
// console.log(this._type, this._category);
var newFileName = sanitizeFileName(this._type) + '-' + sanitizeFileName(this._category)
+ '-' + generateRandomIdentifier() + '.json';
return path.join(process.cwd(), '.changes', 'next-release', newFileName);
Expand Down
17 changes: 16 additions & 1 deletion test/s3/managed_upload.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f84ff26

Please sign in to comment.