-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate.ts
48 lines (37 loc) · 1.19 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
45
46
47
48
import { flags } from "@oclif/command";
import { wrapAction } from "../../utils";
import AuthCommand from "../../auth-command";
import { addToken } from "../../services/nandu.service";
import cli from "cli-ux";
export default class TokenCreate extends AuthCommand {
static description = "create a new token for given user";
static examples = [`$ nandu start -p 4567`];
static flags = {
...AuthCommand.flags,
readonly: flags.boolean({
description: "generate a readonly token",
}),
"cidr-whitelist": flags.string({
description: "comma separated list of whitelisted cidrs",
}),
};
static args = [{ name: "user", required: true }];
async run() {
const { args, flags } = this.parse(this.ctor);
const { opts, password } = await this.getCredentials();
const { "cidr-whitelist": cidrWhitelist } = flags;
wrapAction(cli.action, async () => {
cli.action.start("creating token");
const token = await addToken(
flags.registry,
args.user,
password,
opts,
flags.readonly,
cidrWhitelist
);
cli.action.stop();
console.log(`New token created for user ${args.user}`, token);
});
}
}