forked from aditosoftware/nodepki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodepkictl.js
56 lines (50 loc) · 1.52 KB
/
nodepkictl.js
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
49
50
51
52
53
54
55
56
/*
* NodePKI management tool
*/
var log = require('fancy-log');
var yargs = require('yargs');
var auth = require('./auth.js');
/**
* Register subcommands
*/
var argv = yargs
.usage("Usage: $0 <subcommand> [options]")
.command("useradd", "Create a new API user", function(yargs){
var argv = yargs
.option('username', {
demand: true,
describe: "Username for new user",
type: "string"
})
.option('password', {
demand: true,
describe: "Password for new user",
type: "string"
})
.example("$0 useradd --username thomas --password thomaspassword")
.argv;
if(auth.addUser(argv.username, argv.password)) {
log("User created successfully.");
} else {
log("Error: Username already exists!");
}
})
.command("userdel", "Delete existing API user", function(yargs){
var argv = yargs
.option('username', {
demand: true,
describe: "Username for new user",
type: "string"
})
.example("$0 userdel --username thomas")
.argv;
if(auth.delUser(argv.username)) {
log("User deleted successfully.");
} else {
log("Error: Username does not exist!");
}
})
.demandCommand(1)
.help("h")
.alias("h", "help")
.argv