-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathincident_type.go
358 lines (287 loc) · 13.2 KB
/
incident_type.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
package pagerduty
import (
"context"
"github.com/google/go-querystring/query"
)
// IncidentType is allows to categorize incidents, such as a security incident, a major incident, or a fraud incident.
type IncidentType struct {
Enabled bool `json:"enabled,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Parent *APIReference `json:"parent,omitempty"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
DisplayName string `json:"display_name,omitempty"`
}
type incidentTypeResponse struct {
IncidentType IncidentType `json:"incident_type"`
}
// ListIncidentsTypesOptions is the structure used when passing parameters to the ListIncidentTypes API endpoint.
type ListIncidentTypesOptions struct {
Filter string `url:"filter,omitempty"` // enabled disabled all
}
// ListIncidentsTypesResponse is the response structure when calling the ListIncidentTypes API endpoint.
type ListIncidentTypesResponse struct {
IncidentTypes []IncidentType `json:"incident_types"`
}
// ListIncidentTypes list the available incident types.
func (c *Client) ListIncidentTypes(ctx context.Context, o ListIncidentTypesOptions) (*ListIncidentTypesResponse, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
}
resp, err := c.get(ctx, "/incidents/types?"+v.Encode(), nil)
if err != nil {
return nil, err
}
var result ListIncidentTypesResponse
err = c.decodeJSON(resp, &result)
return &result, err
}
// CreateIncidentTypeOptions contains the parameters for creating a new incident type.
type CreateIncidentTypeOptions struct {
Name string `json:"name"`
DisplayName string `json:"display_name"`
ParentType string `json:"parent_type"`
Enabled *bool `json:"enabled,omitempty"`
Description *string `json:"description,omitempty"`
}
// CreateIncidentType creates a new incident type.
func (c *Client) CreateIncidentType(ctx context.Context, o CreateIncidentTypeOptions) (*IncidentType, error) {
d := map[string]CreateIncidentTypeOptions{
"incident_type": o,
}
resp, err := c.post(ctx, "/incidents/types", d, nil)
if err != nil {
return nil, err
}
var result incidentTypeResponse
err = c.decodeJSON(resp, &result)
return &result.IncidentType, err
}
// GetIncidentTypeOptions contains the parameters for retrieving a specific incident type.
type GetIncidentTypeOptions struct{}
// GetIncidentType retrieves a specific incident type by ID or name.
func (c *Client) GetIncidentType(ctx context.Context, idOrName string, o GetIncidentTypeOptions) (*IncidentType, error) {
resp, err := c.get(ctx, "/incidents/types/"+idOrName, nil)
if err != nil {
return nil, err
}
var result incidentTypeResponse
err = c.decodeJSON(resp, &result)
return &result.IncidentType, err
}
// UpdateIncidentTypeOptions contains the parameters for updating an incident type.
type UpdateIncidentTypeOptions struct {
DisplayName *string `json:"display_name,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Description *string `json:"description,omitempty"`
}
// UpdateIncidentType updates an existing incident type with the provided options.
func (c *Client) UpdateIncidentType(ctx context.Context, idOrName string, o UpdateIncidentTypeOptions) (*IncidentType, error) {
d := map[string]UpdateIncidentTypeOptions{
"incident_type": o,
}
resp, err := c.put(ctx, "/incidents/types/"+idOrName, d, nil)
if err != nil {
return nil, err
}
var result incidentTypeResponse
err = c.decodeJSON(resp, &result)
return &result.IncidentType, err
}
// IncidentTypeField represents a custom field configuration for an incident type.
type IncidentTypeField struct {
Enabled bool `json:"enabled,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Self string `json:"self,omitempty"`
Description string `json:"description,omitempty"`
FieldType string `json:"field_type,omitempty"` // single_value single_value_fixed multi_value multi_value_fixed
DataType string `json:"data_type,omitempty"` // boolean integer float string datetime url
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
DisplayName string `json:"display_name,omitempty"`
DefaultValue interface{} `json:"default_value,omitempty"`
IncidentType string `json:"incident_type,omitempty"`
Summary string `json:"summary,omitempty"`
FieldOptions []IncidentTypeFieldOption `json:"field_options,omitempty"`
}
// IncidentTypeFieldOption represents an option for a custom field.
type IncidentTypeFieldOption struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
Data *IncidentTypeFieldOptionData `json:"data,omitempty"`
}
// IncidentTypeFieldOptionData represents the data for a field option.
type IncidentTypeFieldOptionData struct {
Value string `json:"value,omitempty"`
DataType string `json:"data_type,omitempty"`
}
// ListIncidentTypeFieldsOptions contains the parameters for listing incident type fields.
type ListIncidentTypeFieldsOptions struct {
Includes []string `url:"include,omitempty,brackets"`
}
// ListIncidentTypeFieldsResponse represents the response from listing incident type fields.
type ListIncidentTypeFieldsResponse struct {
Fields []IncidentTypeField `json:"fields,omitempty"`
}
// ListIncidentTypeFields retrieves all custom fields for a specific incident type.
func (c *Client) ListIncidentTypeFields(ctx context.Context, typeIDOrName string, o ListIncidentTypeFieldsOptions) (*ListIncidentTypeFieldsResponse, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
}
resp, err := c.get(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields?"+v.Encode(), nil)
if err != nil {
return nil, err
}
var result ListIncidentTypeFieldsResponse
err = c.decodeJSON(resp, &result)
return &result, err
}
type incidentTypeFieldsResponse struct {
Field IncidentTypeField `json:"field"`
}
// CreateIncidentTypeFieldOptions contains the parameters for creating a new incident type field.
type CreateIncidentTypeFieldOptions struct {
Name string `json:"name"`
DisplayName string `json:"display_name"`
DataType string `json:"data_type"` // boolean integer float string datetime url
FieldType string `json:"field_type"` // single_value single_value_fixed multi_value multi_value_fixed
DefaultValue interface{} `json:"default_value,omitempty"`
Description *string `json:"description,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
FieldOptions []IncidentTypeFieldOption `json:"field_options,omitempty"`
}
// CreateIncidentTypeField creates a new custom field for a specific incident type.
func (c *Client) CreateIncidentTypeField(ctx context.Context, typeIDOrName string, o CreateIncidentTypeFieldOptions) (*IncidentTypeField, error) {
d := map[string]CreateIncidentTypeFieldOptions{
"field": o,
}
resp, err := c.post(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields", d, nil)
if err != nil {
return nil, err
}
var result incidentTypeFieldsResponse
err = c.decodeJSON(resp, &result)
return &result.Field, err
}
// GetIncidentTypeFieldOptions contains the parameters for retrieving a specific incident type field.
type GetIncidentTypeFieldOptions struct {
Includes []string `url:"include,omitempty,brackets"`
}
// GetIncidentTypeField retrieves a specific custom field for an incident type.
func (c *Client) GetIncidentTypeField(ctx context.Context, typeIDOrName string, fieldID string, o GetIncidentTypeFieldOptions) (*IncidentTypeField, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
}
resp, err := c.get(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields/"+fieldID+"?"+v.Encode(), nil)
if err != nil {
return nil, err
}
var result incidentTypeFieldsResponse
err = c.decodeJSON(resp, &result)
return &result.Field, err
}
// UpdateIncidentTypeFieldOptions contains the parameters for updating an incident type field.
type UpdateIncidentTypeFieldOptions struct {
DisplayName *string `json:"display_name,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
DefaultValue *interface{} `json:"default_value,omitempty"`
Description *string `json:"description,omitempty"`
}
// UpdateIncidentTypeField updates an existing custom field for an incident type.
func (c *Client) UpdateIncidentTypeField(ctx context.Context, typeIDOrName, fieldID string, o UpdateIncidentTypeFieldOptions) (*IncidentTypeField, error) {
d := map[string]UpdateIncidentTypeFieldOptions{
"field": o,
}
resp, err := c.put(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields/"+fieldID, d, nil)
if err != nil {
return nil, err
}
var result incidentTypeFieldsResponse
err = c.decodeJSON(resp, &result)
return &result.Field, err
}
// DeleteIncidentTypeField removes a custom field from an incident type.
func (c *Client) DeleteIncidentTypeField(ctx context.Context, typeIDOrName, fieldID string) error {
_, err := c.delete(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields/"+fieldID)
return err
}
// ListIncidentTypeFieldOptionsOptions contains the parameters for listing field options.
type ListIncidentTypeFieldOptionsOptions struct{}
// ListIncidentTypeFieldOptionsResponse represents the response from listing field options.
type ListIncidentTypeFieldOptionsResponse struct {
FieldOptions []IncidentTypeFieldOption `json:"field_options,omitempty"`
}
// ListIncidentTypeFieldOptions retrieves all options for a specific custom field.
func (c *Client) ListIncidentTypeFieldOptions(ctx context.Context, typeIDOrName, fieldID string, o ListIncidentTypeFieldOptionsOptions) (*ListIncidentTypeFieldOptionsResponse, error) {
resp, err := c.get(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields/"+fieldID+"/field_options", nil)
if err != nil {
return nil, err
}
var result ListIncidentTypeFieldOptionsResponse
err = c.decodeJSON(resp, &result)
return &result, err
}
type incidentTypeFieldOptionsResponse struct {
FieldOption IncidentTypeFieldOption `json:"field_option,omitempty"`
}
// CreateIncidentTypeFieldOptionPayload contains the parameters for creating a new field option.
type CreateIncidentTypeFieldOptionPayload struct {
Data *IncidentTypeFieldOptionData `json:"data,omitempty"`
}
// CreateIncidentTypeFieldOption creates a new option for a custom field.
func (c *Client) CreateIncidentTypeFieldOption(ctx context.Context, typeIDOrName, fieldID string, o CreateIncidentTypeFieldOptionPayload) (*IncidentTypeFieldOption, error) {
d := map[string]CreateIncidentTypeFieldOptionPayload{
"field_option": o,
}
resp, err := c.post(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields/"+fieldID+"/field_options", d, nil)
if err != nil {
return nil, err
}
var result incidentTypeFieldOptionsResponse
err = c.decodeJSON(resp, &result)
return &result.FieldOption, err
}
// GetIncidentTypeFieldOptionOptions contains the parameters for retrieving a specific field option.
type GetIncidentTypeFieldOptionOptions struct{}
// GetIncidentTypeFieldOption retrieves a specific option for a custom field.
func (c *Client) GetIncidentTypeFieldOption(ctx context.Context, typeIDOrName, fieldID, fieldOptionID string, o GetIncidentTypeFieldOptionOptions) (*IncidentTypeFieldOption, error) {
resp, err := c.get(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields/"+fieldID+"/field_options/"+fieldOptionID, nil)
if err != nil {
return nil, err
}
var result incidentTypeFieldOptionsResponse
err = c.decodeJSON(resp, &result)
return &result.FieldOption, err
}
// UpdateIncidentTypeFieldOptionPayload contains the parameters for updating a field option.
type UpdateIncidentTypeFieldOptionPayload struct {
ID string `json:"id,omitempty"`
Data *IncidentTypeFieldOptionData `json:"data,omitempty"`
}
// UpdateIncidentTypeFieldOption updates an existing option for a custom field.
func (c *Client) UpdateIncidentTypeFieldOption(ctx context.Context, typeIDOrName, fieldID string, o UpdateIncidentTypeFieldOptionPayload) (*IncidentTypeFieldOption, error) {
d := map[string]UpdateIncidentTypeFieldOptionPayload{
"field_option": o,
}
resp, err := c.put(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields/"+fieldID+"/field_options/"+o.ID, d, nil)
if err != nil {
return nil, err
}
var result incidentTypeFieldOptionsResponse
err = c.decodeJSON(resp, &result)
return &result.FieldOption, err
}
// DeleteIncidentTypeFieldOption removes an option from a custom field.
func (c *Client) DeleteIncidentTypeFieldOption(ctx context.Context, typeIDOrName, fieldID, fieldOptionID string) error {
_, err := c.delete(ctx, "/incidents/types/"+typeIDOrName+"/custom_fields/"+fieldID+"/field_options/"+fieldOptionID)
return err
}