-
Notifications
You must be signed in to change notification settings - Fork 342
/
hook.go
49 lines (39 loc) · 1.05 KB
/
hook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package actions
import (
"bytes"
"context"
"errors"
"fmt"
"net/http"
"github.com/treeverse/lakefs/pkg/graveler"
)
type HookType string
const (
HookTypeWebhook HookType = "webhook"
HookTypeAirflow HookType = "airflow"
HookTypeLua HookType = "lua"
)
// Hook is the abstraction of the basic user-configured runnable building-stone
type Hook interface {
Run(ctx context.Context, record graveler.HookRecord, buf *bytes.Buffer) error
}
type NewHookFunc func(ActionHook, *Action, Config, *http.Server) (Hook, error)
type HookBase struct {
ID string
ActionName string
Config Config
Endpoint *http.Server
}
var hooks = map[HookType]NewHookFunc{
HookTypeWebhook: NewWebhook,
HookTypeAirflow: NewAirflowHook,
HookTypeLua: NewLuaHook,
}
var ErrUnknownHookType = errors.New("unknown hook type")
func NewHook(hook ActionHook, action *Action, cfg Config, server *http.Server) (Hook, error) {
f := hooks[hook.Type]
if f == nil {
return nil, fmt.Errorf("%w (%s)", ErrUnknownHookType, hook.Type)
}
return f(hook, action, cfg, server)
}