-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommand-revoke-token.coffee
42 lines (33 loc) · 1.12 KB
/
command-revoke-token.coffee
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
_ = require 'lodash'
commander = require 'commander'
BaseCommand = require './base-command'
class GenerateToken extends BaseCommand
parseOptions: =>
commander
.usage '[options] <path/to/meshblu.json>'
.option '--token <token>', 'Token'
.option '--tag <tag>', 'Token Tag'
.parse process.argv
@filename = _.first commander.args
@filename ?= "meshblu.json"
@tag = commander.tag
@token = commander.token
@parseConfig()
run: =>
@parseOptions()
return @die new Error "Missing tag or token" unless @tag? or @token?
return @revokeTokenByQuery() if @tag
return @revokeToken() if @token
revokeToken: =>
meshbluHttp = @getMeshbluHttp()
meshbluHttp.revokeToken @config.uuid, @token, (error, data) =>
return @die error if error?
console.log JSON.stringify(data, null, 2)
process.exit 0
revokeTokenByQuery: =>
meshbluHttp = @getMeshbluHttp()
meshbluHttp.revokeTokenByQuery @config.uuid, {@tag}, (error, data) =>
return @die error if error?
console.log 'Tokens deleted.'
process.exit 0
(new GenerateToken()).run()