From 2ac94d5581e74bb8d328154916336b32b8c74d1f Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 24 Jun 2019 13:29:47 -0400 Subject: [PATCH] Add the ability to use a dev Consul node for dev storage (#6965) --- command/server.go | 23 ++++++++++++++++++++++- command/server/config.go | 13 ++----------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/command/server.go b/command/server.go index 695767c6ca..6c27b3787b 100644 --- a/command/server.go +++ b/command/server.go @@ -108,6 +108,7 @@ type ServerCommand struct { flagTestVerifyOnly bool flagCombineLogs bool flagTestServerConfig bool + flagDevConsul bool } type ServerListener struct { @@ -292,6 +293,13 @@ func (c *ServerCommand) Flags() *FlagSets { Hidden: true, }) + f.BoolVar(&BoolVar{ + Name: "dev-consul", + Target: &c.flagDevConsul, + Default: false, + Hidden: true, + }) + // TODO: should the below flags be public? f.BoolVar(&BoolVar{ Name: "combine-logs", @@ -400,7 +408,20 @@ func (c *ServerCommand) Run(args []string) int { // Load the configuration var config *server.Config if c.flagDev { - config = server.DevConfig(c.flagDevHA, c.flagDevTransactional) + var devStorageType string + switch { + case c.flagDevConsul: + devStorageType = "consul" + case c.flagDevHA && c.flagDevTransactional: + devStorageType = "inmem_transactional_ha" + case !c.flagDevHA && c.flagDevTransactional: + devStorageType = "inmem_transactional" + case c.flagDevHA && !c.flagDevTransactional: + devStorageType = "inmem_ha" + default: + devStorageType = "inmem" + } + config = server.DevConfig(devStorageType) if c.flagDevListenAddr != "" { config.Listeners[0].Config["address"] = c.flagDevListenAddr } diff --git a/command/server/config.go b/command/server/config.go index 3f03200bae..19351dbe58 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -80,13 +80,13 @@ type Config struct { } // DevConfig is a Config that is used for dev mode of Vault. -func DevConfig(ha, transactional bool) *Config { +func DevConfig(storageType string) *Config { ret := &Config{ DisableMlock: true, EnableRawEndpoint: true, Storage: &Storage{ - Type: "inmem", + Type: storageType, }, Listeners: []*Listener{ @@ -109,15 +109,6 @@ func DevConfig(ha, transactional bool) *Config { }, } - switch { - case ha && transactional: - ret.Storage.Type = "inmem_transactional_ha" - case !ha && transactional: - ret.Storage.Type = "inmem_transactional" - case ha && !transactional: - ret.Storage.Type = "inmem_ha" - } - return ret }