From 0e1b7038cc8c65684c11d623d48ece7cb9a0eb2c Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Sat, 10 Aug 2019 09:15:19 -0400 Subject: [PATCH] =?UTF-8?q?Update=20the=20v1/agent/service/:service=20endp?= =?UTF-8?q?oint=20to=20output=20tagged=E2=80=A6=20(#6304)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/agent_endpoint.go | 40 ++---------------------------------- agent/agent_endpoint_test.go | 18 +++++++++++++++- api/agent_test.go | 1 + 3 files changed, 20 insertions(+), 39 deletions(-) diff --git a/agent/agent_endpoint.go b/agent/agent_endpoint.go index bfdf5d6ef..6addef95b 100644 --- a/agent/agent_endpoint.go +++ b/agent/agent_endpoint.go @@ -10,8 +10,6 @@ import ( "strings" "time" - "github.com/mitchellh/mapstructure" - "github.com/hashicorp/go-memdb" "github.com/mitchellh/hashstructure" @@ -288,43 +286,9 @@ func (s *HTTPServer) AgentService(resp http.ResponseWriter, req *http.Request) ( return "", nil, acl.ErrPermissionDenied } - var connect *api.AgentServiceConnect - var proxy *api.AgentServiceConnectProxyConfig - - if svc.Connect.Native { - connect = &api.AgentServiceConnect{ - Native: svc.Connect.Native, - } - } - - if svc.Kind == structs.ServiceKindConnectProxy || - svc.Kind == structs.ServiceKindMeshGateway { - - proxy = svc.Proxy.ToAPI() - } - - var weights api.AgentWeights - if svc.Weights != nil { - err := mapstructure.Decode(svc.Weights, &weights) - if err != nil { - return "", nil, err - } - } - // Calculate the content hash over the response, minus the hash field - reply := &api.AgentService{ - Kind: api.ServiceKind(svc.Kind), - ID: svc.ID, - Service: svc.Service, - Tags: svc.Tags, - Meta: svc.Meta, - Port: svc.Port, - Address: svc.Address, - EnableTagOverride: svc.EnableTagOverride, - Weights: weights, - Proxy: proxy, - Connect: connect, - } + aSvc := buildAgentService(svc) + reply := &aSvc rawHash, err := hashstructure.Hash(reply, nil) if err != nil { diff --git a/agent/agent_endpoint_test.go b/agent/agent_endpoint_test.go index ca641f7a3..34d54f6f3 100644 --- a/agent/agent_endpoint_test.go +++ b/agent/agent_endpoint_test.go @@ -278,6 +278,12 @@ func TestAgent_Service(t *testing.T) { services { name = "web" port = 8181 + tagged_addresses { + wan { + address = "198.18.0.1" + port = 1818 + } + } } `) defer a.Shutdown() @@ -323,6 +329,8 @@ func TestAgent_Service(t *testing.T) { Passing: 1, Warning: 1, }, + Meta: map[string]string{}, + Tags: []string{}, } // Copy and modify @@ -335,11 +343,19 @@ func TestAgent_Service(t *testing.T) { ID: "web", Service: "web", Port: 8181, - ContentHash: "afaa0e76b202ffbb", + ContentHash: "6c247f8ffa5d1fb2", Weights: api.AgentWeights{ Passing: 1, Warning: 1, }, + TaggedAddresses: map[string]api.ServiceAddress{ + "wan": api.ServiceAddress{ + Address: "198.18.0.1", + Port: 1818, + }, + }, + Meta: map[string]string{}, + Tags: []string{}, } tests := []struct { diff --git a/api/agent_test.go b/api/agent_test.go index f508be504..c98ad5d7b 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -647,6 +647,7 @@ func TestAPI_AgentService(t *testing.T) { Passing: 1, Warning: 1, }, + Meta: map[string]string{}, } require.Equal(expect, got) require.Equal(expect.ContentHash, qm.LastContentHash)