Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

socaseinpoint
Copy link
Collaborator

No description provided.

Comment on lines 37 to 50
} catch (e) {
this._logger.warn('failed to load aws-sdk/clients/s3', e);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 42 to 65
connect() {
return Promise
.bind(this)
.then(this.findOrCreateBucket);
}
Copy link
Member

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:

Suggested change
connect() {
return Promise
.bind(this)
.then(this.findOrCreateBucket);
}
async connect() {
return this.findOrCreateBucket();
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 65 to 141
const params = {
Bucket: this._config.bucketName,
Expires: action === 'putObject' ? UPLOAD_URL_EXPIRES_IN_SEC : DOWNLOAD_URL_EXPIRES_IN_SEC,
Key: input.key,
};
Copy link
Member

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?

}

connect() {
return Promise
Copy link
Member

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)

Copy link
Collaborator Author

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
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 8 to 9
accessKeyId: 'AKIASS5V3WV23VA4KYOF',
accessKeySecret: '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',
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@codecov
Copy link

codecov bot commented May 26, 2021

Codecov Report

Merging #227 (348f597) into master (a6f2e0d) will decrease coverage by 0.28%.
The diff coverage is 20.00%.

❗ Current head 348f597 differs from pull request most recent head 2414957. Consider uploading reports for the commit 2414957 to get more accurate results
Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/providers/factory.js 73.07% <0.00%> (-9.54%) ⬇️
src/providers/index.js 96.00% <50.00%> (-4.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3966e90...2414957. Read the comment docs.

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}`;
Copy link
Member

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.log.warn('s3 bucket can not be created');
this.log.warn({ err }, 's3 bucket can not be created');

Comment on lines +118 to +122
await aws.createBucket(bucketParams, function handleCreateBucket(_err) {
if (_err) {
this.log.warn('s3 bucket can not be created');
}
});
Copy link
Member

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) => {
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aws or gcs?

Comment on lines +84 to +87
return this.files
.postProcess(0, Date.now())
.reflect()
.then(inspectPromise());
Copy link
Member

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:

Suggested change
return this.files
.postProcess(0, Date.now())
.reflect()
.then(inspectPromise());
await this.files.postProcess(0, Date.now())

Comment on lines +90 to +95
it('rejects to show direct only file without proper username', function test() {
return downloadFile
.call(this, { uploadId: this.response.uploadId })
.reflect()
.then(inspectPromise(false));
});
Copy link
Member

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:

Suggested change
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 }));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants