Permalink
Browse files

Refactoring on config and event listeners

  • Loading branch information...
1 parent 75f2073 commit 5b2b4c74527998795ba942abac5d97fff1d9a20f @lsegal lsegal committed Mar 18, 2013
Showing with 21 additions and 18 deletions.
  1. +1 −1 lib/config.js
  2. +20 −17 lib/event_listeners.js
View
@@ -544,7 +544,7 @@ AWS.EC2MetadataCredentials = inherit(AWS.Credentials, {
self.secretAccessKey = creds.SecretAccessKey;
self.sessionToken = creds.Token;
}
- callback(err, creds);
+ callback(err);
});
}
});
View
@@ -116,23 +116,26 @@ AWS.EventListeners = {
addAsync('SIGN', 'sign', function SIGN(req, doneCallback) {
req.client.config.getCredentials(function (err, credentials) {
- if (err) return doneCallback(err);
-
- var date = AWS.util.date.getDate();
- var sigVersion = req.client.api.signatureVersion;
- var SignerClass = AWS.Signers.RequestSigner.getVersion(sigVersion);
- var signer = new SignerClass(req.httpRequest,
- req.client.api.signingName || req.client.api.endpointPrefix);
-
- // clear old authorization headers
- delete req.httpRequest.headers['Authorization'];
- delete req.httpRequest.headers['Date'];
- delete req.httpRequest.headers['X-Amz-Date'];
-
- // add new authorization
- credentials = AWS.util.copy(credentials);
- signer.addAuthorization(credentials, date);
- doneCallback();
+ try {
+ if (err) return doneCallback(err);
+
+ var date = AWS.util.date.getDate();
+ var sigVersion = req.client.api.signatureVersion;
+ var SignerClass = AWS.Signers.RequestSigner.getVersion(sigVersion);
+ var signer = new SignerClass(req.httpRequest,
+ req.client.api.signingName || req.client.api.endpointPrefix);
+
+ // clear old authorization headers
+ delete req.httpRequest.headers['Authorization'];
+ delete req.httpRequest.headers['Date'];
+ delete req.httpRequest.headers['X-Amz-Date'];
+
+ // add new authorization
+ signer.addAuthorization(credentials, date);
+ doneCallback();
+ } catch (e) {
+ doneCallback(e);
+ }
});
});

0 comments on commit 5b2b4c7

Please sign in to comment.