-
Notifications
You must be signed in to change notification settings - Fork 361
/
hook.go
48 lines (38 loc) · 997 Bytes
/
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
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, *http.Server) (Hook, error)
type HookBase struct {
ID string
ActionName string
Endpoint *http.Server
}
var hooks = map[HookType]NewHookFunc{
HookTypeWebhook: NewWebhook,
HookTypeAirflow: NewAirflowHook,
HookTypeLua: NewLuaHook,
}
var ErrUnknownHookType = errors.New("unknown hook type")
func NewHook(h ActionHook, a *Action, e *http.Server) (Hook, error) {
f := hooks[h.Type]
if f == nil {
return nil, fmt.Errorf("%w (%s)", ErrUnknownHookType, h.Type)
}
return f(h, a, e)
}