Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix loading of credentials for EC2MetadataCredentials

  • Loading branch information...
commit 52177faaaa9a43e0d30b2f8f73c97feafe341d7b 1 parent 2041e09
@lsegal lsegal authored
View
9 lib/config.js
@@ -146,7 +146,8 @@ AWS.Config = inherit({
function getAsyncCredentials() {
self.credentials.get(function(err) {
if (err) {
- var msg = 'Could not load credentials from ' + self.credentials.name;
+ var msg = 'Could not load credentials from ' +
+ self.credentials.constructor.name;
err = credError(msg, err);
}
finish(err);
@@ -523,6 +524,7 @@ AWS.EC2MetadataCredentials = inherit(AWS.Credentials, {
constructor: function EC2MetadataCredentials(options) {
this.serviceError = null;
this.metadataService = new AWS.MetadataService(options);
+ this.metadata = {};
},
refresh: function refresh(callback) {
@@ -537,7 +539,10 @@ AWS.EC2MetadataCredentials = inherit(AWS.Credentials, {
if (err) {
self.serviceError = err;
} else {
- AWS.util.update(self, creds);
+ self.metadata = creds;
+ self.accessKeyId = creds.AccessKeyId;
+ self.secretAccessKey = creds.SecretAccessKey;
+ self.sessionToken = creds.Token;
}
callback(err, creds);
});
View
2  test/config.spec.coffee
@@ -180,7 +180,7 @@ describe 'AWS.Config', ->
it 'should error if credentials.get() cannot resolve', ->
options = credentials:
- name: 'CustomCredentials'
+ constructor: name: 'CustomCredentials'
get: (cb) -> cb(new Error('Error!'), null)
expectError options, 'Could not load credentials from CustomCredentials'
View
10 test/credentials.spec.coffee
@@ -171,7 +171,15 @@ describe 'AWS.EC2MetadataCredentials', ->
expect(creds.metadataService.host).toEqual('host')
describe 'refresh', ->
- it 'loads credentials from EC2 Metadata service'
+ it 'loads credentials from EC2 Metadata service', ->
+ creds = new AWS.EC2MetadataCredentials(host: 'host')
+ spy = spyOn(creds.metadataService, 'loadCredentials').andCallFake (cb) ->
+ cb(null, Code:"Success",AccessKeyId:"KEY",SecretAccessKey:"SECRET",Token:"TOKEN")
+ creds.refresh(->)
+ expect(creds.metadata.Code).toEqual('Success')
+ expect(creds.accessKeyId).toEqual('KEY')
+ expect(creds.secretAccessKey).toEqual('SECRET')
+ expect(creds.sessionToken).toEqual('TOKEN')
it 'does not try to load creds second time if Metadata service failed', ->
creds = new AWS.EC2MetadataCredentials(host: 'host')
View
2  test/metadata_service.spec.coffee
@@ -55,7 +55,7 @@ describe 'AWS.MetadataService', ->
it 'should fail if server is not up', ->
server.close(); server = null
- service = new AWS.MetadataService()
+ service = new AWS.MetadataService(host: '255.255.255.255')
service.httpOptions.timeout = 10
[err, data] = [null, null]
runs ->
Please sign in to comment.
Something went wrong with that request. Please try again.