forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remount.go
73 lines (56 loc) · 1.5 KB
/
remount.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
package command
import (
"fmt"
"strings"
)
// RemountCommand is a Command that remounts a mounted secret backend
// to a new endpoint.
type RemountCommand struct {
Meta
}
func (c *RemountCommand) Run(args []string) int {
flags := c.Meta.FlagSet("remount", FlagSetDefault)
flags.Usage = func() { c.Ui.Error(c.Help()) }
if err := flags.Parse(args); err != nil {
return 1
}
args = flags.Args()
if len(args) != 2 {
flags.Usage()
c.Ui.Error(fmt.Sprintf(
"\nRemount expects two arguments: the from and to path"))
return 1
}
from := args[0]
to := args[1]
client, err := c.Client()
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error initializing client: %s", err))
return 2
}
if err := client.Sys().Remount(from, to); err != nil {
c.Ui.Error(fmt.Sprintf(
"Unmount error: %s", err))
return 2
}
c.Ui.Output(fmt.Sprintf(
"Successfully remounted from '%s' to '%s'!", from, to))
return 0
}
func (c *RemountCommand) Synopsis() string {
return "Remount a secret backend to a new path"
}
func (c *RemountCommand) Help() string {
helpText := `
Usage: vault remount [options] from to
Remount a mounted secret backend to a new path.
This command remounts a secret backend that is already mounted to
a new path. All the secrets from the old path will be revoked, but
the Vault data associated with the backend will be preserved (such
as configuration data).
Example: vault remount secret/ generic/
General Options:
` + generalOptionsUsage()
return strings.TrimSpace(helpText)
}