From 921c700fab9a0eb85f26be11765465640cc6e27f Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Sun, 12 Mar 2023 23:24:10 +0100 Subject: [PATCH] fix(xo-server/api): description params can be empty Fixes #6721 Introduced by d6a3492e9 --- packages/xo-server-sdn-controller/src/index.js | 2 +- packages/xo-server/src/api/disk.mjs | 2 +- packages/xo-server/src/api/host.mjs | 1 + packages/xo-server/src/api/network.mjs | 5 +++-- packages/xo-server/src/api/pool.mjs | 1 + packages/xo-server/src/api/sr.mjs | 16 ++++++++-------- packages/xo-server/src/api/token.mjs | 2 +- packages/xo-server/src/api/vdi.mjs | 2 +- packages/xo-server/src/api/vm.mjs | 6 +++--- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/packages/xo-server-sdn-controller/src/index.js b/packages/xo-server-sdn-controller/src/index.js index 694d09399..24a6ee0d5 100644 --- a/packages/xo-server-sdn-controller/src/index.js +++ b/packages/xo-server-sdn-controller/src/index.js @@ -382,7 +382,7 @@ class SDNController extends EventEmitter { }, }, name: { type: 'string' }, - description: { type: 'string' }, + description: { type: 'string', minLength: 0 }, encapsulation: { type: 'string' }, encrypted: { type: 'boolean', optional: true }, mtu: { type: 'integer', optional: true }, diff --git a/packages/xo-server/src/api/disk.mjs b/packages/xo-server/src/api/disk.mjs index d158ddfc0..73f871357 100644 --- a/packages/xo-server/src/api/disk.mjs +++ b/packages/xo-server/src/api/disk.mjs @@ -270,7 +270,7 @@ async function importDisk({ sr, type, name, description, vmdkData }) { export { importDisk as import } importDisk.params = { - description: { type: 'string', optional: true }, + description: { type: 'string', minLength: 0, optional: true }, name: { type: 'string' }, sr: { type: 'string' }, type: { type: 'string' }, diff --git a/packages/xo-server/src/api/host.mjs b/packages/xo-server/src/api/host.mjs index 794b23fab..bd4f8dbdc 100644 --- a/packages/xo-server/src/api/host.mjs +++ b/packages/xo-server/src/api/host.mjs @@ -102,6 +102,7 @@ set.params = { }, name_description: { type: 'string', + minLength: 0, optional: true, }, multipathing: { diff --git a/packages/xo-server/src/api/network.mjs b/packages/xo-server/src/api/network.mjs index c4732a32f..196a6e8bc 100644 --- a/packages/xo-server/src/api/network.mjs +++ b/packages/xo-server/src/api/network.mjs @@ -24,7 +24,7 @@ create.params = { pool: { type: 'string' }, name: { type: 'string' }, nbd: { type: 'boolean', optional: true }, - description: { type: 'string', optional: true }, + description: { type: 'string', minLength: 0, optional: true }, pif: { type: 'string', optional: true }, mtu: { type: ['integer', 'string'], optional: true }, vlan: { type: ['integer', 'string'], optional: true }, @@ -49,7 +49,7 @@ export async function createBonded({ pool, name, description, pifs, mtu = 1500, createBonded.params = { pool: { type: 'string' }, name: { type: 'string' }, - description: { type: 'string', optional: true }, + description: { type: 'string', minLength: 0, optional: true }, pifs: { type: 'array', items: { @@ -105,6 +105,7 @@ set.params = { }, name_description: { type: 'string', + minLength: 0, optional: true, }, name_label: { diff --git a/packages/xo-server/src/api/pool.mjs b/packages/xo-server/src/api/pool.mjs index 7cb55c080..277c856ef 100644 --- a/packages/xo-server/src/api/pool.mjs +++ b/packages/xo-server/src/api/pool.mjs @@ -45,6 +45,7 @@ set.params = { }, name_description: { type: 'string', + minLength: 0, optional: true, }, backupNetwork: { diff --git a/packages/xo-server/src/api/sr.mjs b/packages/xo-server/src/api/sr.mjs index 4bfa80a93..98d30206b 100644 --- a/packages/xo-server/src/api/sr.mjs +++ b/packages/xo-server/src/api/sr.mjs @@ -29,7 +29,7 @@ set.params = { name_label: { type: 'string', optional: true }, - name_description: { type: 'string', optional: true }, + name_description: { type: 'string', minLength: 0, optional: true }, } set.resolve = { @@ -187,7 +187,7 @@ export async function createIso({ createIso.params = { host: { type: 'string' }, nameLabel: { type: 'string' }, - nameDescription: { type: 'string' }, + nameDescription: { type: 'string', minLength: 0 }, path: { type: 'string' }, type: { type: 'string' }, user: { type: 'string', optional: true }, @@ -260,7 +260,7 @@ export async function createNfs({ createNfs.params = { host: { type: 'string' }, nameLabel: { type: 'string' }, - nameDescription: { type: 'string' }, + nameDescription: { type: 'string', minLength: 0 }, server: { type: 'string' }, serverPath: { type: 'string' }, nfsVersion: { type: 'string', optional: true }, @@ -311,7 +311,7 @@ export async function createHba({ host, nameLabel, nameDescription, scsiId, srUu createHba.params = { host: { type: 'string' }, nameLabel: { type: 'string' }, - nameDescription: { type: 'string' }, + nameDescription: { type: 'string', minLength: 0 }, scsiId: { type: 'string' }, srUuid: { type: 'string', optional: true }, } @@ -348,7 +348,7 @@ export async function createLvm({ host, nameLabel, nameDescription, device }) { createLvm.params = { host: { type: 'string' }, nameLabel: { type: 'string' }, - nameDescription: { type: 'string' }, + nameDescription: { type: 'string', minLength: 0 }, device: { type: 'string' }, } @@ -384,7 +384,7 @@ export async function createExt({ host, nameLabel, nameDescription, device }) { createExt.params = { host: { type: 'string' }, nameLabel: { type: 'string' }, - nameDescription: { type: 'string' }, + nameDescription: { type: 'string', minLength: 0 }, device: { type: 'string' }, } @@ -456,7 +456,7 @@ export async function createZfs({ host, nameLabel, nameDescription, location }) createZfs.params = { host: { type: 'string' }, nameLabel: { type: 'string' }, - nameDescription: { type: 'string' }, + nameDescription: { type: 'string', minLength: 0 }, location: { type: 'string' }, } @@ -616,7 +616,7 @@ export async function createIscsi({ createIscsi.params = { host: { type: 'string' }, nameLabel: { type: 'string' }, - nameDescription: { type: 'string' }, + nameDescription: { type: 'string', minLength: 0 }, target: { type: 'string' }, port: { type: 'integer', optional: true }, targetIqn: { type: 'string' }, diff --git a/packages/xo-server/src/api/token.mjs b/packages/xo-server/src/api/token.mjs index de363074d..2cf1a2a51 100644 --- a/packages/xo-server/src/api/token.mjs +++ b/packages/xo-server/src/api/token.mjs @@ -47,6 +47,6 @@ export async function set({ id, ...props }) { set.description = 'changes the properties of an existing token' set.params = { - description: { type: ['null', 'string'], optional: true }, + description: { type: ['null', 'string'], minLength: 0, optional: true }, id: { type: 'string' }, } diff --git a/packages/xo-server/src/api/vdi.mjs b/packages/xo-server/src/api/vdi.mjs index 02a77030e..82245182e 100644 --- a/packages/xo-server/src/api/vdi.mjs +++ b/packages/xo-server/src/api/vdi.mjs @@ -90,7 +90,7 @@ set.params = { name_label: { type: 'string', optional: true }, - name_description: { type: 'string', optional: true }, + name_description: { type: 'string', minLength: 0, optional: true }, // size of VDI size: { type: ['integer', 'string'], optional: true }, diff --git a/packages/xo-server/src/api/vm.mjs b/packages/xo-server/src/api/vm.mjs index 5d5ebee99..30fc1620e 100644 --- a/packages/xo-server/src/api/vm.mjs +++ b/packages/xo-server/src/api/vm.mjs @@ -300,7 +300,7 @@ create.params = { // Name/description of the new VM. name_label: { type: 'string' }, - name_description: { type: 'string', optional: true }, + name_description: { type: 'string', minLength: 0, optional: true }, // PV Args pv_args: { type: 'string', optional: true }, @@ -668,7 +668,7 @@ set.params = { name_label: { type: 'string', optional: true }, - name_description: { type: 'string', optional: true }, + name_description: { type: 'string', minLength: 0, optional: true }, high_availability: { optional: true, @@ -954,7 +954,7 @@ export const snapshot = defer(async function ( }) snapshot.params = { - description: { type: 'string', optional: true }, + description: { type: 'string', minLength: 0, optional: true }, id: { type: 'string' }, name: { type: 'string', optional: true }, saveMemory: { type: 'boolean', optional: true },