Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Implement S3 storage system with enhanced customs #333

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions lib/document_stores/amazon-s3-custom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*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,
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;