Add volume management

the volumes table can later have backup flag, mount options etc
This commit is contained in:
Girish Ramakrishnan
2020-10-27 22:39:05 -07:00
parent 03e49c59e2
commit 6a3df679fa
17 changed files with 742 additions and 135 deletions
+6 -10
View File
@@ -30,7 +30,7 @@ exports = module.exports = {
setMailbox,
setLocation,
setDataDir,
setBinds,
setVolumes,
stop,
start,
@@ -766,22 +766,18 @@ function downloadFile(req, res, next) {
});
}
function setBinds(req, res, next) {
function setVolumes(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
assert.strictEqual(typeof req.resource, 'object');
if (!req.body.binds || typeof req.body.binds !== 'object') return next(new HttpError(400, 'binds should be an object'));
for (let name of Object.keys(req.body.binds)) {
if (!req.body.binds[name] || typeof req.body.binds[name] !== 'object') return next(new HttpError(400, 'each bind should be an object'));
if (typeof req.body.binds[name].hostPath !== 'string') return next(new HttpError(400, 'hostPath must be a string'));
if (typeof req.body.binds[name].readOnly !== 'boolean') return next(new HttpError(400, 'readOnly must be a boolean'));
if (Array.isArray(req.body.volumes)) return next(new HttpError(400, 'volumes should be an array'));
for (let v of req.body.volumes) {
if (!v || typeof v !== 'string') return next(new HttpError(400, 'volume must be a non-empty string'));
}
apps.setBinds(req.resource, req.body.binds, auditSource.fromRequest(req), function (error, result) {
apps.setVolume(req.resource, req.body.volumes, auditSource.fromRequest(req), function (error, result) {
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(202, { taskId: result.taskId }));
});
}