-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
238 lines (212 loc) · 7.7 KB
/
model.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package connectors
import (
"fmt"
"io"
"strconv"
"strings"
"time"
"github.com/secureworks/taegis-sdk-go/common"
)
// Enumeration of supported auth types
type AuthType string
const (
AuthTypeNone AuthType = "None"
AuthTypePlatform AuthType = "Platform"
AuthTypeRaw AuthType = "Raw"
AuthTypeBasic AuthType = "Basic"
AuthTypeAPIKey AuthType = "APIKey"
AuthTypeClientCerts AuthType = "ClientCerts"
AuthTypeOAuthClientCreds AuthType = "OAuthClientCreds"
AuthTypeOAuthOwnerPasswordCreds AuthType = "OAuthPassword"
AuthTypeOAuthAuthCodeCreds AuthType = "OAuthAuthCode"
)
var AllAuthType = []AuthType{
AuthTypeNone,
AuthTypePlatform,
AuthTypeRaw,
AuthTypeBasic,
AuthTypeAPIKey,
AuthTypeClientCerts,
AuthTypeOAuthClientCreds,
AuthTypeOAuthOwnerPasswordCreds,
AuthTypeOAuthAuthCodeCreds,
}
var OAuthType = []AuthType{
AuthTypeOAuthClientCreds,
AuthTypeOAuthOwnerPasswordCreds,
AuthTypeOAuthAuthCodeCreds,
AuthTypePlatform,
}
// ConnectorCategory is a grouping/categorization of available connectors (e.g. IP reputation services, DNS lookup, etc)
type ConnectorCategory struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Name string `json:"name"`
Description string `json:"description"`
Tags common.Tags `json:"tags,omitempty"`
}
// ConnectorAction defines a method or activity that can be called on a connector and its corresponding input and output
type ConnectorAction struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Name string `json:"name"`
Description string `json:"description"`
Tags common.Tags `json:"tags,omitempty"`
Interface *ConnectorInterface `json:"interface"`
Inputs common.Object `json:"inputs,omitempty"`
Outputs common.Object `json:"outputs,omitempty"`
}
// ConnectorInterface defines an abstract type (set of actions) that could be implemented by multiple connectors
type ConnectorInterface struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Name string `json:"name"`
Description string `json:"description"`
Tags common.Tags `json:"tags,omitempty"`
Categories []*ConnectorCategory `json:"categories,omitempty"`
Actions []*ConnectorAction `json:"actions,omitempty"`
TenantID *string `json:"tenantId,omitempty"`
}
// ConnectionMethod references a service that implements connectors of a specific connection method (e.g. http, grpc, graphql)
type ConnectionMethod struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Name string `json:"name"`
Description string `json:"description"`
Tags common.Tags `json:"tags,omitempty"`
Parameters common.Object `json:"parameters,omitempty"`
GraphQLURL string `json:"graphqlUrl"`
Connectors []*Connector `json:"connectors"`
}
// Connector is an entry in catalog of available connectors (e.g. service now connector based on generic http connector)
type Connector struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Name string `json:"name"`
Description string `json:"description"`
Tags common.Tags `json:"tags,omitempty"`
Docs *string `json:"documentation,omitempty"`
Method *ConnectionMethod `json:"method,omitempty"`
Implements []*ConnectorInterface `json:"implements,omitempty"`
Actions []*ConnectorActionDefinition `json:"actions,omitempty"`
Connections []*Connection `json:"connections,omitempty"`
Parameters common.Object `json:"parameters,omitempty"`
AuthTypes []AuthType `json:"authTypes"`
Sequence *int64 `json:"sequence,omitempty"`
Title *string `json:"title"`
TenantID *string `json:"tenant,omitempty"`
}
// ConnectorActionDefinition defines the configuration of a connector action implementation"
type ConnectorActionDefinition struct {
ID string `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Action *ConnectorAction `json:"action"`
Config common.Object `json:"config"`
}
// Connection is a per-tenant configuration of a connector
type Connection struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Name string `json:"name"`
Description string `json:"description"`
Tags common.Tags `json:"tags,omitempty"`
Connector *Connector `json:"connector,omitempty"`
Actions []*ConnectorAction `json:"actions,omitempty"`
AuthType AuthType `json:"authType"`
AuthURL *string `json:"authUrl,omitempty"`
Config common.Object `json:"config,omitempty"`
Credentials common.Object `json:"credentials,omitempty"`
Sequence *int64 `json:"sequence,omitempty"`
}
// ConnectionInput defines the mutable fields of a connection
type ConnectionInput struct {
Name string `json:"name"`
Description string `json:"description"`
Tags common.Tags `json:"tags"`
Config common.Object `json:"config"`
Credentials common.Object `json:"credentials"`
AuthType AuthType `json:"authType"`
AuthURL *string `json:"authUrl"`
Actions []string `json:"actions"`
}
type ActionLookup struct {
ConnectorName string
ImplementedConnectorInterfaceName string
ConnectorInterfaceActionName string
Namespace string
}
type GetConnectorsInput struct {
ConnectionMethodIDs []string
ConnectorInterfaceIDs []string
ConnectorCategoryIDs []string
Tags []string
}
func (c *Connector) LookupAction(name string) *ConnectorAction {
for _, t := range c.Implements {
for _, a := range t.Actions {
if strings.EqualFold(a.Name, name) {
return a
}
}
}
return nil
}
func (c *ConnectorInterface) LookupAction(name string) *ConnectorAction {
for _, a := range c.Actions {
if strings.EqualFold(a.Name, name) {
return a
}
}
return nil
}
func (a AuthType) IsValid() bool {
for _, at := range AllAuthType {
if a == at {
return true
}
}
return false
}
func (a AuthType) String() string {
return string(a)
}
func (a *AuthType) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*a = AuthType(str)
if !a.IsValid() {
return fmt.Errorf("%s is not a valid AuthType", str)
}
return nil
}
func (a AuthType) MarshalGQL(w io.Writer) {
_, _ = fmt.Fprint(w, strconv.Quote(a.String()))
}
func (a *AuthType) UnmarshalJSON(v []byte) error {
*a = AuthType(strings.Trim(string(v), "'\""))
if !a.IsValid() {
return fmt.Errorf("%s is not a valid AuthType", a.String())
}
return nil
}
func (a AuthType) MarshalJSON() ([]byte, error) {
return []byte(strconv.Quote(a.String())), nil
}
func (a AuthType) IsOAuthType() bool {
for _, auth := range OAuthType {
if auth == a {
return true
}
}
return false
}