server: fsnotify on hooks

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2018-02-16 13:17:26 +01:00
parent d6c32fa88e
commit ca94095739
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
4 changed files with 91 additions and 5 deletions

View file

@ -30,9 +30,16 @@ type HookParams struct {
Arguments []string `json:"arguments"`
}
var (
errNotJSON = errors.New("hook file isn't a JSON")
)
// readHook reads hooks json files, verifies it and returns the json config
func readHook(hookPath string) (HookParams, error) {
var hook HookParams
if !strings.HasSuffix(hookPath, ".json") {
return hook, errNotJSON
}
raw, err := ioutil.ReadFile(hookPath)
if err != nil {
return hook, errors.Wrapf(err, "error Reading hook %q", hookPath)
@ -83,11 +90,11 @@ func readHooks(hooksPath string, hooks map[string]HookParams) error {
}
for _, file := range files {
if !strings.HasSuffix(file.Name(), ".json") {
continue
}
hook, err := readHook(filepath.Join(hooksPath, file.Name()))
if err != nil {
if err == errNotJSON {
continue
}
return err
}
for key, h := range hooks {