-
Notifications
You must be signed in to change notification settings - Fork 13
/
actions.go
246 lines (227 loc) · 9.19 KB
/
actions.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
package opslevel
import (
"fmt"
)
type CustomActionsId struct {
Aliases []string `graphql:"aliases"`
Id ID `graphql:"id"`
}
type CustomActionsWebhookAction struct {
Headers JSON `graphql:"headers" scalar:"true"`
HTTPMethod CustomActionsHttpMethodEnum `graphql:"httpMethod"`
WebhookURL string `graphql:"webhookUrl"`
}
type CustomActionsTriggerDefinition struct {
Action CustomActionsId `graphql:"action"`
Aliases []string `graphql:"aliases"`
Description string `graphql:"description"`
Filter FilterId `graphql:"filter"`
Id ID `graphql:"id"`
ManualInputsDefinition string `graphql:"manualInputsDefinition"`
Name string `graphql:"name"`
Owner TeamId `graphql:"owner"`
Published bool `graphql:"published"`
Timestamps Timestamps `graphql:"timestamps"`
AccessControl CustomActionsTriggerDefinitionAccessControlEnum `graphql:"accessControl"`
ResponseTemplate string `graphql:"responseTemplate"`
EntityType CustomActionsEntityTypeEnum `graphql:"entityType"`
}
func (customActionsTriggerDefinition *CustomActionsTriggerDefinition) ExtendedTeamAccess(client *Client, variables *PayloadVariables) (*TeamConnection, error) {
var q struct {
Account struct {
CustomActionsTriggerDefinition struct {
ExtendedTeamAccess TeamConnection `graphql:"extendedTeamAccess(after: $after, first: $first)"`
} `graphql:"customActionsTriggerDefinition(input: $input)"`
}
}
if customActionsTriggerDefinition.Id == "" {
return nil, fmt.Errorf("unable to get teams with ExtendedTeamAccess, invalid CustomActionsTriggerDefinition id: '%s'", customActionsTriggerDefinition.Id)
}
if variables == nil {
variables = client.InitialPageVariablesPointer()
}
(*variables)["input"] = *NewIdentifier(string(customActionsTriggerDefinition.Id))
if err := client.Query(&q, *variables, WithName("ExtendedTeamAccessList")); err != nil {
return nil, err
}
for q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.PageInfo.End
resp, err := customActionsTriggerDefinition.ExtendedTeamAccess(client, variables)
if err != nil {
return nil, err
}
q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.Nodes = append(q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.Nodes, resp.Nodes...)
q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.PageInfo = resp.PageInfo
q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess.TotalCount += resp.TotalCount
}
return &q.Account.CustomActionsTriggerDefinition.ExtendedTeamAccess, nil
}
type CustomActionsExternalActionsConnection struct {
Nodes []CustomActionsExternalAction
PageInfo PageInfo
TotalCount int
}
type CustomActionsTriggerDefinitionsConnection struct {
Nodes []CustomActionsTriggerDefinition
PageInfo PageInfo
TotalCount int
}
func (client *Client) CreateWebhookAction(input CustomActionsWebhookActionCreateInput) (*CustomActionsExternalAction, error) {
var m struct {
Payload struct {
WebhookAction CustomActionsExternalAction
Errors []OpsLevelErrors
} `graphql:"customActionsWebhookActionCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("WebhookActionCreate"))
return &m.Payload.WebhookAction, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) GetCustomAction(input string) (*CustomActionsExternalAction, error) {
var q struct {
Account struct {
Action CustomActionsExternalAction `graphql:"customActionsExternalAction(input: $input)"`
}
}
v := PayloadVariables{
"input": *NewIdentifier(input),
}
err := client.Query(&q, v, WithName("ExternalActionGet"))
if q.Account.Action.Id == "" {
err = fmt.Errorf("CustomActionsExternalAction with ID or Alias matching '%s' not found", input)
}
return &q.Account.Action, HandleErrors(err, nil)
}
func (client *Client) ListCustomActions(variables *PayloadVariables) (*CustomActionsExternalActionsConnection, error) {
var q struct {
Account struct {
Actions CustomActionsExternalActionsConnection `graphql:"customActionsExternalActions(after: $after, first: $first)"`
}
}
if variables == nil {
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("ExternalActionList")); err != nil {
return nil, err
}
for q.Account.Actions.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Actions.PageInfo.End
resp, err := client.ListCustomActions(variables)
if err != nil {
return nil, err
}
q.Account.Actions.Nodes = append(q.Account.Actions.Nodes, resp.Nodes...)
q.Account.Actions.PageInfo = resp.PageInfo
}
return &q.Account.Actions, nil
}
func (client *Client) UpdateWebhookAction(input CustomActionsWebhookActionUpdateInput) (*CustomActionsExternalAction, error) {
var m struct {
Payload struct {
WebhookAction CustomActionsExternalAction
Errors []OpsLevelErrors
} `graphql:"customActionsWebhookActionUpdate(input: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("WebhookActionUpdate"))
return &m.Payload.WebhookAction, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) DeleteWebhookAction(input string) error {
var m struct {
Payload struct {
Errors []OpsLevelErrors `graphql:"errors"`
} `graphql:"customActionsWebhookActionDelete(resource: $input)"`
}
v := PayloadVariables{
"input": *NewIdentifier(input),
}
err := client.Mutate(&m, v, WithName("WebhookActionDelete"))
return HandleErrors(err, m.Payload.Errors)
}
func (client *Client) CreateTriggerDefinition(input CustomActionsTriggerDefinitionCreateInput) (*CustomActionsTriggerDefinition, error) {
var m struct {
Payload struct {
TriggerDefinition CustomActionsTriggerDefinition
Errors []OpsLevelErrors
} `graphql:"customActionsTriggerDefinitionCreate(input: $input)"`
}
if input.AccessControl == nil {
input.AccessControl = RefOf(CustomActionsTriggerDefinitionAccessControlEnumEveryone)
}
if input.EntityType == nil {
input.EntityType = RefOf(CustomActionsEntityTypeEnumService)
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("TriggerDefinitionCreate"))
return &m.Payload.TriggerDefinition, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) GetTriggerDefinition(input string) (*CustomActionsTriggerDefinition, error) {
var q struct {
Account struct {
Definition CustomActionsTriggerDefinition `graphql:"customActionsTriggerDefinition(input: $input)"`
}
}
v := PayloadVariables{
"input": *NewIdentifier(input),
}
err := client.Query(&q, v, WithName("TriggerDefinitionGet"))
if q.Account.Definition.Id == "" {
err = fmt.Errorf("CustomActionsTriggerDefinition with ID or Alias matching '%s' not found", input)
}
return &q.Account.Definition, HandleErrors(err, nil)
}
func (client *Client) ListTriggerDefinitions(variables *PayloadVariables) (*CustomActionsTriggerDefinitionsConnection, error) {
var q struct {
Account struct {
Definitions CustomActionsTriggerDefinitionsConnection `graphql:"customActionsTriggerDefinitions(after: $after, first: $first)"`
}
}
if variables == nil {
variables = client.InitialPageVariablesPointer()
}
if err := client.Query(&q, *variables, WithName("TriggerDefinitionList")); err != nil {
return nil, err
}
for q.Account.Definitions.PageInfo.HasNextPage {
(*variables)["after"] = q.Account.Definitions.PageInfo.End
resp, err := client.ListTriggerDefinitions(variables)
if err != nil {
return nil, err
}
q.Account.Definitions.Nodes = append(q.Account.Definitions.Nodes, resp.Nodes...)
q.Account.Definitions.PageInfo = resp.PageInfo
q.Account.Definitions.TotalCount += resp.TotalCount
}
return &q.Account.Definitions, nil
}
func (client *Client) UpdateTriggerDefinition(input CustomActionsTriggerDefinitionUpdateInput) (*CustomActionsTriggerDefinition, error) {
var m struct {
Payload struct {
TriggerDefinition CustomActionsTriggerDefinition
Errors []OpsLevelErrors
} `graphql:"customActionsTriggerDefinitionUpdate(input: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("TriggerDefinitionUpdate"))
return &m.Payload.TriggerDefinition, HandleErrors(err, m.Payload.Errors)
}
func (client *Client) DeleteTriggerDefinition(input string) error {
var m struct {
Payload struct {
Errors []OpsLevelErrors `graphql:"errors"`
} `graphql:"customActionsTriggerDefinitionDelete(resource: $input)"`
}
v := PayloadVariables{
"input": *NewIdentifier(input),
}
err := client.Mutate(&m, v, WithName("TriggerDefinitionDelete"))
return HandleErrors(err, m.Payload.Errors)
}