-
Notifications
You must be signed in to change notification settings - Fork 351
/
hook.go
43 lines (33 loc) · 861 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
package actions
import (
"context"
"errors"
"fmt"
"github.com/treeverse/lakefs/pkg/graveler"
)
type HookType string
const (
HookTypeWebhook HookType = "webhook"
HookTypeAirflow HookType = "airflow"
)
// Hook is the abstraction of the basic user-configured runnable building-stone
type Hook interface {
Run(ctx context.Context, record graveler.HookRecord, writer *HookOutputWriter) error
}
type NewHookFunc func(ActionHook, *Action) (Hook, error)
type HookBase struct {
ID string
ActionName string
}
var hooks = map[HookType]NewHookFunc{
HookTypeWebhook: NewWebhook,
HookTypeAirflow: NewAirflowHook,
}
var ErrUnknownHookType = errors.New("unknown hook type")
func NewHook(h ActionHook, a *Action) (Hook, error) {
f := hooks[h.Type]
if f == nil {
return nil, fmt.Errorf("%w (%s)", ErrUnknownHookType, h.Type)
}
return f(h, a)
}