-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
74 lines (67 loc) · 2.07 KB
/
context.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
package connectors
import (
"strings"
)
// Context is the execution context for the current playbook
type Context struct {
TenantID string
UserID string
Connections []*Connection
}
const GlobalNamespace = "global"
func (ctx *Context) LookupAction(actionLookup *ActionLookup) (*Connection, *ConnectorAction) {
globalConnectionIndex := -1
if actionLookup.ConnectorInterfaceActionName != "" {
//If connectorName is set, look for a match on connector name, then look up action
if actionLookup.ConnectorName != "" {
for i, c := range ctx.Connections {
if actionLookup.Namespace != "" {
namespace := GlobalNamespace
if c.Connector.TenantID != nil {
namespace = *c.Connector.TenantID
}
if namespace != actionLookup.Namespace {
continue
}
}
if strings.EqualFold(c.Connector.Name, actionLookup.ConnectorName) {
if c.Connector.TenantID != nil {
return c, c.Connector.LookupAction(actionLookup.ConnectorInterfaceActionName)
}
globalConnectionIndex = i
}
}
if globalConnectionIndex >= 0 {
c := ctx.Connections[globalConnectionIndex]
return c, c.Connector.LookupAction(actionLookup.ConnectorInterfaceActionName)
}
}
// Only loop through connectorInterfaces if necessary
if actionLookup.ImplementedConnectorInterfaceName != "" {
for j, c := range ctx.Connections {
for _, i := range c.Connector.Implements {
if actionLookup.Namespace != "" {
namespace := GlobalNamespace
if c.Connector.TenantID != nil {
namespace = *c.Connector.TenantID
}
if namespace != actionLookup.Namespace {
continue
}
}
if strings.EqualFold(i.Name, actionLookup.ImplementedConnectorInterfaceName) {
if c.Connector.TenantID != nil {
return c, i.LookupAction(actionLookup.ConnectorInterfaceActionName)
}
globalConnectionIndex = j
}
}
}
if globalConnectionIndex >= 0 {
c := ctx.Connections[globalConnectionIndex]
return c, c.Connector.LookupAction(actionLookup.ConnectorInterfaceActionName)
}
}
}
return nil, nil
}