Add bootstrap generate-user-token command

Add command to generate a user token for connecting to the master server
web interface.  This servers as an alternative to generating a control
config for use with clusterioctl.
This commit is contained in:
Hornwitser committed 2020-11-08 18:27:24 +01:00
1 parent 325c08389e
commit 6a4875c5ec
3 files changed
+32 -1

No files matched your search

+7
View File
@@ -110,6 +110,13 @@ exist in the cluster and grant it full cluster admin permission. You
should be using your own Factorio multiplayer username here.
#### `bootstrap generate-user-token <name>`
Generate an access token for logging in and possibly managing the
cluster from the given user account. This can be used both in the web
interface and as the `master_token` to connect with clusterioctl.
#### `bootstrap create-ctl-config <name>`
Creates a clusterioctl config for the given user with url and token set
+10
View File
@@ -1578,6 +1578,7 @@ async function startServer() {
.command("bootstrap", "Bootstrap access to cluster", yargs => {
yargs
.command("create-admin <name>", "Create a cluster admin")
.command("generate-user-token <name>", "Generate authentication token for the given user")
.command("create-ctl-config <name>", "Create clusterioctl config for the given user", yargs => {
yargs.option("output", {
describe: "Path to output config (- for stdout)", type: "string",
@@ -1664,6 +1665,15 @@ async function startServer() {
admin.isAdmin = true;
await saveUsers(masterConfig.get("master.database_directory"), "users.json");
} else if (subCommand === "generate-user-token") {
let user = db.users.get(args.name);
if (!user) {
console.error(`No user named '${args.name}'`);
process.exitCode = 1;
return;
}
console.log(user.createToken(masterConfig.get("master.auth_secret")));
} else if (subCommand === "create-ctl-config") {
let admin = db.users.get(args.name);
if (!admin) {
+15 -1
View File
@@ -5,7 +5,7 @@ const path = require("path");
const libLink = require("@clusterio/lib/link");
const { slowTest, get, execCtl, sendRcon, getControl, instancesDir } = require("./index");
const { slowTest, get, exec, execCtl, sendRcon, getControl, instancesDir } = require("./index");
async function getInstances() {
@@ -19,6 +19,20 @@ async function checkInstanceStatus(id, status) {
}
describe("Integration of Clusterio", function() {
describe("clusteriomaster", function() {
describe("bootstrap generate-user-token", function() {
it("work for existing user", async function() {
await exec("node ../../packages/master bootstrap generate-user-token test");
});
it("fails if user does not exist", async function() {
await assert.rejects(
exec("node ../../packages/master bootstrap generate-user-token invalid")
);
});
});
});
describe("clusterioctl", function() {
describe("slave list", function() {
it("runs", async function() {