-
Notifications
You must be signed in to change notification settings - Fork 300
/
showkey.go
75 lines (59 loc) · 1.18 KB
/
showkey.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package command
import (
"encoding/json"
"fmt"
"strings"
"github.com/koding/kite/kitekey"
"github.com/mitchellh/cli"
)
var tokenKeyOrder = []string{
"sub", // subject
"iss", // issuer
"kontrolURL", // kontrol url
"aud", // audience
"iat", // issued at
"jti", // JWT ID
"kontrolKey", // kontrol public key
}
func toObject(v interface{}) (m map[string]interface{}) {
p, err := json.Marshal(v)
if err != nil {
panic(err)
}
if err := json.Unmarshal(p, &m); err != nil {
panic(err)
}
return m
}
type Showkey struct {
Ui cli.Ui
}
func NewShowkey() cli.CommandFactory {
return func() (cli.Command, error) {
return &Showkey{
Ui: DefaultUi,
}, nil
}
}
func (c *Showkey) Synopsis() string {
return "Shows the registration key"
}
func (c *Showkey) Help() string {
helpText := `
Usage: kitectl showkey
Shows the registration key.
`
return strings.TrimSpace(helpText)
}
func (c *Showkey) Run(_ []string) int {
token, err := kitekey.Parse()
if err != nil {
c.Ui.Error(err.Error())
return 1
}
claims := toObject(token.Claims)
for _, v := range tokenKeyOrder {
c.Ui.Output(fmt.Sprintf("%-15s%+v", v, claims[v]))
}
return 0
}