UNPKG

balena-cli

Version:

The official balena Command Line Interface

51 lines (47 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const errors_1 = require("../../errors"); const lazy_1 = require("../../utils/lazy"); class GenerateCmd extends core_1.Command { async run() { const { args: params } = await this.parse(GenerateCmd); let key; try { key = await (0, lazy_1.getBalenaSdk)().models.apiKey.create(params.name); } catch (e) { if (e.name === 'BalenaNotLoggedIn') { throw new errors_1.ExpectedError((0, lazy_1.stripIndent) ` This command cannot be run when logged in with an API key. Please login again with 'balena login' and select an alternative method. `); } else { throw e; } } console.log((0, lazy_1.stripIndent) ` Registered api key '${params.name}': ${key} This key will not be shown again, so please save it now. `); } } GenerateCmd.description = (0, lazy_1.stripIndent) ` Generate a new balenaCloud API key. Generate a new balenaCloud API key for the current user, with the given name. The key will be logged to the console. This key can be used to log into the CLI using 'balena login --token <key>', or to authenticate requests to the API with an 'Authorization: Bearer <key>' header. `; GenerateCmd.examples = ['$ balena api-key generate "Jenkins Key"']; GenerateCmd.args = { name: core_1.Args.string({ description: 'the API key name', required: true, }), }; GenerateCmd.authenticated = true; exports.default = GenerateCmd; //# sourceMappingURL=generate.js.map