-
Notifications
You must be signed in to change notification settings - Fork 11
/
wikis.go
305 lines (274 loc) · 8.88 KB
/
wikis.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
package morpheus
import (
"fmt"
)
var (
// WikisPath is the API endpoint for wikis
WikisPath = "/api/wiki/pages"
// WikiCategoriesPath is the API endpoint for wiki categories
WikiCategoriesPath = "/api/wiki/categories"
)
// Wiki structures for use in request and response payloads
type Wiki struct {
ID int64 `json:"id"`
Name string `json:"name"`
UrlName string `json:"urlName"`
Category string `json:"category"`
RefID int64 `json:"refId"`
RefType string `json:"refType"`
Format string `json:"format"`
Content string `json:"content"`
CreatedBy struct {
ID int64 `json:"id"`
Username string `json:"username"`
}
UpdatedBy struct {
ID int64 `json:"id"`
Username string `json:"username"`
}
DateCreated string `json:"dateCreated"`
LastUpdated string `json:"lastUpdated"`
}
// CreateWiki structure defines the create wiki payload
type CreateWiki struct {
Name string `json:"name"`
Category string `json:"category"`
Content string `json:"content"`
}
// WikiCategory structure defines the wiki category payload
type WikiCategory struct {
Name string `json:"name"`
PageCount int64 `json:"pageCount"`
}
type ListWikisResult struct {
Wikis *[]Wiki `json:"pages"`
Meta *MetaResult `json:"meta"`
}
type ListWikiCategoriesResult struct {
WikiCategories *[]WikiCategory `json:"categories"`
Meta *MetaResult `json:"meta"`
}
type GetWikiResult struct {
Wiki *Wiki `json:"page"`
}
type CreateWikiResult struct {
Success bool `json:"success"`
Message string `json:"msg"`
Errors map[string]string `json:"errors"`
Wiki *Wiki `json:"page"`
}
type UpdateWikiResult struct {
CreateWikiResult
}
type DeleteWikiResult struct {
DeleteResult
}
// Client request methods
// ListWikis lists all the wikis
// https://apidocs.morpheusdata.com/#get-all-wiki-pages
func (client *Client) ListWikis(req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: WikisPath,
QueryParams: req.QueryParams,
Result: &ListWikisResult{},
})
}
// ListWikiCategories lists all wiki categories
// https://apidocs.morpheusdata.com/#get-all-wiki-categories
func (client *Client) ListWikiCategories(req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: WikiCategoriesPath,
QueryParams: req.QueryParams,
Result: &ListWikiCategoriesResult{},
})
}
// GetAppWiki gets a wiki
// https://apidocs.morpheusdata.com/#get-a-specific-wiki-page
func (client *Client) GetWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: fmt.Sprintf("%s/%d", WikisPath, id),
QueryParams: req.QueryParams,
Result: &GetWikiResult{},
})
}
// GetInstanceWiki gets an instance wiki
// https://apidocs.morpheusdata.com/#get-a-wiki-page-for-instance
func (client *Client) GetInstanceWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: fmt.Sprintf("/api/instances/%d/wiki", id),
QueryParams: req.QueryParams,
Result: &GetWikiResult{},
})
}
// GetAppWiki gets an app wiki
// https://apidocs.morpheusdata.com/#get-a-wiki-page-for-app
func (client *Client) GetAppWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: fmt.Sprintf("/api/apps/%d/wiki", id),
QueryParams: req.QueryParams,
Result: &GetWikiResult{},
})
}
// GetClusterWiki gets a cluster wiki
// https://apidocs.morpheusdata.com/#get-a-wiki-page-for-cluster
func (client *Client) GetClusterWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: fmt.Sprintf("/api/clusters/%d/wiki", id),
QueryParams: req.QueryParams,
Result: &GetWikiResult{},
})
}
// GetServerWiki gets a server wiki
// https://apidocs.morpheusdata.com/#get-a-wiki-page-for-server
func (client *Client) GetServerWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: fmt.Sprintf("/api/servers/%d/wiki", id),
QueryParams: req.QueryParams,
Result: &GetWikiResult{},
})
}
// GetCloudWiki gets a cloud wiki
// https://apidocs.morpheusdata.com/#get-a-wiki-page-for-cloud
func (client *Client) GetCloudWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: fmt.Sprintf("/api/zones/%d/wiki", id),
QueryParams: req.QueryParams,
Result: &GetWikiResult{},
})
}
// GetGroupWiki gets a wiki
// https://apidocs.morpheusdata.com/#get-a-wiki-page-for-group
func (client *Client) GetGroupWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: fmt.Sprintf("/api/groups/%d/wiki", id),
QueryParams: req.QueryParams,
Result: &GetWikiResult{},
})
}
// CreateWiki creates a new wiki
// https://apidocs.morpheusdata.com/#create-a-wiki-page
func (client *Client) CreateWiki(req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "POST",
Path: WikisPath,
QueryParams: req.QueryParams,
Body: req.Body,
Result: &CreateWikiResult{},
})
}
// UpdateWiki updates an existing wiki
// https://apidocs.morpheusdata.com/#update-a-wiki-page
func (client *Client) UpdateWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "PUT",
Path: fmt.Sprintf("%s/%d", WikisPath, id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &UpdateWikiResult{},
})
}
// UpdateInstanceWiki updates an existing instance wiki
// https://apidocs.morpheusdata.com/#update-a-wiki-page-for-instance
func (client *Client) UpdateInstanceWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "PUT",
Path: fmt.Sprintf("/api/instances/%d/wiki", id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &UpdateWikiResult{},
})
}
// UpdateAppWiki updates an existing app wiki
// https://apidocs.morpheusdata.com/#update-a-wiki-page-for-app
func (client *Client) UpdateAppWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "PUT",
Path: fmt.Sprintf("/api/apps/%d/wiki", id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &UpdateWikiResult{},
})
}
// https://apidocs.morpheusdata.com/#update-a-wiki-page-for-cluster
func (client *Client) UpdateClusterWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "PUT",
Path: fmt.Sprintf("/api/clusters/%d/wiki", id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &UpdateWikiResult{},
})
}
// UpdateServerWiki updates an existing server wiki
// https://apidocs.morpheusdata.com/#update-a-wiki-page-for-server
func (client *Client) UpdateServerWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "PUT",
Path: fmt.Sprintf("/api/servers/%d/wiki", id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &UpdateWikiResult{},
})
}
// UpdateCloudWiki updates an existing cloud wiki
// https://apidocs.morpheusdata.com/#update-a-wiki-page-for-cloud
func (client *Client) UpdateCloudWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "PUT",
Path: fmt.Sprintf("/api/zones/%d/wiki", id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &UpdateWikiResult{},
})
}
// UpdateGroupWiki updates an existing group wiki
// https://apidocs.morpheusdata.com/#update-a-wiki-page-for-group
func (client *Client) UpdateGroupWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "PUT",
Path: fmt.Sprintf("/api/groups/%d/wiki", id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &UpdateWikiResult{},
})
}
// DeleteWiki deletes an existing wiki
// https://apidocs.morpheusdata.com/#delete-a-wiki-page
func (client *Client) DeleteWiki(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "DELETE",
Path: fmt.Sprintf("%s/%d", WikisPath, id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &DeleteWikiResult{},
})
}
// FindWikiByName gets an existing wiki by name
func (client *Client) FindWikiByName(name string) (*Response, error) {
// Find by name, then get by ID
resp, err := client.ListWikis(&Request{
QueryParams: map[string]string{
"name": name,
},
})
if err != nil {
return resp, err
}
listResult := resp.Result.(*ListWikisResult)
wikiCount := len(*listResult.Wikis)
if wikiCount != 1 {
return resp, fmt.Errorf("found %d Wikis for %v", wikiCount, name)
}
firstRecord := (*listResult.Wikis)[0]
wikiID := firstRecord.ID
return client.GetWiki(wikiID, &Request{})
}