-
Notifications
You must be signed in to change notification settings - Fork 356
/
hook.go
50 lines (40 loc) · 1.19 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
50
package actions
import (
"bytes"
"context"
"errors"
"fmt"
"net/http"
"github.com/treeverse/lakefs/pkg/graveler"
"github.com/treeverse/lakefs/pkg/stats"
)
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, string, stats.Collector) (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, serverAddress string, collector stats.Collector) (Hook, error) {
f := hooks[hook.Type]
if f == nil {
return nil, fmt.Errorf("%w (%s)", ErrUnknownHookType, hook.Type)
}
return f(hook, action, cfg, server, serverAddress, collector)
}