forked from OpsLevel/opslevel-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert_source.go
108 lines (90 loc) · 2.98 KB
/
alert_source.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
package opslevel
type AlertSourceExternalIdentifier struct {
Type AlertSourceTypeEnum `json:"type"`
ExternalId string `json:"externalId"`
}
type AlertSource struct {
Name string `graphql:"name"`
Description string `graphql:"description"`
Id ID `graphql:"id"`
Type AlertSourceTypeEnum `graphql:"type"`
ExternalId string `graphql:"externalId"`
Integration IntegrationId `graphql:"integration"`
Url string `graphql:"url"`
}
type AlertSourceService struct {
AlertSource AlertSource `graphql:"alertSource"`
Id ID `graphql:"id"`
Service ServiceId `graphql:"service"`
Status AlertSourceStatusTypeEnum `graphql:"status"`
}
type AlertSourceServiceCreateInput struct {
Service IdentifierInput `json:"service"`
Id ID `json:"alertSourceId,omitempty"`
ExternalID *AlertSourceExternalIdentifier `json:"alertSourceExternalIdentifier,omitempty"`
}
type AlertSourceDeleteInput struct {
Id ID `json:"id"`
}
func NewAlertSource(kind AlertSourceTypeEnum, id string) *AlertSourceExternalIdentifier {
output := AlertSourceExternalIdentifier{
Type: kind,
ExternalId: id,
}
return &output
}
//#region Create
func (client *Client) CreateAlertSourceService(input AlertSourceServiceCreateInput) (*AlertSourceService, error) {
var m struct {
Payload struct {
AlertSourceService AlertSourceService
Errors []OpsLevelErrors
} `graphql:"alertSourceServiceCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("AlertSourceServiceCreate"))
return &m.Payload.AlertSourceService, HandleErrors(err, m.Payload.Errors)
}
//#endregion
//#region Retrieve
func (client *Client) GetAlertSourceWithExternalIdentifier(input AlertSourceExternalIdentifier) (*AlertSource, error) {
var q struct {
Account struct {
AlertSource AlertSource `graphql:"alertSource(externalIdentifier: $externalIdentifier)"`
}
}
v := PayloadVariables{
"externalIdentifier": input,
}
err := client.Query(&q, v, WithName("AlertSourceGet"))
return &q.Account.AlertSource, HandleErrors(err, nil)
}
func (client *Client) GetAlertSource(id ID) (*AlertSource, error) {
var q struct {
Account struct {
AlertSource AlertSource `graphql:"alertSource(id: $id)"`
}
}
v := PayloadVariables{
"id": id,
}
err := client.Query(&q, v, WithName("AlertSourceGet"))
return &q.Account.AlertSource, HandleErrors(err, nil)
}
//#endregion
//#region delete
func (client *Client) DeleteAlertSourceService(id ID) error {
var m struct {
Payload struct {
Errors []OpsLevelErrors
} `graphql:"alertSourceServiceDelete(input: $input)"`
}
v := PayloadVariables{
"input": AlertSourceDeleteInput{Id: id},
}
err := client.Mutate(&m, v, WithName("AlertSourceServiceDelete"))
return HandleErrors(err, m.Payload.Errors)
}
//#endregion