added cidr validation and made hook execs to command array with args

This commit is contained in:
ston1th 2021-02-11 20:17:52 +01:00
commit 85a2e39a4b
6 changed files with 54 additions and 165 deletions

View file

@ -7,6 +7,7 @@ import (
"path/filepath"
"strings"
"github.com/vishvananda/netlink"
"gopkg.in/yaml.v2"
)
@ -41,14 +42,20 @@ func Validate(c *Config) error {
if len(c.VirtualIPs) == 0 {
return errors.New("missing virtualIPs config")
}
if c.LeaderHook != "" {
if !filepath.IsAbs(c.LeaderHook) {
return errors.New("leaderHook path must be absolute")
for _, vip := range c.VirtualIPs {
_, err := netlink.ParseAddr(vip)
if err != nil {
return fmt.Errorf("failed to parse CIDR virtualIP '%s': %w", vip, err)
}
}
if c.FollowerHook != "" {
if !filepath.IsAbs(c.FollowerHook) {
return errors.New("followerHook path must be absolute")
if len(c.LeaderHook) > 0 {
if !filepath.IsAbs(c.LeaderHook[0]) {
return errors.New("leaderHook executable path must be absolute")
}
}
if len(c.FollowerHook) > 0 {
if !filepath.IsAbs(c.FollowerHook[0]) {
return errors.New("followerHook executable path must be absolute")
}
}
raft := c.Cluster.Raft
@ -116,8 +123,8 @@ type Config struct {
VirtualIPs []string `yaml:"virtualIPs"`
Interface string `yaml:"interface,omitempty"`
Label string `yaml:"label,omitempty"`
LeaderHook string `yaml:"leaderHook,omitempty"`
FollowerHook string `yaml:"followerHook,omitempty"`
LeaderHook []string `yaml:"leaderHook,omitempty"`
FollowerHook []string `yaml:"followerHook,omitempty"`
Cluster Cluster `yaml:"cluster"`
}