From 32b4f48e667631d810de1c33ad251c4616e9008f Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 2 Jun 2016 18:19:51 -0400 Subject: [PATCH] Add a metadata node_id field for Atlas usage and fix tests --- command/server/config.go | 4 ++ command/server/config_test.go | 20 +++++----- command/server/listener_atlas.go | 4 +- command/server/test-fixtures/config.hcl | 1 + command/server/test-fixtures/config.hcl.json | 42 ++++++++++---------- 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/command/server/config.go b/command/server/config.go index 1e6786d7c2..1de86e17c9 100644 --- a/command/server/config.go +++ b/command/server/config.go @@ -428,6 +428,7 @@ func parseListeners(result *Config, list *ast.ObjectList) error { "address", "endpoint", "infrastructure", + "node_id", "tls_disable", "tls_cert_file", "tls_key_file", @@ -456,6 +457,9 @@ func parseListeners(result *Config, list *ast.ObjectList) error { if m["infrastructure"] == "" { return multierror.Prefix(fmt.Errorf("'infrastructure' must be specified for an Atlas listener"), fmt.Sprintf("listeners.%s", key)) } + if m["node_id"] == "" { + return multierror.Prefix(fmt.Errorf("'node_id' must be specified for an Atlas listener"), fmt.Sprintf("listeners.%s", key)) + } } } diff --git a/command/server/config_test.go b/command/server/config_test.go index 17d923aa3f..8841990c09 100644 --- a/command/server/config_test.go +++ b/command/server/config_test.go @@ -16,17 +16,18 @@ func TestLoadConfigFile(t *testing.T) { expected := &Config{ Listeners: []*Listener{ &Listener{ - Type: "tcp", + Type: "atlas", Config: map[string]string{ - "address": "127.0.0.1:443", + "token": "foobar", + "infrastructure": "foo/bar", + "endpoint": "https://foo.bar:1111", + "node_id": "foo_node", }, }, &Listener{ - Type: "atlas", + Type: "tcp", Config: map[string]string{ - Token: "foobar", - Infrastructure: "foo/bar", - Endpoint: "https://foo.bar:1111", + "address": "127.0.0.1:443", }, }, }, @@ -83,9 +84,10 @@ func TestLoadConfigFile_json(t *testing.T) { &Listener{ Type: "atlas", Config: map[string]string{ - Token: "foobar", - Infrastructure: "foo/bar", - Endpoint: "https://foo.bar:1111", + "token": "foobar", + "infrastructure": "foo/bar", + "endpoint": "https://foo.bar:1111", + "node_id": "foo_node", }, }, }, diff --git a/command/server/listener_atlas.go b/command/server/listener_atlas.go index 594c00c90a..5d36c6c6cd 100644 --- a/command/server/listener_atlas.go +++ b/command/server/listener_atlas.go @@ -31,7 +31,9 @@ func atlasListenerFactory(config map[string]string, logger io.Writer) (net.Liste Service: "vault", Version: version.GetVersion().String(), ResourceType: "vault-cluster", - Meta: map[string]string{}, + Meta: map[string]string{ + "node_id": config["node_id"], + }, Atlas: scada.AtlasConfig{ Endpoint: config["endpoint"], Infrastructure: config["infrastructure"], diff --git a/command/server/test-fixtures/config.hcl b/command/server/test-fixtures/config.hcl index 26ab8d2004..122710bf41 100644 --- a/command/server/test-fixtures/config.hcl +++ b/command/server/test-fixtures/config.hcl @@ -7,6 +7,7 @@ listener "atlas" { token = "foobar" infrastructure = "foo/bar" endpoint = "https://foo.bar:1111" + node_id = "foo_node" } listener "tcp" { diff --git a/command/server/test-fixtures/config.hcl.json b/command/server/test-fixtures/config.hcl.json index 5e1eac93b2..094dc154a5 100644 --- a/command/server/test-fixtures/config.hcl.json +++ b/command/server/test-fixtures/config.hcl.json @@ -1,22 +1,24 @@ { - "listener":{ - "tcp":{ - "address":"127.0.0.1:443" - } - }, - "atlas":{ - "token":"foobar", - "infrastructure":"foo/bar", - "endpoint":"https://foo.bar:1111" - }, - "backend":{ - "consul":{ - "foo":"bar" - } - }, - "telemetry":{ - "statsite_address":"baz" - }, - "max_lease_ttl":"10h", - "default_lease_ttl":"10h" + "listener": [{ + "tcp": { + "address": "127.0.0.1:443" + } + }, { + "atlas": { + "token": "foobar", + "infrastructure": "foo/bar", + "endpoint": "https://foo.bar:1111", + "node_id": "foo_node" + } + }], + "backend": { + "consul": { + "foo": "bar" + } + }, + "telemetry": { + "statsite_address": "baz" + }, + "max_lease_ttl": "10h", + "default_lease_ttl": "10h" }