/
list.go
45 lines (39 loc) · 1.08 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
package vault
import (
"fmt"
"os"
"github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/internal/connector/internal/services/vault"
"github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pkg/environments"
"github.com/golang/glog"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
func NewListCommand(env *environments.Env) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List the vault secrets",
Long: "List the vault secrets",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
err := env.CreateServices()
if err != nil {
glog.Fatalf("Unable to initialize environment: %s", err.Error())
}
},
Run: func(cmd *cobra.Command, args []string) {
env.MustInvoke(runList)
},
}
return cmd
}
func runList(vaultService vault.VaultService) {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Secret Key", "Owning Resource"})
err := vaultService.ForEachSecret(func(key string, owner string) bool {
table.Append([]string{key, owner})
return true
})
if err != nil {
fmt.Println("error:", err)
}
table.Render()
}