diff --git a/agent/agent_endpoint.go b/agent/agent_endpoint.go index bfdf5d6ef6..6addef95bf 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 ca641f7a37..34d54f6f32 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 f508be5046..c98ad5d7b1 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)