forked from fabric8-services/fabric8-wit
/
codebases.go
341 lines (318 loc) · 10.2 KB
/
codebases.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
package design
import (
d "github.com/goadesign/goa/design"
a "github.com/goadesign/goa/design/apidsl"
)
var codebase = a.Type("Codebase", func() {
a.Description(`JSONAPI store for the data of a codebase. See also http://jsonapi.org/format/#document-resource-object`)
a.Attribute("type", d.String, func() {
a.Enum("codebases")
})
a.Attribute("id", d.UUID, "ID of codebase", func() {
a.Example("40bbdd3d-8b5d-4fd6-ac90-7236b669af04")
})
a.Attribute("attributes", codebaseAttributes)
a.Attribute("relationships", codebaseRelationships)
a.Attribute("links", codebaseLinks)
a.Required("type", "attributes")
})
var codebaseAttributes = a.Type("CodebaseAttributes", func() {
a.Description(`JSONAPI store for all the "attributes" of a codebase. +See also see http://jsonapi.org/format/#document-resource-object-attributes`)
a.Attribute("type", d.String, "The codebase type", func() {
a.Example("git")
})
a.Attribute("url", d.String, "The URL of the codebase ", func() {
a.Example("git@github.com:fabric8-services/fabric8-wit.git")
})
a.Attribute("stackId", d.String, "The stack id of the codebase ", func() {
a.Example("java-centos")
})
a.Attribute("createdAt", d.DateTime, "When the codebase was created", func() {
a.Example("2016-11-29T23:18:14Z")
})
a.Attribute("last_used_workspace", d.String, "The last used workspace name of the codebase ", func() {
a.Example("java-centos")
})
})
var codebaseLinks = a.Type("CodebaseLinks", func() {
a.UseTrait("GenericLinksTrait")
a.Attribute("edit", d.String)
})
var codebaseRelationships = a.Type("CodebaseRelations", func() {
a.Attribute("space", relationGeneric, "This defines the owning space")
a.Attribute("workspaces", relationGeneric, "This defines the dependent workspaces")
})
var codebaseListMeta = a.Type("CodebaseListMeta", func() {
a.Attribute("totalCount", d.Integer)
a.Required("totalCount")
})
var workspace = a.Type("Workspace", func() {
a.Description(`JSONAPI store for the data of a workspace. See also http://jsonapi.org/format/#document-resource-object`)
a.Attribute("type", d.String, func() {
a.Enum("workspaces")
})
a.Attribute("attributes", workspaceAttributes)
a.Attribute("links", workspaceLinks)
a.Attribute("relationships", workspaceRelationships)
a.Required("type", "attributes")
})
var workspaceAttributes = a.Type("WorkspaceAttributes", func() {
a.Description(`JSONAPI store for all the "attributes" of a workspace. +See also see http://jsonapi.org/format/#document-resource-object-attributes`)
a.Attribute("id", d.String, "The workspace id", func() {
a.Example("workspacephly8l91tqg0u08x")
})
a.Attribute("name", d.String, "The workspace name", func() {
a.Example("test")
})
a.Attribute("description", d.String, "The workspace description", func() {
a.Example("")
})
a.Attribute("status", d.String, "The workspace status", func() {
a.Example("STOPPED")
})
})
var workspaceRelationships = a.Type("WorkspaceRelations", func() {
a.Attribute("codebase", relationGeneric, "This defines the owning codebase")
})
var workspaceLinks = a.Type("WorkspaceLinks", func() {
a.Attribute("open", d.String, "The workspace 'open' link", func() {
a.Example("http://localhost:8080/wsmaster/api/workspace/workspace28t00rschopreajr")
})
a.Attribute("self", d.String, "The workspace 'self' link", func() {
a.Example("http://localhost:8080/wsmaster/api/workspace/workspace28t00rschopreajr")
})
a.Attribute("ide", d.String, "The workspace 'ide' link", func() {
a.Example("http://localhost:8080/che/test")
})
})
var workspaceEditLinks = a.Type("WorkspaceEditLinks", func() {
a.Attribute("create", d.String)
})
var workspaceOpenLinks = a.Type("WorkspaceOpenLinks", func() {
a.Attribute("open", d.String)
})
var codebaseList = JSONList(
"Codebase", "Holds the list of codebases",
codebase,
pagingLinks,
codebaseListMeta)
var codebaseSingle = JSONSingle(
"Codebase", "Holds a single codebase",
codebase,
nil)
var workspaceList = JSONList(
"Workspace", "Holds the list of workspaces related to a codebase",
workspace,
workspaceEditLinks,
nil)
var workspaceOpen = a.MediaType("application/vnd.workspaceopen+json", func() {
a.TypeName("WorkspaceOpen")
a.Description(`JSONAPI store for the links of a workspace. See also http://jsonapi.org/format/#document-resource-object`)
a.Attribute("links", workspaceOpenLinks)
a.View("default", func() {
a.Attribute("links")
})
})
var cheServerState = a.MediaType("CheServerState", func() {
a.TypeName("CheServerState")
a.Description(`JSONAPI store Che Server state. See also http://jsonapi.org/format/#document-resource-object`)
a.Attributes(func() {
a.Attribute("running", d.Boolean, "Che server state")
a.Attribute("multiTenant", d.Boolean, "Holds info about Che server type - multi-tenant / single-tenant")
})
a.View("default", func() {
a.Attribute("running")
a.Attribute("multiTenant")
})
})
var createWorkspace = a.MediaType("application/vnd.createworkspace+json", func() {
a.UseTrait("jsonapi-media-type")
a.TypeName("CreateWorkspace")
a.Description("Create Workspace")
a.Attributes(func() {
a.Attribute("data", createWorkspaceData)
a.Required("data")
})
a.View("default", func() {
a.Attribute("data")
a.Required("data")
})
})
var createWorkspaceData = a.Type("CreateWorkspaceData", func() {
a.Attribute("attributes", createWorkspaceDataAttributes, "Attributes of the workspace")
})
var createWorkspaceDataAttributes = a.Type("CreateWorkspaceDataAttributes", func() {
a.Attribute("branch", d.String, "The workspace branch")
})
// new version of "list" for migration
var _ = a.Resource("codebase", func() {
a.BasePath("/codebases")
a.Action("show", func() {
a.Routing(
a.GET("/:codebaseID"),
)
a.Description("Retrieve codebase with given id.")
a.Params(func() {
a.Param("codebaseID", d.UUID, "Codebase Identifier")
})
a.Response(d.OK, func() {
a.Media(codebaseSingle)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
// Deprecated: Use 'listWorkspaces' instead
a.Action("edit", func() {
a.Security("jwt")
a.Routing(
a.GET("/:codebaseID/edit"),
)
a.Description("Deprecated: Trigger edit of a given codebase.")
a.Params(func() {
a.Param("codebaseID", d.UUID, "Codebase Identifier")
})
a.Response(d.OK, func() {
a.Media(workspaceList)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
})
a.Action("listWorkspaces", func() {
a.Security("jwt")
a.Routing(
a.GET("/:codebaseID/workspaces"),
)
a.Description("Retrieve the list of workspaces that belong to a given codebase")
a.Params(func() {
a.Param("codebaseID", d.UUID, "Codebase Identifier")
})
a.Response(d.OK, func() {
a.Media(workspaceList)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
})
a.Action("delete", func() {
a.Security("jwt")
a.Routing(
a.DELETE("/:codebaseID"),
)
a.Description("Delete a codebase with the given ID.")
a.Params(func() {
a.Param("codebaseID", d.UUID, "ID of the codebase to delete")
})
a.Response(d.NoContent)
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.Forbidden, JSONAPIErrors)
})
a.Action("create", func() {
a.Security("jwt")
a.Routing(
a.POST("/:codebaseID/create"),
)
a.Description("Trigger create a worksapce for a codebase.")
a.Params(func() {
a.Param("codebaseID", d.UUID, "Codebase Identifier")
})
a.OptionalPayload(createWorkspace)
a.Response(d.OK, func() {
a.Media(workspaceOpen)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
})
a.Action("open", func() {
a.Security("jwt")
a.Routing(
a.POST("/:codebaseID/open/:workspaceID"),
)
a.Description("Trigger open of a given worksapce for a codebase.")
a.Params(func() {
a.Param("codebaseID", d.UUID, "Codebase Identifier")
a.Param("workspaceID", d.String, "Workspace Identifier")
})
a.Response(d.OK, func() {
a.Media(workspaceOpen)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
})
a.Action("cheState", func() {
a.Security("jwt")
a.Routing(
a.GET("/che/state"),
)
a.Description("Get che server state.")
a.Response(d.OK, func() {
a.Media(cheServerState)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
})
a.Action("cheStart", func() {
a.Security("jwt")
a.Routing(
a.PATCH("/che/start"),
)
a.Description("Start che server if not running.")
a.Response(d.OK, func() {
a.Media(cheServerState)
})
a.Response(d.Accepted, func() {
a.Media(cheServerState)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
})
})
// new version of "list" for migration
var _ = a.Resource("space_codebases", func() {
a.Parent("space")
a.Action("list", func() {
a.Routing(
a.GET("codebases"),
)
a.Description("List codebases.")
a.Params(func() {
a.Param("page[offset]", d.String, "Paging start position")
a.Param("page[limit]", d.Integer, "Paging size")
})
a.Response(d.OK, func() {
a.Media(codebaseList)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
})
a.Action("create", func() {
a.Security("jwt")
a.Routing(
a.POST("codebases"),
)
a.Description("Create codebase.")
a.Payload(codebaseSingle)
a.Response(d.Created, "/codebases/.*", func() {
a.Media(codebaseSingle)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.Forbidden, JSONAPIErrors)
a.Response(d.Conflict, JSONAPIErrors)
})
})