rename to apiConfig

This commit is contained in:
Girish Ramakrishnan
2016-03-31 09:48:01 -07:00
parent 9e7ae1a4f7
commit b4ddfa94cc
2 changed files with 50 additions and 50 deletions
+26 -26
View File
@@ -11,38 +11,38 @@ exports = module.exports = {
var assert = require('assert'),
AWS = require('aws-sdk');
function getBackupCredentials(backupConfig, callback) {
assert.strictEqual(typeof backupConfig, 'object');
function getBackupCredentials(apiConfig, callback) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof callback, 'function');
assert(backupConfig.accessKeyId && backupConfig.secretAccessKey);
assert(apiConfig.accessKeyId && apiConfig.secretAccessKey);
var credentials = {
accessKeyId: backupConfig.accessKeyId,
secretAccessKey: backupConfig.secretAccessKey,
accessKeyId: apiConfig.accessKeyId,
secretAccessKey: apiConfig.secretAccessKey,
region: 'us-east-1'
};
if (backupConfig.endpoint) credentials.endpoint = new AWS.Endpoint(backupConfig.endpoint);
if (apiConfig.endpoint) credentials.endpoint = new AWS.Endpoint(apiConfig.endpoint);
callback(null, credentials);
}
function getAllPaged(backupConfig, page, perPage, callback) {
assert.strictEqual(typeof backupConfig, 'object');
function getAllPaged(apiConfig, page, perPage, callback) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof page, 'number');
assert.strictEqual(typeof perPage, 'number');
assert.strictEqual(typeof callback, 'function');
getBackupCredentials(backupConfig, function (error, credentials) {
getBackupCredentials(apiConfig, function (error, credentials) {
if (error) return callback(error);
var s3 = new AWS.S3(credentials);
var params = {
Bucket: backupConfig.bucket,
Bucket: apiConfig.bucket,
EncodingType: 'url',
Prefix: backupConfig.prefix + '/backup_'
Prefix: apiConfig.prefix + '/backup_'
};
s3.listObjects(params, function (error, data) {
@@ -51,7 +51,7 @@ function getAllPaged(backupConfig, page, perPage, callback) {
var results = data.Contents.map(function (backup) {
return {
creationTime: backup.LastModified,
restoreKey: backup.Key.slice(backupConfig.prefix.length + 1),
restoreKey: backup.Key.slice(apiConfig.prefix.length + 1),
dependsOn: [] // FIXME empty dependsOn is wrong and version property is missing!!
};
});
@@ -63,19 +63,19 @@ function getAllPaged(backupConfig, page, perPage, callback) {
});
}
function getSignedUploadUrl(backupConfig, filename, callback) {
assert.strictEqual(typeof backupConfig, 'object');
function getSignedUploadUrl(apiConfig, filename, callback) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof filename, 'string');
assert.strictEqual(typeof callback, 'function');
getBackupCredentials(backupConfig, function (error, credentials) {
getBackupCredentials(apiConfig, function (error, credentials) {
if (error) return callback(error);
var s3 = new AWS.S3(credentials);
var params = {
Bucket: backupConfig.bucket,
Key: backupConfig.prefix + '/' + filename,
Bucket: apiConfig.bucket,
Key: apiConfig.prefix + '/' + filename,
Expires: 60 * 30 /* 30 minutes */
};
@@ -85,12 +85,12 @@ function getSignedUploadUrl(backupConfig, filename, callback) {
});
}
function getSignedDownloadUrl(backupConfig, info, callback) {
assert.strictEqual(typeof backupConfig, 'object');
function getSignedDownloadUrl(apiConfig, info, callback) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof info, 'object');
assert.strictEqual(typeof callback, 'function');
getBackupCredentials(backupConfig, function (error, credentials) {
getBackupCredentials(apiConfig, function (error, credentials) {
if (error) return callback(error);
var s3 = new AWS.S3(credentials);
@@ -107,19 +107,19 @@ function getSignedDownloadUrl(backupConfig, info, callback) {
});
}
function copyObject(backupConfig, from, to, callback) {
assert.strictEqual(typeof backupConfig, 'object');
function copyObject(apiConfig, from, to, callback) {
assert.strictEqual(typeof apiConfig, 'object');
assert.strictEqual(typeof from, 'string');
assert.strictEqual(typeof to, 'string');
assert.strictEqual(typeof callback, 'function');
getBackupCredentials(backupConfig, function (error, credentials) {
getBackupCredentials(apiConfig, function (error, credentials) {
if (error) return callback(error);
var params = {
Bucket: backupConfig.bucket, // target bucket
Key: backupConfig.prefix + '/' + to, // target file
CopySource: backupConfig.bucket + '/' + backupConfig.prefix + '/' + from, // source
Bucket: apiConfig.bucket, // target bucket
Key: apiConfig.prefix + '/' + to, // target file
CopySource: apiConfig.bucket + '/' + apiConfig.prefix + '/' + from, // source
};
var s3 = new AWS.S3(credentials);