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

Don't allow empty S3-key parts #98

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
3 changes: 2 additions & 1 deletion backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var AWS = require('aws-sdk');
var Dyno = require('dyno');
var stream = require('stream');
var zlib = require('zlib');
var joinPath = require('path.join');

module.exports = function(config, done) {
var primary = Dyno(config);
Expand All @@ -16,7 +17,7 @@ module.exports = function(config, done) {
return done(new Error('Must provide a bucket, prefix and jobid for backups'));

var index = !isNaN(parseInt(config.segment)) ? config.segment.toString() : 0;
var key = [config.backup.prefix, config.backup.jobid, index].join('/');
var key = joinPath(config.backup.prefix, config.backup.jobid, index);
var count = 0;
var size = 0;

Expand Down
5 changes: 3 additions & 2 deletions bin/incremental-diff-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var crypto = require('crypto');
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
var assert = require('assert');
var joinPath = require('path.join');

var args = minimist(process.argv.slice(2));

Expand Down Expand Up @@ -69,13 +70,13 @@ try {
catch (err) { key = JSON.parse(key); }


s3url.Key = [
s3url.Key = joinPath(
s3url.Key,
table,
crypto.createHash('md5')
.update(Dyno.serialize(key))
.digest('hex')
].join('/');
);

var dyno = Dyno({
region: region,
Expand Down
5 changes: 3 additions & 2 deletions bin/incremental-record-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var AWS = require('aws-sdk');
var s3 = new AWS.S3();
var queue = require('queue-async');
var Dyno = require('dyno');
var joinPath = require('path.join');

var args = minimist(process.argv.slice(2));

Expand Down Expand Up @@ -67,13 +68,13 @@ try {
}
catch (err) { key = JSON.parse(key); }

s3url.Key = [
s3url.Key = joinPath(
s3url.Key,
table,
crypto.createHash('md5')
.update(Dyno.serialize(key))
.digest('hex')
].join('/');
);

var q = queue(100);
q.awaitAll(function(err, results) {
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var queue = require('queue-async');
var crypto = require('crypto');
var https = require('https');
var streambot = require('streambot');
var joinPath = require('path.join');

module.exports.replicate = replicate;
module.exports.streambotReplicate = streambot(function(event, callback) {
Expand Down Expand Up @@ -189,7 +190,7 @@ function incrementalBackup(event, context, callback) {

var params = {
Bucket: process.env.BackupBucket,
Key: [process.env.BackupPrefix, table, id].join('/')
Key: joinPath(process.env.BackupPrefix, table, id)
};

var req = change.eventName === 'REMOVE' ? 'deleteObject' : 'putObject';
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"fastlog": "^1.0.0",
"minimist": "^1.1.0",
"queue-async": "1.0.7",
"path.join": "1.0.0",
"s3scan": "^0.2.2",
"s3urls": "^1.3.0",
"split": "^0.3.3",
Expand Down
3 changes: 2 additions & 1 deletion s3-backfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var stream = require('stream');
var queue = require('queue-async');
var crypto = require('crypto');
var https = require('https');
var joinPath = require('path.join');

module.exports = backfill;

Expand Down Expand Up @@ -59,7 +60,7 @@ function backfill(config, done) {

var params = {
Bucket: config.backup.bucket,
Key: [config.backup.prefix, config.table, id].join('/'),
Key: joinPath(config.backup.prefix, config.table, id),
Body: Dyno.serialize(record)
};

Expand Down
3 changes: 2 additions & 1 deletion s3-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var s3scan = require('s3scan');
var zlib = require('zlib');
var stream = require('stream');
var AgentKeepAlive = require('agentkeepalive');
var joinPath = require('path.join');

module.exports = function(config, done) {
var log = config.log || console.log;
Expand All @@ -29,7 +30,7 @@ module.exports = function(config, done) {
var s3 = new AWS.S3(s3Options);

var size = 0;
var uri = ['s3:/', config.source.bucket, config.source.prefix].join('/');
var uri = 's3://' + joinPath(config.source.bucket, config.source.prefix);
var partsLoaded = -1;

var objStream = s3scan.Scan(uri, { s3: s3 })
Expand Down