Stronger API validation

This commit is contained in:
Armon Dadgar 2013-12-24 12:43:34 -08:00
parent 682a986ae8
commit 1fb80fe38d
1 changed files with 21 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package consul
import (
"fmt"
"github.com/hashicorp/consul/consul/structs"
)
@ -15,6 +16,11 @@ func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error
return err
}
// Verify the args
if args.Node == "" || args.Address == "" {
return fmt.Errorf("Must provide node and address")
}
_, err := c.srv.raftApply(structs.RegisterRequestType, args)
if err != nil {
c.srv.logger.Printf("[ERR] Register failed: %v", err)
@ -29,6 +35,11 @@ func (c *Catalog) Deregister(args *structs.DeregisterRequest, reply *struct{}) e
return err
}
// Verify the args
if args.Node == "" {
return fmt.Errorf("Must provide node")
}
_, err := c.srv.raftApply(structs.DeregisterRequestType, args)
if err != nil {
c.srv.logger.Printf("[ERR] Deregister failed: %v", err)
@ -93,6 +104,11 @@ func (c *Catalog) ServiceNodes(args *structs.ServiceNodesRequest, reply *structs
return err
}
// Verify the arguments
if args.ServiceName == "" {
return fmt.Errorf("Must provide service name")
}
// Get the nodes
state := c.srv.fsm.State()
var nodes structs.ServiceNodes
@ -112,6 +128,11 @@ func (c *Catalog) NodeServices(args *structs.NodeServicesRequest, reply *structs
return err
}
// Verify the arguments
if args.Node == "" {
return fmt.Errorf("Must provide node")
}
// Get the node services
state := c.srv.fsm.State()
services := state.NodeServices(args.Node)