/
connectors.go
261 lines (223 loc) · 9.33 KB
/
connectors.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package main
import (
"fmt"
"os"
"github.com/secureworks/taegis-sdk-go/graphql"
"github.com/secureworks/taegis-sdk-go/common"
"github.com/secureworks/taegis-sdk-go/orchestration/connectors"
"github.com/davecgh/go-spew/spew"
"github.com/gofrs/uuid"
)
const (
TENANT_ID = "123456789"
)
func errTest(err error) {
if err != nil {
spew.Dump(err)
os.Exit(1)
}
}
func main() {
connectorsSvc := connectors.New("test.com")
testObjMetaInput := common.ObjectMetaInput{
Name: "test",
Description: nil,
Tags: nil,
}
//Define a ConnectionMethod
connectionMethodInput := connectors.ConnectionMethodInput{
ObjectMetaInput: testObjMetaInput,
URL: "test.com",
}
definedConnectionMethod, err := connectorsSvc.DefineConnectionMethod(&connectionMethodInput)
errTest(err)
//connectionMethod represents a ConnectionMethod Output
//use dot notations to access specific ConnectionMethod fields
fmt.Printf("CONNECTION METHOD NAME: %v\n", definedConnectionMethod.Name)
fmt.Printf("CONNECTION METHOD DESCRIPTION: %v\n", definedConnectionMethod.Description)
connectionMethod, err := connectorsSvc.GetConnectionMethod("test")
errTest(err)
//connectionMethod represents a ConnectionMethod Output
//use dot notations to access specific ConnectionMethod fields
fmt.Printf("CONNECTION METHOD NAME: %v\n", connectionMethod.Name)
fmt.Printf("CONNECTION METHOD DESCRIPTION: %v\n", connectionMethod.Description)
//Remove a ConnectionMethod
removedConnectionMethod, err := connectorsSvc.RemoveConnectionMethod(connectionMethod.ID)
//connectionMethod represents a ConnectionMethod Output
//use dot notations to access specific ConnectionMethod fields
fmt.Printf("CONNECTION METHOD NAME: %v\n", removedConnectionMethod.Name)
fmt.Printf("CONNECTION METHOD DESCRIPTION: %v\n", removedConnectionMethod.Description)
connectionInput := connectors.GetConnectionsInput{
ConnectionIDs: []string{"1234"},
ConnectorIDs: nil,
ConnectorInterfaceIDs: nil,
}
connections, err := connectorsSvc.GetConnections(&connectionInput)
errTest(err)
for _, connection := range connections {
//connection represents a Connection Output
//use dot notations to access specific Connection fields
fmt.Printf("CONNECTION NAME: %v\n", connection.Name)
fmt.Printf("CONNECTION DESCRIPTION: %v\n", connection.Description)
}
connectorInput := connectors.GetConnectorsInput{
ConnectionMethodIDs: []string{"test"},
ConnectorInterfaceIDs: nil,
ConnectorCategoryIDs: nil,
Tags: nil,
}
//connectors represents an array of Connector
connectorsArr, err := connectorsSvc.GetConnectors(&connectorInput)
errTest(err)
for _, connector := range connectorsArr {
//connector represents a Connector Output
//use dot notations to access specific Connector fields
fmt.Printf("CONNECTOR NAME: %v\n", connector.Name)
fmt.Printf("CONNECTOR DESCRIPTION: %v\n", connector.Description)
}
context, err := connectorsSvc.GetContext(&connectionInput, graphql.RequestWithTenant(TENANT_ID))
errTest(err)
//context represents a Context Output
//use dot notation to access specific Context fields
fmt.Printf("CONTEXT TENANT ID: %v\n", context.TenantID)
fmt.Printf("CONTEXT USER ID: %v\n", context.UserID)
for _, connection := range context.Connections {
//connection represents a Connection Output
//use dot notations to access specific Connection fields
fmt.Printf("CONTEXT CONNECTION NAME: %v\n", connection.Name)
fmt.Printf("CONTEXT CONNECTION DESCRIPTION: %v\n", connection.Description)
}
//Create a ConnectorInterface
connectorInterfaceInput := connectors.ConnectorInterfaceInput{
ObjectMetaInput: testObjMetaInput,
Categories: nil,
Actions: nil,
AllTenants: nil,
}
connectorInterface, err := connectorsSvc.CreateConnectorInterface(&connectorInterfaceInput)
errTest(err)
//connectorInterface represents a ConnectorInterface Output
//use dot notations to access specific ConnectorInterface fields
fmt.Printf("CONNECTOR INTERFACE NAME: %v\n", connectorInterface.Name)
fmt.Printf("CONNECTOR INTERFACE DESCRIPTION: %v\n", connectorInterface.Description)
//Get ConnectorInterface
connectorInterface, err = connectorsSvc.GetConnectorInterface(connectorInterface.ID)
errTest(err)
//connectorInterface represents a ConnectorInterface Output
//use dot notations to access specific ConnectorInterface fields
fmt.Printf("CONNECTOR INTERFACE NAME: %v\n", connectorInterface.Name)
fmt.Printf("CONNECTOR INTERFACE DESCRIPTION: %v\n", connectorInterface.Description)
//Update ConnectorInterface
connectorInterface, err = connectorsSvc.UpdateConnectorInterface(connectorInterface.ID, &connectorInterfaceInput)
errTest(err)
//connectorInterface represents a ConnectorInterface Output
//use dot notations to access specific ConnectorInterface fields
fmt.Printf("CONNECTOR INTERFACE NAME: %v\n", connectorInterface.Name)
fmt.Printf("CONNECTOR INTERFACE DESCRIPTION: %v\n", connectorInterface.Description)
//Delete ConnectorInterface
connectorInterface, err = connectorsSvc.DeleteConnectorInterface(connectorInterface.ID)
errTest(err)
//connectorInterface represents a ConnectorInterface Output
//use dot notations to access specific ConnectorInterface fields
fmt.Printf("DELETED CONNECTOR INTERFACE NAME: %v\n", connectorInterface.Name)
fmt.Printf("DELETED CONNECTOR INTERFACE DESCRIPTION: %v\n", connectorInterface.Description)
//Create Connector
connectorIn := connectors.ConnectorInput{
ObjectMetaInput: testObjMetaInput,
Implements: nil,
Parameters: nil,
AuthTypes: nil,
AllTenants: nil,
Actions: nil,
Documentation: nil,
Categories: nil,
}
connector, err := connectorsSvc.CreateConnector("123", &connectorIn)
errTest(err)
//connector represents a Connector Output
//use dot notations to access specific Connector fields
fmt.Printf("CONNECTOR NAME: %v\n", connector.Name)
fmt.Printf("CONNECTOR DESCRIPTION: %v\n", connector.Description)
//Get Connector
connector, err = connectorsSvc.GetConnector(connector.ID)
errTest(err)
//connector represents a Connector Output
//use dot notations to access specific Connector fields
fmt.Printf("CONNECTOR NAME: %v\n", connector.Name)
fmt.Printf("CONNECTOR DESCRIPTION: %v\n", connector.Description)
id, _ := uuid.NewV4()
connectorUpdateInput := connectors.ConnectorUpdateInput{
Name: "new name",
Description: "updated connector",
Implements: nil,
AuthTypes: []connectors.AuthType{connectors.AuthTypeBasic},
Documentation: "",
Actions: nil,
Categories: common.IDs{"123"},
Tags: nil,
}
//Update Connector
connector, err = connectorsSvc.UpdateConnector(connector.ID, &connectorUpdateInput)
errTest(err)
//connector represents a Connector Output
//use dot notations to access specific Connector fields
fmt.Printf("UPDATED CONNECTOR NAME: %v\n", connector.Name)
fmt.Printf("UPDATED CONNECTOR DESCRIPTION: %v\n", connector.Description)
//Delete Connector
connector, err = connectorsSvc.DeleteConnector(connector.ID)
errTest(err)
//connector represents a Connector Output
//use dot notations to access specific Connector fields
fmt.Printf("DELETED CONNECTOR NAME: %v\n", connector.Name)
fmt.Printf("DELETED CONNECTOR DESCRIPTION: %v\n", connector.Description)
//Get ConnectorCategory
connectorCategory, err := connectorsSvc.GetConnectorCategory(id.String())
errTest(err)
//connectorCategory represents a ConnectorCategory Output
//use dot notations to access specific ConnectorCategory fields
fmt.Printf("CONNECTOR CATEGORY NAME: %v\n", connectorCategory.Name)
fmt.Printf("CONNECTOR CATEGORY DESCRIPTION: %v\n", connectorCategory.Description)
conInput := connectors.ConnectionInput{
Name: "test",
Description: "test",
Tags: nil,
Config: nil,
Credentials: nil,
AuthType: connectors.AuthTypeBasic,
AuthURL: nil,
Actions: nil,
}
//Create Connection
connection, err := connectorsSvc.CreateConnection("123", &conInput)
errTest(err)
//connection represents a Connection Output
//use dot notations to access specific Connection fields
fmt.Printf("CONNECTION NAME: %v\n", connection.Name)
fmt.Printf("CONNECTION DESCRIPTION: %v\n", connection.Description)
//Get Connection
connection, err = connectorsSvc.GetConnection(connection.ID)
errTest(err)
//connection represents a Connection Output
//use dot notations to access specific Connection fields
fmt.Printf("CONNECTION NAME: %v\n", connection.Name)
fmt.Printf("CONNECTION DESCRIPTION: %v\n", connection.Description)
//Update Connection
connection, err = connectorsSvc.UpdateConnection(connection.ID, &conInput)
errTest(err)
//connection represents a Connection Output
//use dot notations to access specific Connection fields
fmt.Printf("CONNECTION NAME: %v\n", connection.Name)
fmt.Printf("CONNECTION DESCRIPTION: %v\n", connection.Description)
//Execute Connection Action
action, err := connectorsSvc.ExecuteConnectionAction(connection.ID, "test", nil)
errTest(err)
//action represents an interface
//Cast this interface to your expected type
fmt.Printf("ACTION INTERFACE: %v\n", action)
//Delete Connection
connection, err = connectorsSvc.DeleteConnection(connection.ID)
//connection represents a Connection Output
//use dot notations to access specific Connection fields
fmt.Printf("DELETED CONNECTION NAME: %v\n", connection.Name)
fmt.Printf("DELETED CONNECTION DESCRIPTION: %v\n", connection.Description)
}