/
erase.go
41 lines (33 loc) 路 852 Bytes
/
erase.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
package cmd
import (
"os"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
// eraseCmd represents the erase command
var eraseCmd = &cobra.Command{
Use: "erase",
Short: "(For use by vault) Erase the stored token for the current $VAULT_ADDR",
SilenceUsage: true, // Don't show help on error, just print the error
RunE: func(cmd *cobra.Command, args []string) error {
if err := initBackend(); err != nil {
return err
}
vaultAddr := os.Getenv("VAULT_ADDR")
if vaultAddr == "" {
return errors.New("Missing VAULT_ADDR environment variable")
}
vaultNamespace := os.Getenv("VAULT_NAMESPACE")
if vaultNamespace != "" {
vaultAddr += "/"
vaultAddr += vaultNamespace
}
if err := backend.Erase(vaultAddr); err != nil {
return err
}
return nil
},
}
func init() {
RootCmd.AddCommand(eraseCmd)
}