Move backup config fetching into storage backend
This commit is contained in:
@@ -5,6 +5,7 @@ exports = module.exports = {
|
||||
getAppBackupDetails: getAppBackupDetails,
|
||||
|
||||
getRestoreUrl: getRestoreUrl,
|
||||
getAppRestoreConfig: getAppRestoreConfig,
|
||||
getLocalFilePath: getLocalFilePath,
|
||||
|
||||
copyObject: copyObject
|
||||
@@ -13,6 +14,7 @@ exports = module.exports = {
|
||||
var assert = require('assert'),
|
||||
AWS = require('aws-sdk'),
|
||||
config = require('../config.js'),
|
||||
safe = require('safetydance'),
|
||||
superagent = require('superagent');
|
||||
|
||||
function getBackupCredentials(apiConfig, callback) {
|
||||
@@ -106,6 +108,28 @@ function getRestoreUrl(apiConfig, filename, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getAppRestoreConfig(apiConfig, backupId, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupId, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
var configFilename = backupId.replace(/\.tar\.gz$/, '.json');
|
||||
|
||||
getRestoreUrl(apiConfig, configFilename, function (error, result) {
|
||||
if (error) return callback(error);
|
||||
|
||||
superagent.get(result.url).buffer(true).timeout(30 * 1000).end(function (error, response) {
|
||||
if (error && !error.response) return callback(new Error(error.message));
|
||||
if (response.statusCode !== 200) return callback(new Error('Invalid response code when getting config.json : ' + response.statusCode));
|
||||
|
||||
var config = safe.JSON.parse(response.text);
|
||||
if (!config) return callback(new Error('Error in config:' + safe.error.message));
|
||||
|
||||
return callback(null, config);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getLocalFilePath(apiConfig, filename, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof filename, 'string');
|
||||
|
||||
@@ -5,6 +5,7 @@ exports = module.exports = {
|
||||
getAppBackupDetails: getAppBackupDetails,
|
||||
|
||||
getRestoreUrl: getRestoreUrl,
|
||||
getAppRestoreConfig: getAppRestoreConfig,
|
||||
getLocalFilePath: getLocalFilePath,
|
||||
|
||||
copyObject: copyObject
|
||||
@@ -12,7 +13,8 @@ exports = module.exports = {
|
||||
|
||||
var assert = require('assert'),
|
||||
fs = require('fs'),
|
||||
path = require('path');
|
||||
path = require('path'),
|
||||
safe = require('safetydance');
|
||||
|
||||
var FALLBACK_BACKUP_FOLDER = '/var/backups';
|
||||
|
||||
@@ -57,6 +59,20 @@ function getRestoreUrl(apiConfig, filename, callback) {
|
||||
callback(null, { url: restoreUrl });
|
||||
}
|
||||
|
||||
function getAppRestoreConfig(apiConfig, backupId, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupId, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
var backupFolder = apiConfig.backupFolder || FALLBACK_BACKUP_FOLDER;
|
||||
var configFilename = backupId.replace(/\.tar\.gz$/, '.json');
|
||||
|
||||
var restoreConfig = safe.require(path.join(backupFolder, configFilename));
|
||||
if (!restoreConfig) return callback(new Error('No app backup config found'));
|
||||
|
||||
callback(null, restoreConfig);
|
||||
}
|
||||
|
||||
function getLocalFilePath(apiConfig, filename, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof filename, 'string');
|
||||
|
||||
@@ -11,6 +11,7 @@ exports = module.exports = {
|
||||
getAppBackupDetails: getAppBackupDetails,
|
||||
|
||||
getRestoreUrl: getRestoreUrl,
|
||||
getAppRestoreConfig: getAppRestoreConfig,
|
||||
getLocalFilePath: getLocalFilePath,
|
||||
|
||||
copyObject: copyObject
|
||||
@@ -53,6 +54,19 @@ function getRestoreUrl(apiConfig, filename, callback) {
|
||||
callback(new Error('not implemented'));
|
||||
}
|
||||
|
||||
function getAppRestoreConfig(apiConfig, backupId, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupId, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
// var configFilename = backupId.replace(/\.tar\.gz$/, '.json');
|
||||
|
||||
// Result: {} <- Backup config object from .json file
|
||||
// The resulting url must work with curl as it is passed into start.sh and restoreapp.sh
|
||||
|
||||
callback(new Error('not implemented'));
|
||||
}
|
||||
|
||||
function getLocalFilePath(apiConfig, filename, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof filename, 'string');
|
||||
|
||||
@@ -5,13 +5,16 @@ exports = module.exports = {
|
||||
getAppBackupDetails: getAppBackupDetails,
|
||||
|
||||
getRestoreUrl: getRestoreUrl,
|
||||
getAppRestoreConfig: getAppRestoreConfig,
|
||||
getLocalFilePath: getLocalFilePath,
|
||||
|
||||
copyObject: copyObject
|
||||
};
|
||||
|
||||
var assert = require('assert'),
|
||||
AWS = require('aws-sdk');
|
||||
AWS = require('aws-sdk'),
|
||||
safe = require('safetydance'),
|
||||
superagent = require('superagent');
|
||||
|
||||
function getBackupCredentials(apiConfig, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
@@ -86,6 +89,28 @@ function getRestoreUrl(apiConfig, filename, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function getAppRestoreConfig(apiConfig, backupId, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof backupId, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
var configFilename = backupId.replace(/\.tar\.gz$/, '.json');
|
||||
|
||||
getRestoreUrl(apiConfig, configFilename, function (error, result) {
|
||||
if (error) return callback(error);
|
||||
|
||||
superagent.get(result.url).buffer(true).timeout(30 * 1000).end(function (error, response) {
|
||||
if (error && !error.response) return callback(new Error(error.message));
|
||||
if (response.statusCode !== 200) return callback(new Error('Invalid response code when getting config.json : ' + response.statusCode));
|
||||
|
||||
var config = safe.JSON.parse(response.text);
|
||||
if (!config) return callback(new Error('Error in config:' + safe.error.message));
|
||||
|
||||
return callback(null, config);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getLocalFilePath(apiConfig, filename, callback) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof filename, 'string');
|
||||
|
||||
Reference in New Issue
Block a user