/
hooks.go
55 lines (42 loc) · 1.47 KB
/
hooks.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
51
52
53
54
55
package hooks
import (
"context"
"github.com/arangodb/go-driver"
"github.com/SecurityBrewery/catalyst/index"
)
type Hooks struct {
DatabaseAfterConnectFuncs []func(ctx context.Context, client driver.Client, name string)
IngestionFilterFunc func(ctx context.Context, index *index.Index) (string, error)
TicketReadFilterFunc func(ctx context.Context) (string, map[string]any, error)
TicketWriteFilterFunc func(ctx context.Context) (string, map[string]any, error)
GetGroupsFunc func(ctx context.Context, username string) ([]string, error)
}
func (h *Hooks) DatabaseAfterConnect(ctx context.Context, client driver.Client, name string) {
for _, f := range h.DatabaseAfterConnectFuncs {
f(ctx, client, name)
}
}
func (h *Hooks) IngestionFilter(ctx context.Context, index *index.Index) (string, error) {
if h.IngestionFilterFunc != nil {
return h.IngestionFilterFunc(ctx, index)
}
return "[]", nil
}
func (h *Hooks) TicketReadFilter(ctx context.Context) (string, map[string]any, error) {
if h.TicketReadFilterFunc != nil {
return h.TicketReadFilterFunc(ctx)
}
return "", nil, nil
}
func (h *Hooks) TicketWriteFilter(ctx context.Context) (string, map[string]any, error) {
if h.TicketWriteFilterFunc != nil {
return h.TicketWriteFilterFunc(ctx)
}
return "", nil, nil
}
func (h *Hooks) GetGroups(ctx context.Context, username string) ([]string, error) {
if h.GetGroupsFunc != nil {
return h.GetGroupsFunc(ctx, username)
}
return nil, nil
}