From fd3765fe3e39d8fb4c514e4c8f2eb8a170308f91 Mon Sep 17 00:00:00 2001 From: Chris Aubuchon Date: Wed, 2 Dec 2015 18:40:30 -0600 Subject: [PATCH] Restore AtlasConfig --- command/agent/config.go | 27 +++++++++++++++++++++++++++ command/agent/config_test.go | 12 ++++++++++++ 2 files changed, 39 insertions(+) diff --git a/command/agent/config.go b/command/agent/config.go index ac86ee5ff..368bfa76b 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -388,6 +388,14 @@ func (a *Config) Merge(b *Config) *Config { result.AdvertiseAddrs = result.AdvertiseAddrs.Merge(b.AdvertiseAddrs) } + // Apply the Atlas configuration + if result.Atlas == nil && b.Atlas != nil { + atlasConfig := *b.Atlas + result.Atlas = &atlasConfig + } else if b.Atlas != nil { + result.Atlas = result.Atlas.Merge(b.Atlas) + } + return &result } @@ -549,6 +557,25 @@ func (a *AdvertiseAddrs) Merge(b *AdvertiseAddrs) *AdvertiseAddrs { return &result } +// Merge merges two Atlas configurations together. +func (a *AtlasConfig) Merge(b *AtlasConfig) *AtlasConfig { + var result AtlasConfig = *a + + if b.Infrastructure != "" { + result.Infrastructure = b.Infrastructure + } + if b.Token != "" { + result.Token = b.Token + } + if b.Join { + result.Join = true + } + if b.Endpoint != "" { + result.Endpoint = b.Endpoint + } + return &result +} + // LoadConfig loads the configuration at the given path, regardless if // its a file or directory. func LoadConfig(path string) (*Config, error) { diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 67edceff0..90f2b620c 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -64,6 +64,12 @@ func TestConfig_Merge(t *testing.T) { RPC: "127.0.0.1", Serf: "127.0.0.1", }, + Atlas: &AtlasConfig{ + Infrastructure: "hashicorp/test1", + Token: "abc", + Join: false, + Endpoint: "foo", + }, } c2 := &Config{ @@ -129,6 +135,12 @@ func TestConfig_Merge(t *testing.T) { RPC: "127.0.0.2", Serf: "127.0.0.2", }, + Atlas: &AtlasConfig{ + Infrastructure: "hashicorp/test2", + Token: "xyz", + Join: true, + Endpoint: "bar", + }, } result := c1.Merge(c2)