From dd8b928684e57ed2a743c12eb72c9ae0984e7170 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Mon, 21 Sep 2015 14:02:00 -0700 Subject: [PATCH] aws: add copyObject --- src/aws.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/aws.js b/src/aws.js index b0fe8a683..c5c45e1bf 100644 --- a/src/aws.js +++ b/src/aws.js @@ -8,7 +8,9 @@ exports = module.exports = { addSubdomain: addSubdomain, delSubdomain: delSubdomain, - getChangeStatus: getChangeStatus + getChangeStatus: getChangeStatus, + + copyObject: copyObject }; var assert = require('assert'), @@ -259,3 +261,26 @@ function getChangeStatus(changeId, callback) { }); }); } + +function copyObject(from, to, callback) { + assert.strictEqual(typeof from, 'string'); + assert.strictEqual(typeof to, 'string'); + assert.strictEqual(typeof callback, 'function'); + + getAWSCredentials(function (error, credentials) { + if (error) return callback(error); + + var params = { + Bucket: config.aws().backupBucket, // target bucket + Key: config.aws().backupPrefix + '/' + to, // target file + CopySource: config.aws().backupBucket + '/' + config.aws().backupPrefix + '/' + from, // source + }; + + var s3 = new AWS.S3(credentials); + s3.copyObject(params, function (error) { + if (error) return callback(new SubdomainError(SubdomainError.EXTERNAL_ERROR, new Error(error))); + + callback(null); + }); + }); +}