Skip to content

Synchronise S3 initialisation with ember-cli-deploy-s3 #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -26,7 +26,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ The AWS secret for the user that has the ability to upload to the `bucket`. This

*Default:* `undefined`

### sessionToken

The AWS session token for the user that has the ability to upload to the `bucket`. This may be required if you are using the [AWS Security Token Service][6].
This requires both `accessKeyId` and `secretAccessKey` to be defined.

*Default:* `undefined`

### profile

The AWS profile as definied in ~/.aws/credentials. If this is left undefined, the normal [AWS SDK credential resolution][7] will take place.
Expand Down Expand Up @@ -155,6 +162,11 @@ If `endpoint` set the `region` option will be ignored.

*Default:* `[region].s3.amazonaws.com`

### proxy

The network proxy url used when sending requests to S3.

*Default:* `undefined`

### serverSideEncryption

Expand Down
75 changes: 54 additions & 21 deletions lib/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,74 @@ async function headObject(client, params) {

module.exports = CoreObject.extend({
init: function(options) {
this._super();
var plugin = options.plugin;
var config = plugin.pluginConfig;
var profile = plugin.readConfig('profile');
var endpoint = plugin.readConfig('endpoint');
var credentials;
this._super(options);

this._plugin = plugin;

var providedS3Client = plugin.readConfig("s3Client");
var s3Options = {
region: this.plugin.readConfig('region')
};

const proxy = this.plugin.readConfig('proxy');
if (proxy) {
var agent;
this._proxyAgent = this.plugin.readConfig('proxyAgent');
if (this._proxyAgent) {
agent = this._proxyAgent(proxy);
} else {
const { ProxyAgent } = require('proxy-agent');
agent = new ProxyAgent(proxy);
}
s3Options.httpOptions = {
agent
};
}

if (profile && !providedS3Client) {
this._plugin.log("Using AWS profile from config", { verbose: true });
credentials = fromIni({ profile: profile });
const accessKeyId = this.plugin.readConfig('accessKeyId');
const secretAccessKey = this.plugin.readConfig('secretAccessKey');
const sessionToken = this.plugin.readConfig('sessionToken');
const profile = this.plugin.readConfig('profile');
const signatureVersion = this.plugin.readConfig('signatureVersion');
const endpoint = this.plugin.readConfig('endpoint');

if (accessKeyId && secretAccessKey) {
this.plugin.log('Using AWS access key id and secret access key from config', { verbose: true });
s3Options.credentials = {
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
};

if (sessionToken) {
this.plugin.log('Using AWS session token from config', { verbose: true });
s3Options.credentials.sessionToken = sessionToken;
}
}

if (endpoint) {
this._plugin.log('Using endpoint from config', { verbose: true });
if (signatureVersion) {
this.plugin.log('Using signature version from config', { verbose: true });
s3Options.signatureVersion = signatureVersion;
}

this._client = providedS3Client || new S3(config);
if (profile && !this.plugin.readConfig('s3Client')) {
this.plugin.log('Using AWS profile from config', { verbose: true });
s3Options.credentials = fromIni({ profile: profile });
}

if (endpoint) {
this._client.config.endpoint = endpoint;
}
if (credentials) {
this._client.config.credentials = credentials;
this.plugin.log('Using endpoint from config', { verbose: true });
s3Options.endpoint = endpoint;
}

this._client = this.plugin.readConfig('s3Client') || new S3(s3Options);

if (this.plugin.readConfig('s3Client')) {
if (endpoint) {
this._client.config.endpoint = endpoint;
}
}
},

upload: function(options) {
var client = this._client;
var plugin = this._plugin;
var plugin = this.plugin;
var bucket = options.bucket;
var acl = options.acl;
var cacheControl = options.cacheControl;
Expand Down Expand Up @@ -112,7 +145,7 @@ module.exports = CoreObject.extend({
},

activate: function(options) {
var plugin = this._plugin;
var plugin = this.plugin;
var client = this._client;
var bucket = options.bucket;
var acl = options.acl;
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"core-object": "^3.0.0",
"ember-cli-deploy-plugin": "^0.2.9",
"mime-types": "^2.1.27",
"proxy-agent": "^6.5.0",
"rsvp": "^4.8.5"
},
"devDependencies": {
Expand All @@ -36,7 +37,7 @@
"release-it-lerna-changelog": "^3.1.0"
},
"engines": {
"node": "14.* || 16.* || 18.* || >= 20"
"node": "18.* || >= 20"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand Down
Loading