Browse files

Remove initialCredentials from FilesystemCredentials

  • Loading branch information...
1 parent 9dc16b1 commit b93b941664822cb5455fe57d13cf101db2bb420d @lsegal lsegal committed Mar 19, 2013
Showing with 13 additions and 35 deletions.
  1. +6 −7 lib/config.js
  2. +7 −28 test/credentials.spec.coffee
View
13 lib/config.js
@@ -195,7 +195,7 @@ AWS.Config = inherit({
this.clear();
var options = JSON.parse(AWS.util.readFileSync(path));
- var fileSystemCreds = new AWS.FileSystemCredentials(path, this);
+ var fileSystemCreds = new AWS.FileSystemCredentials(path);
var chain = new AWS.CredentialProviderChain();
chain.providers.unshift(fileSystemCreds);
chain.resolve(function (err, creds) {
@@ -447,16 +447,14 @@ AWS.Credentials = inherit({
AWS.FileSystemCredentials = inherit(AWS.Credentials, {
/**
- * @overload AWS.FileSystemCredentials(filename, initialCredentials=null)
+ * @overload AWS.FileSystemCredentials(filename)
* Creates a new FileSystemCredentials object from a filename
*
* @param filename [String] the path on disk to the JSON file to load.
- * @param initialCredentials [String] default credentials to load
- * if not specified in the file.
*/
- constructor: function FileSystemCredentials(filename, initialCredentials) {
+ constructor: function FileSystemCredentials(filename) {
+ AWS.Credentials.call(this);
this.filename = filename;
- AWS.Credentials.call(this, initialCredentials);
this.get(function() {});
},
@@ -474,7 +472,8 @@ AWS.FileSystemCredentials = inherit(AWS.Credentials, {
refresh: function refresh(callback) {
if (!callback) callback = function(err) { if (err) throw err; };
try {
- AWS.Credentials.call(this, JSON.parse(AWS.util.readFileSync(this.filename)));
+ var creds = JSON.parse(AWS.util.readFileSync(this.filename));
+ AWS.Credentials.call(this, creds);
if (!this.accessKeyId || !this.secretAccessKey) {
throw new Error('Credentials not set in ' + this.filename);
}
View
35 test/credentials.spec.coffee
@@ -120,49 +120,28 @@ describe 'AWS.FileSystemCredentials', ->
it 'should accept filename and load credentials from credentials block', ->
mock = '{"credentials":{"accessKeyId":"akid", "secretAccessKey":"secret","sessionToken":"session"}}'
- spyOn(AWS.util, 'readFileSync').andReturn(mock)
+ spy = spyOn(AWS.util, 'readFileSync').andReturn(mock)
creds = new AWS.FileSystemCredentials('foo')
validateCredentials(creds)
- it 'should accept filename and use initialCredentials', ->
- mock = '{}'
- spyOn(AWS.util, 'readFileSync').andReturn(mock)
-
- values =
- accessKeyId: "akid"
- secretAccessKey: "secret"
- sessionToken: "session"
- creds = new AWS.FileSystemCredentials('foo', values)
- validateCredentials(creds)
-
describe 'refresh', ->
it 'should refresh from given filename', ->
mock = '{"credentials":{"accessKeyId":"RELOADED", "secretAccessKey":"RELOADED","sessionToken":"RELOADED"}}'
spyOn(AWS.util, 'readFileSync').andReturn(mock)
- values =
- accessKeyId: "akid"
- secretAccessKey: "secret"
- sessionToken: "session"
- creds = new AWS.FileSystemCredentials('foo', values)
- validateCredentials(creds)
-
- creds.refresh()
-
+ creds = new AWS.FileSystemCredentials('foo')
validateCredentials(creds, 'RELOADED', 'RELOADED', 'RELOADED')
it 'fails if credentials are not in the file', ->
mock = '{"credentials":{}}'
spyOn(AWS.util, 'readFileSync').andReturn(mock)
- values =
- accessKeyId: "akid"
- secretAccessKey: "secret"
- sessionToken: "session"
- creds = new AWS.FileSystemCredentials('foo', values)
- validateCredentials(creds)
- expect(-> creds.refresh()).toThrow('Credentials not set in foo')
+ new AWS.FileSystemCredentials('foo').refresh (err) ->
+ expect(err.message).toEqual('Credentials not set in foo')
+
+ expect(-> new AWS.FileSystemCredentials('foo').refresh()).
+ toThrow('Credentials not set in foo')
describe 'AWS.EC2MetadataCredentials', ->
describe 'constructor', ->

0 comments on commit b93b941

Please sign in to comment.