diff --git a/src/routes/volumes.js b/src/routes/volumes.js index f2519dcca..f2e2b0808 100644 --- a/src/routes/volumes.js +++ b/src/routes/volumes.js @@ -6,7 +6,7 @@ exports = module.exports = { del, list, load, - setMountConfig, + update, getMountStatus }; @@ -61,13 +61,13 @@ async function list(req, res, next) { next(new HttpSuccess(200, { volumes: result })); } -async function setMountConfig(req, res, next) { +async function update(req, res, next) { assert.strictEqual(typeof req.params.id, 'string'); if (typeof req.body.mountType !== 'string') return next(new HttpError(400, 'mountType must be a string')); if (typeof req.body.mountOptions !== 'object') return next(new HttpError(400, 'mountOptions must be a object')); - const [error] = await safe(volumes.setMountConfig(req.resource, req.body.mountType, req.body.mountOptions)); + const [error] = await safe(volumes.update(req.resource, req.body.mountType, req.body.mountOptions)); if (error) return next(BoxError.toHttpError(error)); next(new HttpSuccess(200, {})); } diff --git a/src/server.js b/src/server.js index f60282754..3d40d62f9 100644 --- a/src/server.js +++ b/src/server.js @@ -310,7 +310,7 @@ function initializeExpressSync() { router.get ('/api/v1/volumes', token, authorizeAdmin, routes.volumes.list); router.get ('/api/v1/volumes/:id', token, authorizeAdmin, routes.volumes.load, routes.volumes.get); router.del ('/api/v1/volumes/:id', token, authorizeAdmin, routes.volumes.load, routes.volumes.del); - router.post('/api/v1/volumes/:id/mount_config', token, authorizeAdmin, routes.volumes.load, routes.volumes.setMountConfig); + router.post('/api/v1/volumes/:id', json, token, authorizeAdmin, routes.volumes.load, routes.volumes.update); router.get ('/api/v1/volumes/:id/mount_status', token, authorizeAdmin, routes.volumes.load, routes.volumes.getMountStatus); router.use ('/api/v1/volumes/:id/files/*', token, authorizeAdmin, routes.filemanager.proxy); diff --git a/src/volumes.js b/src/volumes.js index a12c9184b..7eaf3a89a 100644 --- a/src/volumes.js +++ b/src/volumes.js @@ -5,7 +5,7 @@ exports = module.exports = { get, del, list, - setMountConfig, + update, getMountStatus, }; @@ -136,7 +136,7 @@ async function removeMountFile(volume) { await safe(shell.promises.sudo('generateMountFile', [ RM_MOUNT_CMD, volume.hostPath ], {})); // ignore any error } -async function setMountConfig(volume, mountType, mountOptions) { +async function update(volume, mountType, mountOptions) { assert.strictEqual(typeof volume, 'object'); assert.strictEqual(typeof mountType, 'string'); assert.strictEqual(typeof mountOptions, 'object'); @@ -144,8 +144,14 @@ async function setMountConfig(volume, mountType, mountOptions) { let error = validateMountOptions(mountType, mountOptions); if (error) throw error; + if (mountType === 'noop') { + await safe(removeMountFile(Object.assign({}, volume, { mountType, mountOptions }))); + } else { + await safe(writeMountFile(Object.assign({}, volume, { mountType, mountOptions }))); + } + let result; - [error, result] = await safe(database.query('UPDATE volumes SET mountType=? AND mountOptionsJson=? WHERE id=?', [ mountType, JSON.stringify(mountOptions), volume.id ])); + [error, result] = await safe(database.query('UPDATE volumes SET mountType=?, mountOptionsJson=? WHERE id=?', [ mountType, JSON.stringify(mountOptions), volume.id ])); if (error) throw error; if (result.affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'Volume not found'); }