-
Notifications
You must be signed in to change notification settings - Fork 3
/
connector_catalog.go
99 lines (76 loc) · 2.02 KB
/
connector_catalog.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
88
89
90
91
92
93
94
95
96
97
98
99
package eventline
import (
"github.com/exograd/eventline/pkg/utils"
"github.com/exograd/go-daemon/check"
)
var Connectors = map[string]Connector{}
func ValidateConnectorName(name string) error {
if _, found := Connectors[name]; !found {
return &UnknownConnectorDefError{Name: name}
}
return nil
}
func ConnectorExists(name string) (exists bool) {
_, exists = Connectors[name]
return
}
func FindConnector(name string) (Connector, bool) {
c, found := Connectors[name]
return c, found
}
func GetConnector(name string) Connector {
c, found := Connectors[name]
if !found {
utils.Panicf("unknown connector %q", name)
}
return c
}
func GetConnectorDef(name string) *ConnectorDef {
c := GetConnector(name)
return c.Definition()
}
func CheckConnectorName(c *check.Checker, token string, cname string) bool {
if c.CheckStringNotEmpty(token, cname) {
return c.Check(token, ConnectorExists(cname),
"unknown_connector", "unknown connector %q", cname)
}
return true
}
func IdentityExists(cname, itype string) bool {
c, found := Connectors[cname]
if !found {
return false
}
cdef := c.Definition()
return cdef.IdentityExists(itype)
}
func CheckIdentityName(c *check.Checker, token string, cname, itype string) {
c.CheckStringNotEmpty(token, itype)
if itype != "" {
c.Check(token, IdentityExists(cname, itype),
"unknown_identity", "unknown identity %q in connector %q",
itype, cname)
}
}
func EventExists(cname, name string) bool {
c, found := Connectors[cname]
if !found {
return false
}
cdef := c.Definition()
return cdef.EventExists(name)
}
func EventDefExists(ref EventRef) bool {
return EventExists(ref.Connector, ref.Event)
}
func GetEventDef(ref EventRef) *EventDef {
cdef := GetConnectorDef(ref.Connector)
return cdef.Event(ref.Event)
}
func CheckEventName(c *check.Checker, token string, cname, name string) bool {
if c.CheckStringNotEmpty(token, name) == false {
return false
}
return c.Check(token, EventExists(cname, name),
"unknown_event", "unknown event %q in connector %q", name, cname)
}