From 59d4890eae438886cdaf2a187dee00efb2358e93 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 4 Apr 2018 14:42:57 +0200 Subject: [PATCH 1/5] Add 'api-key generate' command Change-Type: minor --- capitanodoc.ts | 4 ++++ doc/cli.markdown | 20 ++++++++++++++++++++ lib/actions/api-key.ts | 27 +++++++++++++++++++++++++++ lib/actions/index.coffee | 3 ++- lib/app.coffee | 13 ++++++++----- package.json | 2 +- 6 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 lib/actions/api-key.ts 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..ee456355 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,22 @@ 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..c33cf229 --- /dev/null +++ b/lib/actions/api-key.ts @@ -0,0 +1,27 @@ +import { CommandDefinition } from 'capitano'; + +export const generate: CommandDefinition<{ + name: string; +}> = { + signature: 'api-key generate ', + description: 'Generate a new API key with the given name', + help: ` +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(`Registered api key '${params.name}':\n${key}`); + 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..d4f5a9fe 100644 --- a/package.json +++ b/package.json @@ -143,7 +143,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", From e0bcb5e0b9a4136aa4676fa2755dba70f8a969b3 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 11 Apr 2018 19:27:58 +0200 Subject: [PATCH 2/5] Always call done() for api key generation, not just if we're successful --- lib/actions/api-key.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/actions/api-key.ts b/lib/actions/api-key.ts index c33cf229..c1df2cb3 100644 --- a/lib/actions/api-key.ts +++ b/lib/actions/api-key.ts @@ -21,7 +21,6 @@ Examples: resin.models.apiKey.create(params.name).then(key => { console.log(`Registered api key '${params.name}':\n${key}`); - done(); - }); + }).finally(done); }, }; From 0e5f2fe748477b98da02f2b0f968b9565e937abc Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 11 Apr 2018 19:30:29 +0200 Subject: [PATCH 3/5] Remove now-unused stream-to-promise dependency --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index d4f5a9fe..3da86d8f 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,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", @@ -152,7 +151,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", From 834a2f1e4d7d434b1c18c89c2acdcdaf12d87622 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 11 Apr 2018 19:31:03 +0200 Subject: [PATCH 4/5] Warn user that api keys will not be shown again in future --- doc/cli.markdown | 4 +--- lib/actions/api-key.ts | 32 +++++++++++++++++++++----------- package.json | 2 ++ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/doc/cli.markdown b/doc/cli.markdown index ee456355..84d8f94c 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -188,7 +188,6 @@ environment variable (in the same standard URL format). ## 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. @@ -197,8 +196,7 @@ or to authenticate requests to the API with an 'Authorization: Bearer ' hea Examples: - $ resin api-key generate "Jenkins Key" - + $ resin api-key generate "Jenkins Key" # Application diff --git a/lib/actions/api-key.ts b/lib/actions/api-key.ts index c1df2cb3..e48a7f79 100644 --- a/lib/actions/api-key.ts +++ b/lib/actions/api-key.ts @@ -1,26 +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: ` -This command generates a new API key for the current user, with the given -name. The key will be logged to the console. + 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. + 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: + Examples: - $ resin api-key generate "Jenkins Key" -`, + $ 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(`Registered api key '${params.name}':\n${key}`); - }).finally(done); + 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/package.json b/package.json index 3da86d8f..70d8c52c 100644 --- a/package.json +++ b/package.json @@ -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", @@ -96,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", From d7616e941a4fbbba812e4b5eb63dbab2a8500e26 Mon Sep 17 00:00:00 2001 From: "resin-io-versionbot[bot]" Date: Thu, 12 Apr 2018 10:06:09 +0000 Subject: [PATCH 5/5] v7.3.0 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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/package.json b/package.json index 70d8c52c..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",