consul: rename function to avoid collision and clean up

pull/1024/head
Ryan Uber 2015-06-11 12:48:38 -07:00
parent 6623538c93
commit d217c25668
6 changed files with 15 additions and 23 deletions

View File

@ -309,10 +309,10 @@ func (f *aclFilter) filterNodeDump(dump *structs.NodeDump) {
} }
} }
// aclFilter is used to filter results from our service catalog based on the // filterACL is used to filter results from our service catalog based on the
// rules configured for the provided token. The subject is scrubbed and // rules configured for the provided token. The subject is scrubbed and
// modified in-place, leaving only resources the token can access. // modified in-place, leaving only resources the token can access.
func (s *Server) aclFilter(token string, subj interface{}) error { func (s *Server) filterACL(token string, subj interface{}) error {
// Get the ACL from the token // Get the ACL from the token
acl, err := s.resolveToken(token) acl, err := s.resolveToken(token)
if err != nil { if err != nil {

View File

@ -126,7 +126,7 @@ func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.Inde
state.QueryTables("Nodes"), state.QueryTables("Nodes"),
func() error { func() error {
reply.Index, reply.Nodes = state.Nodes() reply.Index, reply.Nodes = state.Nodes()
return c.srv.aclFilter(args.Token, reply) return c.srv.filterACL(args.Token, reply)
}) })
} }
@ -143,7 +143,7 @@ func (c *Catalog) ListServices(args *structs.DCSpecificRequest, reply *structs.I
state.QueryTables("Services"), state.QueryTables("Services"),
func() error { func() error {
reply.Index, reply.Services = state.Services() reply.Index, reply.Services = state.Services()
return c.srv.aclFilter(args.Token, reply) return c.srv.filterACL(args.Token, reply)
}) })
} }
@ -169,7 +169,7 @@ func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *stru
} else { } else {
reply.Index, reply.ServiceNodes = state.ServiceNodes(args.ServiceName) reply.Index, reply.ServiceNodes = state.ServiceNodes(args.ServiceName)
} }
return c.srv.aclFilter(args.Token, reply) return c.srv.filterACL(args.Token, reply)
}) })
// Provide some metrics // Provide some metrics
@ -203,6 +203,6 @@ func (c *Catalog) NodeServices(args *structs.NodeSpecificRequest, reply *structs
state.QueryTables("NodeServices"), state.QueryTables("NodeServices"),
func() error { func() error {
reply.Index, reply.NodeServices = state.NodeServices(args.Node) reply.Index, reply.NodeServices = state.NodeServices(args.Node)
return c.srv.aclFilter(args.Token, reply) return c.srv.filterACL(args.Token, reply)
}) })
} }

View File

@ -778,7 +778,7 @@ func TestCatalogRegister_FailedCase1(t *testing.T) {
} }
} }
func TestCatalog_applyDiscoveryACLs(t *testing.T) { func TestCatalog_filterACL(t *testing.T) {
dir, srv := testServerWithConfig(t, func(c *Config) { dir, srv := testServerWithConfig(t, func(c *Config) {
c.ACLDatacenter = "dc1" c.ACLDatacenter = "dc1"
c.ACLMasterToken = "root" c.ACLMasterToken = "root"

View File

@ -43,7 +43,7 @@ func (h *Health) NodeChecks(args *structs.NodeSpecificRequest,
state.QueryTables("NodeChecks"), state.QueryTables("NodeChecks"),
func() error { func() error {
reply.Index, reply.HealthChecks = state.NodeChecks(args.Node) reply.Index, reply.HealthChecks = state.NodeChecks(args.Node)
return h.srv.aclFilter(args.Token, reply) return h.srv.filterACL(args.Token, reply)
}) })
} }
@ -67,7 +67,7 @@ func (h *Health) ServiceChecks(args *structs.ServiceSpecificRequest,
state.QueryTables("ServiceChecks"), state.QueryTables("ServiceChecks"),
func() error { func() error {
reply.Index, reply.HealthChecks = state.ServiceChecks(args.ServiceName) reply.Index, reply.HealthChecks = state.ServiceChecks(args.ServiceName)
return h.srv.aclFilter(args.Token, reply) return h.srv.filterACL(args.Token, reply)
}) })
} }
@ -93,7 +93,7 @@ func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *struc
} else { } else {
reply.Index, reply.Nodes = state.CheckServiceNodes(args.ServiceName) reply.Index, reply.Nodes = state.CheckServiceNodes(args.ServiceName)
} }
return h.srv.aclFilter(args.Token, reply) return h.srv.filterACL(args.Token, reply)
}) })
// Provide some metrics // Provide some metrics

View File

@ -223,7 +223,7 @@ func TestHealth_ServiceNodes(t *testing.T) {
} }
} }
func TestHealth_applyDiscoveryACLs(t *testing.T) { func TestHealth_filterACL(t *testing.T) {
dir, srv := testServerWithConfig(t, func(c *Config) { dir, srv := testServerWithConfig(t, func(c *Config) {
c.ACLDatacenter = "dc1" c.ACLDatacenter = "dc1"
c.ACLMasterToken = "root" c.ACLMasterToken = "root"

View File

@ -25,12 +25,8 @@ func (m *Internal) NodeInfo(args *structs.NodeSpecificRequest,
&reply.QueryMeta, &reply.QueryMeta,
state.QueryTables("NodeInfo"), state.QueryTables("NodeInfo"),
func() error { func() error {
index, dump := state.NodeInfo(args.Node) reply.Index, reply.Dump = state.NodeInfo(args.Node)
if err := m.srv.aclFilter(args.Token, &dump); err != nil { return m.srv.filterACL(args.Token, reply)
return err
}
reply.Index, reply.Dump = index, dump
return nil
}) })
} }
@ -47,12 +43,8 @@ func (m *Internal) NodeDump(args *structs.DCSpecificRequest,
&reply.QueryMeta, &reply.QueryMeta,
state.QueryTables("NodeDump"), state.QueryTables("NodeDump"),
func() error { func() error {
index, dump := state.NodeDump() reply.Index, reply.Dump = state.NodeDump()
if err := m.srv.aclFilter(args.Token, &dump); err != nil { return m.srv.filterACL(args.Token, reply)
return err
}
reply.Index, reply.Dump = index, dump
return nil
}) })
} }