forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate.go
66 lines (54 loc) · 1.47 KB
/
rotate.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
package command
import (
"fmt"
"strings"
)
// RotateCommand is a Command that rotates the encryption key being used
type RotateCommand struct {
Meta
}
func (c *RotateCommand) Run(args []string) int {
flags := c.Meta.FlagSet("rotate", 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
}
// Rotate the key
err = client.Sys().Rotate()
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error with key rotation: %s", err))
return 2
}
// Print the key status
status, err := client.Sys().KeyStatus()
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error reading audits: %s", err))
return 2
}
c.Ui.Output(fmt.Sprintf("Key Term: %d", status.Term))
c.Ui.Output(fmt.Sprintf("Installation Time: %v", status.InstallTime))
return 0
}
func (c *RotateCommand) Synopsis() string {
return "Rotates the backend encryption key used to persist data"
}
func (c *RotateCommand) Help() string {
helpText := `
Usage: vault rotate [options]
Rotates the backend encryption key which is used to secure data
written to the storage backend. This is done by installing a new key
which encrypts new data, while old keys are still used to decrypt
secrets written previously. This is an online operation and is not
disruptive.
General Options:
` + generalOptionsUsage()
return strings.TrimSpace(helpText)
}