storage: check volume status

This commit is contained in:
Girish Ramakrishnan
2022-06-03 10:17:34 -07:00
parent 4bee30dd83
commit 7dba294961
2 changed files with 11 additions and 6 deletions

View File

@@ -482,8 +482,6 @@ function validateStorage(volume, prefix) {
assert.strictEqual(typeof volume, 'object');
assert.strictEqual(typeof prefix, 'string');
// TODO: check the volume type
if (path.isAbsolute(prefix)) return new BoxError(BoxError.BAD_FIELD, `prefix "${prefix}" must be a relative path`);
if (prefix.endsWith('/')) return new BoxError(BoxError.BAD_FIELD, `prefix "${prefix}" contains trailing slash`);
if (path.normalize(prefix) !== prefix) return new BoxError(BoxError.BAD_FIELD, `prefix "${prefix}" is not a normalized path`);
@@ -1797,7 +1795,10 @@ async function setStorage(app, volumeId, volumePrefix, auditSource) {
if (volumeId) {
const volume = await volumes.get(volumeId);
if (volume === null) return new BoxError(BoxError.BAD_FIELD, 'Storage volume not found');
if (volume === null) throw new BoxError(BoxError.BAD_FIELD, 'Storage volume not found');
const status = await volumes.getStatus(volume);
if (status.state !== 'active') throw new BoxError(BoxError.BAD_FIELD, 'Volume is not active');
error = validateStorage(volume, volumePrefix);
if (error) throw error;