mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-01-18 10:46:34 +00:00
Add 'api-key generate' command
Change-Type: minor
This commit is contained in:
parent
51da5360da
commit
59d4890eae
@ -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' ]
|
||||
|
@ -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 <key>',
|
||||
or to authenticate requests to the API with an 'Authorization: Bearer <key>' header.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin api-key generate "Jenkins Key"
|
||||
|
||||
|
||||
# Application
|
||||
|
||||
## app create <name>
|
||||
|
27
lib/actions/api-key.ts
Normal file
27
lib/actions/api-key.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { CommandDefinition } from 'capitano';
|
||||
|
||||
export const generate: CommandDefinition<{
|
||||
name: string;
|
||||
}> = {
|
||||
signature: 'api-key generate <name>',
|
||||
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 <key>',
|
||||
or to authenticate requests to the API with an 'Authorization: Bearer <key>' 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();
|
||||
});
|
||||
},
|
||||
};
|
@ -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')
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user