From 670bab2fd92bd28654021657314292cca55cf255 Mon Sep 17 00:00:00 2001 From: Lukas SP <46935044+Lukaesebrot@users.noreply.github.com> Date: Mon, 10 Aug 2020 14:24:42 +0200 Subject: [PATCH 1/3] Create amazon-s3-custom.js --- lib/document_stores/amazon-s3-custom.js | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lib/document_stores/amazon-s3-custom.js diff --git a/lib/document_stores/amazon-s3-custom.js b/lib/document_stores/amazon-s3-custom.js new file mode 100644 index 00000000..41d8377d --- /dev/null +++ b/lib/document_stores/amazon-s3-custom.js @@ -0,0 +1,61 @@ +/*global require,module,process*/ + +var AWS = require('aws-sdk'); +var winston = require('winston'); + +var AmazonS3CustomDocumentStore = function(options) { + this.expire = options.expire; + this.bucket = options.bucket; + this.client = new AWS.S3({ + endpoint: options.endpoint, + region: options.region, + s3ForcePathStyle: true, + signatureVersion: 'v4' + }); +}; + +AmazonS3CustomDocumentStore.prototype.get = function(key, callback, skipExpire) { + var _this = this; + + var req = { + Bucket: _this.bucket, + Key: key + }; + + _this.client.getObject(req, function(err, data) { + if(err) { + callback(false); + } + else { + callback(data.Body.toString('utf-8')); + if (_this.expire && !skipExpire) { + winston.warn('amazon s3 store cannot set expirations on keys'); + } + } + }); +} + +AmazonS3CustomDocumentStore.prototype.set = function(key, data, callback, skipExpire) { + var _this = this; + + var req = { + Bucket: _this.bucket, + Key: key, + Body: data, + ContentType: 'text/plain' + }; + + _this.client.putObject(req, function(err, data) { + if (err) { + callback(false); + } + else { + callback(true); + if (_this.expire && !skipExpire) { + winston.warn('amazon s3 store cannot set expirations on keys'); + } + } + }); +} + +module.exports = AmazonS3CustomDocumentStore; From d238f36f7a68eee51f05c85386dbb6e64c22b7f2 Mon Sep 17 00:00:00 2001 From: Lukas SP <46935044+Lukaesebrot@users.noreply.github.com> Date: Mon, 10 Aug 2020 14:28:40 +0200 Subject: [PATCH 2/3] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 23ca0772..0faf047d 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,16 @@ Once you've done that, your config section should look like this: } ``` +If you want to specify some enhanced customs like the endpoint to use (may be useful if you want to use MinIO for example), you can use the `amazon-s3-custom` storage system: + +```json +{ + "type": "amazon-s3-custom", + "endpoint": "https://your-s3-endpoint.com", + "bucket": "your-bucket-name" +} +``` + Authentication is handled automatically by the client. Check [Amazon's documentation](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html) for more information. You will need to grant your role these permissions to From 19b7d6dd9af0ada86bf4b3805b2cff7f52e867bc Mon Sep 17 00:00:00 2001 From: Lukas SP <46935044+Lukaesebrot@users.noreply.github.com> Date: Mon, 10 Aug 2020 14:29:24 +0200 Subject: [PATCH 3/3] Remove S3 custom region --- lib/document_stores/amazon-s3-custom.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/document_stores/amazon-s3-custom.js b/lib/document_stores/amazon-s3-custom.js index 41d8377d..bf2916ba 100644 --- a/lib/document_stores/amazon-s3-custom.js +++ b/lib/document_stores/amazon-s3-custom.js @@ -8,7 +8,6 @@ var AmazonS3CustomDocumentStore = function(options) { this.bucket = options.bucket; this.client = new AWS.S3({ endpoint: options.endpoint, - region: options.region, s3ForcePathStyle: true, signatureVersion: 'v4' });