command/server: load config from flags
This commit is contained in:
parent
d88c20e293
commit
86c7a4c155
|
@ -1,8 +1,10 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/vault/command/server"
|
||||
"github.com/hashicorp/vault/helper/flag-slice"
|
||||
)
|
||||
|
||||
|
@ -28,6 +30,23 @@ func (c *ServerCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
// Load the configuration
|
||||
var config *server.Config
|
||||
for _, path := range configPath {
|
||||
current, err := server.LoadConfig(path)
|
||||
if err != nil {
|
||||
c.Ui.Error(fmt.Sprintf(
|
||||
"Error loading configuration from %s: %s", path, err))
|
||||
return 1
|
||||
}
|
||||
|
||||
if config == nil {
|
||||
config = current
|
||||
} else {
|
||||
config = config.Merge(current)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the listeners
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -56,6 +56,21 @@ func (c *Config) Merge(c2 *Config) *Config {
|
|||
return result
|
||||
}
|
||||
|
||||
// LoadConfig loads the configuration at the given path, regardless if
|
||||
// its a file or directory.
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if fi.IsDir() {
|
||||
return LoadConfigDir(path)
|
||||
} else {
|
||||
return LoadConfigFile(path)
|
||||
}
|
||||
}
|
||||
|
||||
// LoadConfigFile loads the configuration from the given file.
|
||||
func LoadConfigFile(path string) (*Config, error) {
|
||||
// Read the file
|
||||
|
|
Loading…
Reference in New Issue