mirror of https://github.com/status-im/consul.git
Merge pull request #1140 from hashicorp/h-acl
Filter services when using ChecksInState.
This commit is contained in:
commit
6cc2d21241
|
@ -816,6 +816,7 @@ func testACLFilterServer(t *testing.T) (dir, token string, srv *Server, client *
|
||||||
CheckID: "service:foo",
|
CheckID: "service:foo",
|
||||||
Name: "service:foo",
|
Name: "service:foo",
|
||||||
ServiceID: "foo",
|
ServiceID: "foo",
|
||||||
|
Status: structs.HealthPassing,
|
||||||
},
|
},
|
||||||
WriteRequest: structs.WriteRequest{Token: "root"},
|
WriteRequest: structs.WriteRequest{Token: "root"},
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (h *Health) ChecksInState(args *structs.ChecksInStateRequest,
|
||||||
state.QueryTables("ChecksInState"),
|
state.QueryTables("ChecksInState"),
|
||||||
func() error {
|
func() error {
|
||||||
reply.Index, reply.HealthChecks = state.ChecksInState(args.State)
|
reply.Index, reply.HealthChecks = state.ChecksInState(args.State)
|
||||||
return nil
|
return h.srv.filterACL(args.Token, reply)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -316,3 +316,33 @@ func TestHealth_ServiceNodes_FilterACL(t *testing.T) {
|
||||||
t.Fatalf("bad: %#v", reply.Nodes)
|
t.Fatalf("bad: %#v", reply.Nodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHealth_ChecksInState_FilterACL(t *testing.T) {
|
||||||
|
dir, token, srv, client := testACLFilterServer(t)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
defer srv.Shutdown()
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
opt := structs.ChecksInStateRequest{
|
||||||
|
Datacenter: "dc1",
|
||||||
|
State: structs.HealthPassing,
|
||||||
|
QueryOptions: structs.QueryOptions{Token: token},
|
||||||
|
}
|
||||||
|
reply := structs.IndexedHealthChecks{}
|
||||||
|
if err := client.Call("Health.ChecksInState", &opt, &reply); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
found := false
|
||||||
|
for _, chk := range reply.HealthChecks {
|
||||||
|
switch chk.ServiceName {
|
||||||
|
case "foo":
|
||||||
|
found = true
|
||||||
|
case "bar":
|
||||||
|
t.Fatalf("bad service 'bar': %#v", reply.HealthChecks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Fatalf("missing service 'foo': %#v", reply.HealthChecks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue