mirror of https://github.com/status-im/consul.git
Stronger API validation
This commit is contained in:
parent
682a986ae8
commit
1fb80fe38d
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue