From 86c7a4c15569ff38bd8777052c37c57c7e6c5e2e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 Mar 2015 15:30:07 -0700 Subject: [PATCH] command/server: load config from flags --- command/server.go | 19 +++++++++++++++++++ command/server/config.go | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/command/server.go b/command/server.go index 5c952533e..ed58cb0b4 100644 --- a/command/server.go +++ b/command/server.go @@ -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 } diff --git a/command/server/config.go b/command/server/config.go index 614aad0f2..31646918c 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -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