From 7797ee708ac91207ae8c362f92540dd711a2682b Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 1 Mar 2021 15:02:28 +0100 Subject: [PATCH] Add ctl master plugin list command Add command to list the plugins enabled on the master server and their versions to clusterioctl. --- CHANGELOG.md | 1 + packages/ctl/ctl.js | 29 +++++++++++++++++++++++++++-- packages/ctl/package.json | 1 + test/integration/clusterio.js | 6 ++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e05e4b71..c5827ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Version 2.0.0 - Added option to configure timeout for exported Prometheus metrics. - Added option to set address to bind HTTP(S) port to. - Added an overview of the installed plugins to the web interface. +- Added clusterioctl command to list plugins on the master server. ### Changes diff --git a/packages/ctl/ctl.js b/packages/ctl/ctl.js index 449ac26f..693d29df 100755 --- a/packages/ctl/ctl.js +++ b/packages/ctl/ctl.js @@ -13,6 +13,7 @@ const events = require("events"); const path = require("path"); const winston = require("winston"); const setBlocking = require("set-blocking"); +const phin = require("phin"); const libLink = require("@clusterio/lib/link"); const libErrors = require("@clusterio/lib/errors"); @@ -104,6 +105,25 @@ masterConfigCommands.add(new libCommand.Command({ masterCommands.add(masterConfigCommands); +const masterPluginCommands = new libCommand.CommandTree({ + name: "plugin", alias: ["p"], description: "master plugin inspection", +}); +masterPluginCommands.add(new libCommand.Command({ + definition: ["list", "List plugins on master"], + handler: async function(args, control) { + let url = new URL(control.config.get("control.master_url")); + url.pathname += "api/plugins"; + let response = await phin({ + url, + parse: "json", + core: { ca: control.tlsCa }, + }); + print(asTable(response.body)); + }, +})); +masterCommands.add(masterPluginCommands); + + const slaveCommands = new libCommand.CommandTree({ name: "slave", description: "Slave management" }); slaveCommands.add(new libCommand.Command({ definition: [["list", "l"], "List slaves connected to the master"], @@ -698,10 +718,15 @@ class ControlConnector extends libLink.WebSocketClientConnector { */ class Control extends libLink.Link { - constructor(connector, tlsCa, controlPlugins) { + constructor(connector, controlConfig, tlsCa, controlPlugins) { super("control", "master", connector); libLink.attachAllMessages(this); + /** + * Control config used for connecting to the master. + * @type {module:lib/config.ControlConfig} + */ + this.config = controlConfig; /** * Certificate authority used to validate TLS connections to the master. * @type {?string} @@ -922,7 +947,7 @@ async function startControl() { tlsCa, controlConfig.get("control.master_token") ); - let control = new Control(controlConnector, tlsCa, controlPlugins); + let control = new Control(controlConnector, controlConfig, tlsCa, controlPlugins); try { await controlConnector.connect(); } catch (err) { diff --git a/packages/ctl/package.json b/packages/ctl/package.json index 71f3f455..2664c621 100644 --- a/packages/ctl/package.json +++ b/packages/ctl/package.json @@ -22,6 +22,7 @@ "as-table": "^1.0.31", "chalk": "^3.0.0", "fs-extra": "^8.1.0", + "phin": "^3.5.1", "winston": "^3.3.3", "yargs": "^14.2.0" }, diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index 8d3be325..47050662 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -71,6 +71,12 @@ describe("Integration of Clusterio", function() { }); }); + describe("master plugin list", function() { + it("runs", async function() { + await execCtl("master plugin list"); + }); + }); + describe("slave list", function() { it("runs", async function() { await execCtl("slave list");