-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat: add aws s3 provider #227
base: master
Are you sure you want to change the base?
Conversation
src/providers/aws.js
Outdated
} catch (e) { | ||
this._logger.warn('failed to load aws-sdk/clients/s3', e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} catch (e) { | |
this._logger.warn('failed to load aws-sdk/clients/s3', e); | |
} | |
} catch (err) { | |
this._logger.warn({ err }, 'failed to load aws-sdk/clients/s3'); | |
} |
otherwise error will not get serialized - this is an optimization in the logger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/providers/aws.js
Outdated
connect() { | ||
return Promise | ||
.bind(this) | ||
.then(this.findOrCreateBucket); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use native promises now:
connect() { | |
return Promise | |
.bind(this) | |
.then(this.findOrCreateBucket); | |
} | |
async connect() { | |
return this.findOrCreateBucket(); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/providers/aws.js
Outdated
const params = { | ||
Bucket: this._config.bucketName, | ||
Expires: action === 'putObject' ? UPLOAD_URL_EXPIRES_IN_SEC : DOWNLOAD_URL_EXPIRES_IN_SEC, | ||
Key: input.key, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not familiar with s3 signed URLs, but on google you have to sign headers as well, especially for put action.
headers include object size, any custom headers, etc - could this be required here?
src/providers/aws.js
Outdated
} | ||
|
||
connect() { | ||
return Promise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise.bind is specific to bluebird (http://bluebirdjs.com/docs/getting-started.html)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
@@ -57,6 +57,14 @@ class ProviderFactory { | |||
|
|||
return provider; | |||
} | |||
|
|||
// eslint-disable-next-line class-methods-use-this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use static
modifier since we are not using this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
test/suites/providers/aws.js
Outdated
accessKeyId: 'AKIASS5V3WV23VA4KYOF', | ||
accessKeySecret: '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', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these keys must be revoked now as they were commited to open source code - they must be passed on via .env and never be commited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
773348a
to
348f597
Compare
Codecov Report
@@ Coverage Diff @@
## master #227 +/- ##
==========================================
- Coverage 92.78% 92.50% -0.29%
==========================================
Files 49 49
Lines 1289 1294 +5
==========================================
+ Hits 1196 1197 +1
- Misses 93 97 +4
Continue to review full report at Codecov.
|
348f597
to
99a1a80
Compare
09e6621
to
77cc20c
Compare
77cc20c
to
2414957
Compare
async subscribe() { | ||
const { Topics: topics } = await new SNS({ region: this._config.aws.credentials.region }).listTopics({}).promise(); | ||
|
||
const topicArn = `arn:aws:sns:us-west-2:178085672309:${this._config.aws.credentials.topicName}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to configuration
|
||
async function handleListBuckets(err, data) { | ||
if (err) { | ||
this.log.warn('s3 bucket can not be created'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.log.warn('s3 bucket can not be created'); | |
this.log.warn({ err }, 's3 bucket can not be created'); |
await aws.createBucket(bucketParams, function handleCreateBucket(_err) { | ||
if (_err) { | ||
this.log.warn('s3 bucket can not be created'); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise & callback?
}; | ||
|
||
return new Promise((resolve, reject) => { | ||
this._aws.getSignedUrl('putObject', params, (err, url) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promisify
// }, | ||
// ]; | ||
|
||
exports.transport = env.PROVIDER === 'aws' ? awsTransport : awsTransport; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aws or gcs?
return this.files | ||
.postProcess(0, Date.now()) | ||
.reflect() | ||
.then(inspectPromise()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a legacy implementstion, its best to use the following now:
return this.files | |
.postProcess(0, Date.now()) | |
.reflect() | |
.then(inspectPromise()); | |
await this.files.postProcess(0, Date.now()) |
it('rejects to show direct only file without proper username', function test() { | ||
return downloadFile | ||
.call(this, { uploadId: this.response.uploadId }) | ||
.reflect() | ||
.then(inspectPromise(false)); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for these things its best to do this:
it('rejects to show direct only file without proper username', function test() { | |
return downloadFile | |
.call(this, { uploadId: this.response.uploadId }) | |
.reflect() | |
.then(inspectPromise(false)); | |
}); | |
it('rejects to show direct only file without proper username', async function test() { | |
await assert.rejects(downloadFile.call(this, { uploadId: this.response.uploadId })); | |
}); |
No description provided.