forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audit_list.go
84 lines (67 loc) · 1.82 KB
/
audit_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package command
import (
"fmt"
"sort"
"strings"
"github.com/ryanuber/columnize"
)
// AuditListCommand is a Command that lists the enabled audits.
type AuditListCommand struct {
Meta
}
func (c *AuditListCommand) Run(args []string) int {
flags := c.Meta.FlagSet("audit-list", FlagSetDefault)
flags.Usage = func() { c.Ui.Error(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
}
client, err := c.Client()
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error initializing client: %s", err))
return 2
}
audits, err := client.Sys().ListAudit()
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error reading audits: %s", err))
return 2
}
if len(audits) == 0 {
c.Ui.Error(fmt.Sprintf(
"No audit backends are enabled. Use `vault audit-enable` to\n" +
"enable an audit backend."))
return 1
}
paths := make([]string, 0, len(audits))
for path, _ := range audits {
paths = append(paths, path)
}
sort.Strings(paths)
columns := []string{"Type | Description | Options"}
for _, path := range paths {
audit := audits[path]
opts := make([]string, 0, len(audit.Options))
for k, v := range audit.Options {
opts = append(opts, k+"="+v)
}
columns = append(columns, fmt.Sprintf(
"%s | %s | %s", audit.Type, audit.Description, strings.Join(opts, " ")))
}
c.Ui.Output(columnize.SimpleFormat(columns))
return 0
}
func (c *AuditListCommand) Synopsis() string {
return "Lists enabled audit backends in Vault"
}
func (c *AuditListCommand) Help() string {
helpText := `
Usage: vault audit-list [options]
List the enabled audit backends.
The output lists the enabled audit backends and the options for those
backends. The options may contain sensitive information, and therefore
only a root Vault user can view this.
General Options:
` + generalOptionsUsage()
return strings.TrimSpace(helpText)
}