diff --git a/CHANGELOG.md b/CHANGELOG.md index 74c6bd4a..645d8fea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v7.3.0 - 2018-04-12 + +* Add 'api-key generate' command #854 [Tim Perry] + ## v7.2.4 - 2018-04-10 * Explicitly depend on tar-stream #852 [Tim Perry] diff --git a/capitanodoc.ts b/capitanodoc.ts index a7457fc7..991c40f4 100644 --- a/capitanodoc.ts +++ b/capitanodoc.ts @@ -63,6 +63,10 @@ environment variable (in the same standard URL format).\ `, categories: [ + { + title: 'Api keys', + files: [ 'build/actions/api-key.js' ], + }, { title: 'Application', files: [ 'build/actions/app.js' ] diff --git a/doc/cli.markdown b/doc/cli.markdown index a0ef074a..84d8f94c 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -62,6 +62,10 @@ environment variable (in the same standard URL format). # Table of contents +- Api keys + + - [api-key generate <name>](#api-key-generate-name-) + - Application - [app create <name>](#app-create-name-) @@ -180,6 +184,20 @@ environment variable (in the same standard URL format). - [util available-drives](#util-available-drives) +# Api keys + +## api-key generate <name> + +This command generates a new 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 'resin login --token ', +or to authenticate requests to the API with an 'Authorization: Bearer ' header. + +Examples: + + $ resin api-key generate "Jenkins Key" + # Application ## app create <name> diff --git a/lib/actions/api-key.ts b/lib/actions/api-key.ts new file mode 100644 index 00000000..e48a7f79 --- /dev/null +++ b/lib/actions/api-key.ts @@ -0,0 +1,36 @@ +import { CommandDefinition } from 'capitano'; +import { stripIndent } from 'common-tags'; + +export const generate: CommandDefinition<{ + name: string; +}> = { + signature: 'api-key generate ', + description: 'Generate a new API key with the given name', + help: stripIndent` + This command generates a new 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 'resin login --token ', + or to authenticate requests to the API with an 'Authorization: Bearer ' header. + + Examples: + + $ resin api-key generate "Jenkins Key" + `, + async action(params, _options, done) { + const resin = (await import('resin-sdk')).fromSharedOptions(); + + resin.models.apiKey + .create(params.name) + .then(key => { + console.log(stripIndent` + Registered api key '${params.name}': + + ${key} + + This key will not be shown again, so please save it now. + `); + }) + .finally(done); + }, +}; diff --git a/lib/actions/index.coffee b/lib/actions/index.coffee index 6137e9f9..b6303e11 100644 --- a/lib/actions/index.coffee +++ b/lib/actions/index.coffee @@ -16,9 +16,10 @@ limitations under the License. module.exports = wizard: require('./wizard') + apiKey: require('./api-key') app: require('./app') - info: require('./info') auth: require('./auth') + info: require('./info') device: require('./device') env: require('./environment-variables') keys: require('./keys') diff --git a/lib/app.coffee b/lib/app.coffee index 4faf13d7..6df8f88b 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -114,11 +114,8 @@ capitano.command(actions.help.help) # ---------- Wizard Module ---------- capitano.command(actions.wizard.wizard) -# ---------- Auth Module ---------- -capitano.command(actions.auth.login) -capitano.command(actions.auth.logout) -capitano.command(actions.auth.signup) -capitano.command(actions.auth.whoami) +# ---------- Api key module ---------- +capitano.command(actions.apiKey.generate) # ---------- App Module ---------- capitano.command(actions.app.create) @@ -127,6 +124,12 @@ capitano.command(actions.app.remove) capitano.command(actions.app.restart) capitano.command(actions.app.info) +# ---------- Auth Module ---------- +capitano.command(actions.auth.login) +capitano.command(actions.auth.logout) +capitano.command(actions.auth.signup) +capitano.command(actions.auth.whoami) + # ---------- Device Module ---------- capitano.command(actions.device.list) capitano.command(actions.device.supported) diff --git a/package.json b/package.json index d8efbe4f..c2f6e9a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "resin-cli", - "version": "7.2.4", + "version": "7.3.0", "description": "The official resin.io CLI tool", "main": "./build/actions/index.js", "homepage": "https://github.com/resin-io/resin-cli", @@ -57,6 +57,7 @@ "devDependencies": { "@types/archiver": "^2.0.1", "@types/bluebird": "^3.5.19", + "@types/common-tags": "^1.4.0", "@types/es6-promise": "0.0.32", "@types/fs-extra": "^5.0.0", "@types/is-root": "^1.0.0", @@ -85,7 +86,6 @@ }, "dependencies": { "@resin.io/valid-email": "^0.1.0", - "@types/stream-to-promise": "^2.2.0", "ansi-escapes": "^2.0.0", "any-promise": "^1.3.0", "archiver": "^2.1.0", @@ -97,6 +97,7 @@ "cli-truncate": "^1.1.0", "coffeescript": "^1.12.6", "columnify": "^1.5.2", + "common-tags": "^1.7.2", "denymount": "^2.2.0", "docker-progress": "^3.0.1", "docker-qemu-transpose": "^0.5.1", @@ -143,7 +144,7 @@ "resin-multibuild": "^0.5.1", "resin-preload": "^6.2.0", "resin-release": "^1.2.0", - "resin-sdk": "9.0.0-beta16", + "resin-sdk": "9.0.0-beta17", "resin-sdk-preconfigured": "^6.9.0", "resin-settings-client": "^3.6.1", "resin-stream-logger": "^0.1.0", @@ -152,7 +153,6 @@ "rindle": "^1.0.0", "semver": "^5.3.0", "split": "^1.0.1", - "stream-to-promise": "^2.2.0", "string-width": "^2.1.1", "strip-ansi-stream": "^1.0.0", "tar-stream": "^1.5.5",