backups: move mount status to separate route

This commit is contained in:
Girish Ramakrishnan
2023-04-30 17:21:18 +02:00
parent 898413bfd4
commit 883915c9d3
7 changed files with 42 additions and 9 deletions
+17
View File
@@ -27,6 +27,7 @@ exports = module.exports = {
testProviderConfig,
remount,
getMountStatus,
BACKUP_IDENTIFIER_BOX: 'box',
BACKUP_IDENTIFIER_MAIL: 'mail',
@@ -50,6 +51,7 @@ const assert = require('assert'),
eventlog = require('./eventlog.js'),
hat = require('./hat.js'),
locker = require('./locker.js'),
mounts = require('./mounts.js'),
path = require('path'),
paths = require('./paths.js'),
safe = require('safetydance'),
@@ -361,3 +363,18 @@ async function remount(auditSource) {
await storage.api(backupConfig.provider).remount(backupConfig);
}
async function getMountStatus() {
const backupConfig = await settings.getBackupConfig();
let hostPath;
if (mounts.isManagedProvider(backupConfig.provider)) {
hostPath = paths.MANAGED_BACKUP_MOUNT_DIR;
} else if (backupConfig.provider === 'mountpoint') {
hostPath = backupConfig.mountPoint;
} else if (backupConfig.provider === 'filesystem') {
hostPath = backupConfig.backupFolder;
}
return await mounts.getStatus(backupConfig.provider, hostPath); // { state, message }
}
+7
View File
@@ -6,6 +6,7 @@ exports = module.exports = {
create,
cleanup,
remount,
getMountStatus
};
const assert = require('assert'),
@@ -63,3 +64,9 @@ async function remount(req, res, next) {
next(new HttpSuccess(202, {}));
}
async function getMountStatus(req, res, next) {
const [error, mountStatus] = await safe(backups.getMountStatus());
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(200, mountStatus));
}
+1
View File
@@ -145,6 +145,7 @@ async function initializeExpressSync() {
// backup routes
router.get ('/api/v1/backups', token, authorizeAdmin, routes.backups.list);
router.get ('/api/v1/backups/mount_status', token, authorizeAdmin, routes.backups.getMountStatus);
router.post('/api/v1/backups/create', token, authorizeAdmin, routes.backups.create);
router.post('/api/v1/backups/cleanup', json, token, authorizeAdmin, routes.backups.cleanup);
router.post('/api/v1/backups/remount', json, token, authorizeAdmin, routes.backups.remount);
+1 -7
View File
@@ -406,13 +406,7 @@ async function getBackupConfig() {
const value = await get(exports.BACKUP_CONFIG_KEY);
if (value === null) return gDefaults[exports.BACKUP_CONFIG_KEY];
const backupConfig = JSON.parse(value); // provider, token, password, region, prefix, bucket
if (mounts.isManagedProvider(backupConfig.provider) || backupConfig.provider === 'mountpoint') {
const hostPath = mounts.isManagedProvider(backupConfig.provider) ? paths.MANAGED_BACKUP_MOUNT_DIR : backupConfig.mountPoint;
backupConfig.mountStatus = await mounts.getStatus(backupConfig.provider, hostPath); // { state, message }
}
const backupConfig = JSON.parse(value); // { provider, token, password, region, prefix, bucket }
return backupConfig;
}