-
Notifications
You must be signed in to change notification settings - Fork 3
/
connector_def.go
87 lines (65 loc) · 1.75 KB
/
connector_def.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package eventline
import (
"fmt"
"github.com/exograd/eventline/pkg/utils"
)
type UnknownConnectorDefError struct {
Name string
}
func (err UnknownConnectorDefError) Error() string {
return fmt.Sprintf("unknown connector %q", err.Name)
}
type ConnectorDef struct {
Name string
Identities map[string]*IdentityDef
Events map[string]*EventDef
Worker WorkerBehaviour
}
func NewConnectorDef(name string) *ConnectorDef {
return &ConnectorDef{
Name: name,
Identities: make(map[string]*IdentityDef),
Events: make(map[string]*EventDef),
}
}
func (c *ConnectorDef) AddIdentity(idef *IdentityDef) {
idef.DataDef = idef.Data.Def()
c.Identities[idef.Type] = idef
}
func (c *ConnectorDef) IdentityExists(typeName string) (exists bool) {
_, exists = c.Identities[typeName]
return
}
func (c *ConnectorDef) Identity(typeName string) *IdentityDef {
def, found := c.Identities[typeName]
if !found {
utils.Panicf("unknown identity %q in connector %q", typeName, c.Name)
}
return def
}
func (c *ConnectorDef) ValidateIdentityType(typeName string) error {
if _, found := c.Identities[typeName]; !found {
return &UnknownIdentityDefError{Connector: c.Name, Type: typeName}
}
return nil
}
func (c *ConnectorDef) AddEvent(edef *EventDef) {
c.Events[edef.Name] = edef
}
func (c *ConnectorDef) EventExists(typeName string) (exists bool) {
_, exists = c.Events[typeName]
return
}
func (c *ConnectorDef) Event(typeName string) *EventDef {
def, found := c.Events[typeName]
if !found {
utils.Panicf("unknown event %q in connector %q", typeName, c.Name)
}
return def
}
func (c *ConnectorDef) ValidateEventName(name string) error {
if _, found := c.Events[name]; !found {
return &UnknownEventDefError{Connector: c.Name, Name: name}
}
return nil
}