From 6928b5a8a622e8845fb6d2f6d3d9bf02b5578e1f Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Sun, 21 Jul 2019 10:42:35 -0600 Subject: [PATCH] Add token command --- server/commands/token.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 server/commands/token.ts diff --git a/server/commands/token.ts b/server/commands/token.ts new file mode 100644 index 0000000..ff46aac --- /dev/null +++ b/server/commands/token.ts @@ -0,0 +1,32 @@ +import { flags } from "@oclif/command"; +import * as auth from "@server/authentication" + +import ManageCommand from "@server/ManageCommand"; + +// tslint:disable:no-shadowed-variable + +export default class TokenCommand extends ManageCommand { + static description = "Manage tokens"; + + static flags = { + "gen-device-reg": flags.boolean({ + char: "d", + description: "Generate a device registration token", + }), + }; + + async run() { + const parseResult = this.parse(TokenCommand); + + const flags = parseResult.flags; + + if (flags["gen-device-reg"]) { + const token = await auth.generateDeviceRegistrationToken(); + this.log(`Device registration token: "${token}"`) + } else { + this.error("Must specify a command to run"); + this._help(); + } + + } +}