Skip to content

Commit 8710952

Browse files
committed
Merge pull request #39 from kkumler/feature/allow_iam_profiles
Remove required keys, to support IAM roles
2 parents b35188a + 1625565 commit 8710952

File tree

4 files changed

+18
-51
lines changed

4 files changed

+18
-51
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,16 @@ For detailed information on how configuration of plugins works, please refer to
6363
**WARNING: Don't share a configuration object between [ember-cli-deploy-s3-index](https://github.com/ember-cli-deploy/ember-cli-deploy-s3-index) and this plugin. The way these two plugins read their configuration has sideeffects which will unfortunately break your deploy if you share one configuration object between the two** (we are already working on a fix)
6464
<hr/>
6565

66-
### accessKeyId (`required`)
66+
### accessKeyId
6767

68-
The AWS access key for the user that has the ability to upload to the `bucket`.
68+
The AWS access key for the user that has the ability to upload to the `bucket`. If this is left undefined,
69+
the normal [AWS SDK credential resolution](5) will take place.
6970

7071
*Default:* `undefined`
7172

72-
### secretAccessKey (`required`)
73+
### secretAccessKey
7374

74-
The AWS secret for the user that has the ability to upload to the `bucket`.
75+
The AWS secret for the user that has the ability to upload to the `bucket`. This must be defined when `accessKeyId` is defined.
7576

7677
*Default:* `undefined`
7778

@@ -193,3 +194,4 @@ Replace <your-s3-bucket-name> with the name of the actual bucket you are deployi
193194
[2]: https://github.com/ember-cli-deploy/ember-cli-deploy-build "ember-cli-deploy-build"
194195
[3]: https://github.com/lukemelia/ember-cli-deploy-gzip "ember-cli-deploy-gzip"
195196
[4]: https://github.com/lukemelia/ember-cli-deploy-manifest "ember-cli-deploy-manifest"
197+
[5]: https://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html#Setting_AWS_Credentials "Setting AWS Credentials"

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = {
3535
return context.s3Client; // if you want to provide your own S3 client to be used instead of one from aws-sdk
3636
}
3737
},
38-
requiredConfig: ['accessKeyId', 'secretAccessKey', 'bucket', 'region'],
38+
requiredConfig: ['bucket', 'region'],
3939

4040
upload: function(context) {
4141
var self = this;

lib/s3.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,18 @@ module.exports = CoreObject.extend({
1414
init: function(options) {
1515
this._plugin = options.plugin;
1616
var AWS = require('aws-sdk');
17-
this._client = this._plugin.readConfig('s3Client') || new AWS.S3({
18-
accessKeyId: this._plugin.readConfig('accessKeyId'),
19-
secretAccessKey: this._plugin.readConfig('secretAccessKey'),
17+
var s3Options = {
2018
region: this._plugin.readConfig('region')
21-
});
19+
};
20+
const accessKeyId = this._plugin.readConfig('accessKeyId');
21+
const secretAccessKey = this._plugin.readConfig('secretAccessKey');
22+
23+
if (accessKeyId && secretAccessKey) {
24+
this._plugin.log('Using AWS access key id and secret access key from config', { verbose: true });
25+
s3Options.accessKeyId = accessKeyId;
26+
s3Options.secretAccessKey = secretAccessKey;
27+
}
28+
this._client = this._plugin.readConfig('s3Client') || new AWS.S3(s3Options);
2229
},
2330

2431
upload: function(options) {

tests/unit/index-nodetest.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -124,48 +124,6 @@ describe('s3 plugin', function() {
124124
});
125125

126126
describe('required config', function() {
127-
it('warns about missing accessKeyId', function() {
128-
delete context.config.s3.accessKeyId;
129-
130-
var plugin = subject.createDeployPlugin({
131-
name: 's3'
132-
});
133-
plugin.beforeHook(context);
134-
assert.throws(function(error){
135-
plugin.configure(context);
136-
});
137-
var messages = mockUi.messages.reduce(function(previous, current) {
138-
if (/- Missing required config: `accessKeyId`/.test(current)) {
139-
previous.push(current);
140-
}
141-
142-
return previous;
143-
}, []);
144-
145-
assert.equal(messages.length, 1);
146-
});
147-
148-
it('warns about missing secretAccessKey', function() {
149-
delete context.config.s3.secretAccessKey;
150-
151-
var plugin = subject.createDeployPlugin({
152-
name: 's3'
153-
});
154-
plugin.beforeHook(context);
155-
assert.throws(function(error){
156-
plugin.configure(context);
157-
});
158-
var messages = mockUi.messages.reduce(function(previous, current) {
159-
if (/- Missing required config: `secretAccessKey`/.test(current)) {
160-
previous.push(current);
161-
}
162-
163-
return previous;
164-
}, []);
165-
166-
assert.equal(messages.length, 1);
167-
});
168-
169127
it('warns about missing bucket', function() {
170128
delete context.config.s3.bucket;
171129

0 commit comments

Comments
 (0)