agent: parseSource still subs for _agent
This commit is contained in:
parent
5089561b1b
commit
134f66e3d4
|
@ -531,7 +531,13 @@ func (s *HTTPServer) parseToken(req *http.Request, token *string) {
|
|||
// DC in the request, if given, or else the agent's DC.
|
||||
func (s *HTTPServer) parseSource(req *http.Request, source *structs.QuerySource) {
|
||||
s.parseDC(req, &source.Datacenter)
|
||||
source.Node = req.URL.Query().Get("near")
|
||||
if node := req.URL.Query().Get("near"); node != "" {
|
||||
if node == "_agent" {
|
||||
source.Node = s.agent.config.NodeName
|
||||
} else {
|
||||
source.Node = node
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// parse is a convenience method for endpoints that need
|
||||
|
|
|
@ -345,8 +345,8 @@ func TestParseSource(t *testing.T) {
|
|||
defer srv.Shutdown()
|
||||
defer srv.agent.Shutdown()
|
||||
|
||||
// Default is agent's DC and no node (since the user didn't care,
|
||||
// then just give them the cheapest possible query).
|
||||
// Default is agent's DC and no node (since the user didn't care, then
|
||||
// just give them the cheapest possible query).
|
||||
req, err := http.NewRequest("GET",
|
||||
"/v1/catalog/nodes", nil)
|
||||
if err != nil {
|
||||
|
@ -382,6 +382,18 @@ func TestParseSource(t *testing.T) {
|
|||
if source.Datacenter != "foo" || source.Node != "bob" {
|
||||
t.Fatalf("bad: %v", source)
|
||||
}
|
||||
|
||||
// The magic "_agent" node name will use the agent's local node name.
|
||||
req, err = http.NewRequest("GET",
|
||||
"/v1/catalog/nodes?near=_agent", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
source = structs.QuerySource{}
|
||||
srv.parseSource(req, &source)
|
||||
if source.Datacenter != "dc1" || source.Node != srv.agent.config.NodeName {
|
||||
t.Fatalf("bad: %v", source)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseWait(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue