mirror of https://github.com/status-im/consul.git
Update the v1/agent/service/:service endpoint to output tagged… (#6304)
This commit is contained in:
parent
82e2cef4e1
commit
6a1e0dfed8
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue