From de2cf8aeaa69f2566c3f8381b5ba1beab0b13f58 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 21 Nov 2023 14:07:20 +0100 Subject: [PATCH] feat(xo-cli): support REST PUT method --- CHANGELOG.unreleased.md | 1 + packages/xo-cli/.USAGE.md | 13 +++++++++++++ packages/xo-cli/README.md | 13 +++++++++++++ packages/xo-cli/index.mjs | 13 +++++++++++++ packages/xo-cli/rest.mjs | 12 ++++++++++++ 5 files changed, 52 insertions(+) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 6ad2b556ea0..9a00980155a 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -42,6 +42,7 @@ - @xen-orchestra/cr-seed-cli major - @xen-orchestra/vmware-explorer patch - xen-api major +- xo-cli minor - xo-server minor - xo-server-netbox minor - xo-vmdk-to-vhd patch diff --git a/packages/xo-cli/.USAGE.md b/packages/xo-cli/.USAGE.md index 5c0230ad87d..1ef30ef7df4 100644 --- a/packages/xo-cli/.USAGE.md +++ b/packages/xo-cli/.USAGE.md @@ -50,6 +50,7 @@ Usage: Examples: xo-cli rest del tasks/ + xo-cli rest del vms//tags/ xo-cli rest get [fields=] [filter=] [limit=] List objects in a REST API collection. @@ -122,6 +123,18 @@ Usage: Examples: xo-cli rest post tasks//actions/abort xo-cli rest post vms//actions/snapshot name_label='My snapshot' + + xo-cli rest put / =... + Put a item in a collection + + / + Full path of the item to add + + =... + Properties of the item + + Examples: + xo-cli rest put vms//tags/ ``` #### Register your XO instance diff --git a/packages/xo-cli/README.md b/packages/xo-cli/README.md index 1a57f9082b3..62ef51d74c7 100644 --- a/packages/xo-cli/README.md +++ b/packages/xo-cli/README.md @@ -68,6 +68,7 @@ Usage: Examples: xo-cli rest del tasks/ + xo-cli rest del vms//tags/ xo-cli rest get [fields=] [filter=] [limit=] List objects in a REST API collection. @@ -140,6 +141,18 @@ Usage: Examples: xo-cli rest post tasks//actions/abort xo-cli rest post vms//actions/snapshot name_label='My snapshot' + + xo-cli rest put / =... + Put a item in a collection + + / + Full path of the item to add + + =... + Properties of the item + + Examples: + xo-cli rest put vms//tags/ ``` #### Register your XO instance diff --git a/packages/xo-cli/index.mjs b/packages/xo-cli/index.mjs index bc1ec933be1..64800d74d82 100755 --- a/packages/xo-cli/index.mjs +++ b/packages/xo-cli/index.mjs @@ -274,6 +274,7 @@ const help = wrap( Examples: $name rest del tasks/ + $name rest del vms//tags/ $name rest get [fields=] [filter=] [limit=] List objects in a REST API collection. @@ -347,6 +348,18 @@ const help = wrap( $name rest post tasks//actions/abort $name rest post vms//actions/snapshot name_label='My snapshot' + $name rest put / =... + Put a item in a collection + + / + Full path of the item to add + + =... + Properties of the item + + Examples: + $name rest put vms//tags/ + $name v$version`.replace(/<([^>]+)>|\$(\w+)/g, function (_, arg, key) { if (arg) { return '<' + chalk.yellow(arg) + '>' diff --git a/packages/xo-cli/rest.mjs b/packages/xo-cli/rest.mjs index 18780c71052..65117f17d13 100644 --- a/packages/xo-cli/rest.mjs +++ b/packages/xo-cli/rest.mjs @@ -112,6 +112,18 @@ const COMMANDS = { return stripPrefix(await response.text()) }, + + async put([path, ...params]) { + const response = await this.exec(path, { + body: JSON.stringify(parseParams(params)), + headers: { + 'content-type': 'application/json', + }, + method: 'PUT', + }) + + return stripPrefix(await response.text()) + }, } export async function rest(args) {