forked from OpsLevel/opslevel-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.go
119 lines (99 loc) · 3.06 KB
/
tools.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
package opslevel
type Tool struct {
Category ToolCategory
CategoryAlias string `json:",omitempty"`
DisplayName string
Environment string `json:",omitempty"`
Id ID `json:",omitempty"`
Url string
Service ServiceId
}
type ToolConnection struct {
Nodes []Tool
PageInfo PageInfo
TotalCount int
}
type ToolCreateInput struct {
Category ToolCategory `json:"category"`
DisplayName string `json:"displayName"`
Url string `json:"url"`
Environment string `json:"environment,omitempty"`
ServiceId ID `json:"serviceId,omitempty"`
ServiceAlias string `json:"serviceAlias,omitempty"`
}
type ToolUpdateInput struct {
Id ID `json:"id"`
Category ToolCategory `json:"category,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Url string `json:"url,omitempty"`
Environment string `json:"environment,omitempty"`
}
type ToolDeleteInput struct {
Id ID `json:"id"`
}
//#region Create
func (client *Client) CreateTool(input ToolCreateInput) (*Tool, error) {
// TODO: validate - Category, DisplayName & Url are non nil - or throw err
var m struct {
Payload struct {
Tool Tool
Errors []OpsLevelErrors
} `graphql:"toolCreate(input: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("ToolCreate"))
return &m.Payload.Tool, HandleErrors(err, m.Payload.Errors)
}
//#endregion
//#region Retrieve
// Deprecated: Use client.GetServiceWithAlias(alias).Tools instead
func (client *Client) GetToolsForServiceWithAlias(alias string) ([]Tool, error) {
service, serviceErr := client.GetServiceWithAlias(alias)
return service.Tools.Nodes, serviceErr
}
// Deprecated: Use GetToolsForService instead
func (client *Client) GetToolsForServiceWithId(id ID) ([]Tool, error) {
return client.GetToolsForService(id, nil)
}
// Deprecated: Use client.GetService(id).Tools instead
func (client *Client) GetToolsForService(id ID, variables *PayloadVariables) ([]Tool, error) {
service, serviceErr := client.GetService(id)
return service.Tools.Nodes, serviceErr
}
// Deprecated: Use client.GetService(id).Tools.TotalCount instead
func (client *Client) GetToolCount(id ID) (int, error) {
service, serviceErr := client.GetService(id)
return service.Tools.TotalCount, serviceErr
}
//#endregion
//#region Update
func (client *Client) UpdateTool(input ToolUpdateInput) (*Tool, error) {
var m struct {
Payload struct {
Tool Tool
Errors []OpsLevelErrors
} `graphql:"toolUpdate(input: $input)"`
}
v := PayloadVariables{
"input": input,
}
err := client.Mutate(&m, v, WithName("ToolUpdate"))
return &m.Payload.Tool, HandleErrors(err, m.Payload.Errors)
}
//#endregion
//#region Delete
func (client *Client) DeleteTool(id ID) error {
var m struct {
Payload struct {
Errors []OpsLevelErrors
} `graphql:"toolDelete(input: $input)"`
}
v := PayloadVariables{
"input": ToolDeleteInput{Id: id},
}
err := client.Mutate(&m, v, WithName("ToolDelete"))
return HandleErrors(err, m.Payload.Errors)
}
//#endregion