-
Notifications
You must be signed in to change notification settings - Fork 0
/
kms.go
49 lines (41 loc) · 931 Bytes
/
kms.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
package commands
import (
"fmt"
cli "gopkg.in/urfave/cli.v1"
)
// KMSCmds - manage padl-managed public keys
var KMSCmds = cli.Command{
Name: "kms",
Aliases: []string{"k"},
Usage: "Inspect padl-managed public keys",
Subcommands: []cli.Command{
{
Name: "public",
Usage: "get an RSA public key for inspection",
Flags: []cli.Flag{
jsonFlag,
asMandatory(idFlag),
},
Before: publicKeyValidator,
Action: publicKeyHandler,
},
},
}
func publicKeyValidator(ctx *cli.Context) error {
return assertSet(ctx, idFlag)
}
func publicKeyHandler(ctx *cli.Context) error {
c, err := getClient(ctx)
if err != nil {
return fmt.Errorf("could not initialize client: %s", err)
}
k, err := c.GetPublicKey(ctx.String(name(idFlag)))
if err != nil {
return fmt.Errorf("could not get public key: %s", err)
}
if ctx.Bool(name(jsonFlag)) {
return printJSON(&k)
}
fmt.Println(k.PEM)
return nil
}