forked from smallstep/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
65 lines (55 loc) 路 1.4 KB
/
list.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
package provisioner
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/smallstep/cli/crypto/pki"
"github.com/smallstep/cli/errs"
"github.com/urfave/cli"
)
func listCommand() cli.Command {
return cli.Command{
Name: "list",
Action: cli.ActionFunc(listAction),
Usage: "list provisioners configured in the CA",
UsageText: `**step ca provisioner list** [**--ca-url**=<uri>]
[**--root**=<file>]`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "ca-url",
Usage: "<URI> of the targeted Step Certificate Authority.",
},
cli.StringFlag{
Name: "root",
Usage: "The path to the PEM <file> used as the root certificate authority.",
},
},
Description: `**step ca provisioner list** lists the provisioners configured
in the CA.
## EXAMPLES
Prints a JSON list with active provisioners:
'''
$ step ca provisioner list
'''`,
}
}
func listAction(ctx *cli.Context) error {
if err := errs.NumberOfArguments(ctx, 0); err != nil {
return err
}
root := ctx.String("root")
caURL := ctx.String("ca-url")
if len(caURL) == 0 {
return errs.RequiredFlag(ctx, "ca-url")
}
provisioners, err := pki.GetProvisioners(caURL, root)
if err != nil {
return errors.Wrap(err, "error getting the provisioners")
}
b, err := json.MarshalIndent(provisioners, "", " ")
if err != nil {
return errors.Wrap(err, "error marshaling provisioners")
}
fmt.Println(string(b))
return nil
}