Restore AtlasConfig

This commit is contained in:
Chris Aubuchon
2015-12-02 18:40:30 -06:00
parent 53b23cdc1b
commit fd3765fe3e
2 changed files with 39 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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)