forked from kuzzleio/kourou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.ts
44 lines (37 loc) · 1.03 KB
/
create.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { flags } from '@oclif/command'
import { Kommand } from '../../common'
import { kuzzleFlags } from '../../support/kuzzle'
class ApiKeyCreate extends Kommand {
public static description = 'Creates a new API Key for a user';
public static flags = {
help: flags.help(),
description: flags.string({
char: 'd',
description: 'API Key description',
required: true,
}),
id: flags.string({
description: 'API Key unique ID',
}),
expire: flags.string({
description: 'API Key validity',
default: '-1',
}),
...kuzzleFlags,
};
static args = [
{ name: 'user', description: 'User kuid', required: true },
]
async runSafe() {
const apiKey = await this.sdk.security.createApiKey(
this.args.user,
this.flags.description,
{
_id: this.flags.id,
expiresIn: this.flags.expire
})
this.logOk(`Successfully created API Key "${apiKey._id}" for user "${this.args.user}"`)
this.log(apiKey._source.token)
}
}
export default ApiKeyCreate