44package command
55
66import (
7+ "context"
78 "fmt"
89 "strings"
910
1920
2021type PluginReloadCommand struct {
2122 * BaseCommand
22- plugin string
23- mounts []string
24- scope string
23+ plugin string
24+ mounts []string
25+ scope string
26+ pluginType string
2527}
2628
2729func (c * PluginReloadCommand ) Synopsis () string {
@@ -36,9 +38,16 @@ Usage: vault plugin reload [options]
3638 mount(s) must be provided, but not both. In case the plugin name is provided,
3739 all of its corresponding mounted paths that use the plugin backend will be reloaded.
3840
39- Reload the plugin named "my-custom-plugin":
41+ If run with a Vault namespace other than the root namespace, only plugins
42+ running in the same namespace will be reloaded.
4043
41- $ vault plugin reload -plugin=my-custom-plugin
44+ Reload the secret plugin named "my-custom-plugin" on the current node:
45+
46+ $ vault plugin reload -type=secret -plugin=my-custom-plugin
47+
48+ Reload the secret plugin named "my-custom-plugin" across all nodes and replicated clusters:
49+
50+ $ vault plugin reload -type=secret -plugin=my-custom-plugin -scope=global
4251
4352` + c .Flags ().Help ()
4453
@@ -68,7 +77,15 @@ func (c *PluginReloadCommand) Flags() *FlagSets {
6877 Name : "scope" ,
6978 Target : & c .scope ,
7079 Completion : complete .PredictAnything ,
71- Usage : "The scope of the reload, omitted for local, 'global', for replicated reloads" ,
80+ Usage : "The scope of the reload, omitted for local, 'global', for replicated reloads." ,
81+ })
82+
83+ f .StringVar (& StringVar {
84+ Name : "type" ,
85+ Target : & c .pluginType ,
86+ Completion : complete .PredictAnything ,
87+ Usage : "The type of plugin to reload, one of auth, secret, or database. Mutually " +
88+ "exclusive with -mounts. If not provided, all plugins with a matching name will be reloaded." ,
7289 })
7390
7491 return set
@@ -103,6 +120,10 @@ func (c *PluginReloadCommand) Run(args []string) int {
103120 return 1
104121 case c .scope != "" && c .scope != "global" :
105122 c .UI .Error (fmt .Sprintf ("Invalid reload scope: %s" , c .scope ))
123+ return 1
124+ case len (c .mounts ) > 0 && c .pluginType != "" :
125+ c .UI .Error ("Cannot specify -type with -mounts" )
126+ return 1
106127 }
107128
108129 client , err := c .Client ()
@@ -111,25 +132,46 @@ func (c *PluginReloadCommand) Run(args []string) int {
111132 return 2
112133 }
113134
114- rid , err := client .Sys ().ReloadPlugin (& api.ReloadPluginInput {
115- Plugin : c .plugin ,
116- Mounts : c .mounts ,
117- Scope : c .scope ,
118- })
135+ var reloadID string
136+ if client .Namespace () == "" {
137+ pluginType := api .PluginTypeUnknown
138+ pluginTypeStr := strings .TrimSpace (c .pluginType )
139+ if pluginTypeStr != "" {
140+ var err error
141+ pluginType , err = api .ParsePluginType (pluginTypeStr )
142+ if err != nil {
143+ c .UI .Error (fmt .Sprintf ("Error parsing -type as a plugin type, must be unset or one of auth, secret, or database: %s" , err ))
144+ return 1
145+ }
146+ }
147+
148+ reloadID , err = client .Sys ().RootReloadPlugin (context .Background (), & api.RootReloadPluginInput {
149+ Plugin : c .plugin ,
150+ Type : pluginType ,
151+ Scope : c .scope ,
152+ })
153+ } else {
154+ reloadID , err = client .Sys ().ReloadPlugin (& api.ReloadPluginInput {
155+ Plugin : c .plugin ,
156+ Mounts : c .mounts ,
157+ Scope : c .scope ,
158+ })
159+ }
160+
119161 if err != nil {
120162 c .UI .Error (fmt .Sprintf ("Error reloading plugin/mounts: %s" , err ))
121163 return 2
122164 }
123165
124166 if len (c .mounts ) > 0 {
125- if rid != "" {
126- c .UI .Output (fmt .Sprintf ("Success! Reloading mounts: %s, reload_id: %s" , c .mounts , rid ))
167+ if reloadID != "" {
168+ c .UI .Output (fmt .Sprintf ("Success! Reloading mounts: %s, reload_id: %s" , c .mounts , reloadID ))
127169 } else {
128170 c .UI .Output (fmt .Sprintf ("Success! Reloaded mounts: %s" , c .mounts ))
129171 }
130172 } else {
131- if rid != "" {
132- c .UI .Output (fmt .Sprintf ("Success! Reloading plugin: %s, reload_id: %s" , c .plugin , rid ))
173+ if reloadID != "" {
174+ c .UI .Output (fmt .Sprintf ("Success! Reloading plugin: %s, reload_id: %s" , c .plugin , reloadID ))
133175 } else {
134176 c .UI .Output (fmt .Sprintf ("Success! Reloaded plugin: %s" , c .plugin ))
135177 }
0 commit comments