-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.go
351 lines (290 loc) · 7.61 KB
/
models.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
package api
import (
"encoding/json"
"github.com/simon987/task_tracker/storage"
"golang.org/x/time/rate"
)
const (
MinPasswordLength = 8
MinUsernameLength = 3
MaxUsernameLength = 16
)
type JsonResponse struct {
Ok bool `json:"ok"`
Message string `json:"message,omitempty"`
RateLimitDelay float64 `json:"rate_limit_delay,omitempty"`
Content interface{} `json:"content,omitempty"`
}
type GitPayload struct {
Ref string `json:"ref"`
Before string `json:"before"`
After string `json:"after"`
Repository struct {
Id int64 `json:"id"`
Owner struct {
Id int64 `json:"id"`
Username string `json:"username"`
Login string `json:"login"`
FullName string `json:"full_name"`
Email string `json:"email"`
} `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Private bool `json:"private"`
Fork bool `json:"fork"`
Size int64 `json:"size"`
HtmlUrl string `json:"html_url"`
SshUrl string `json:"ssh_url"`
CloneUrl string `json:"clone_url"`
DefaultBranch string `json:"default_branch"`
} `json:"repository"`
}
func (g GitPayload) String() string {
jsonBytes, _ := json.Marshal(g)
return string(jsonBytes)
}
type ErrorResponse struct {
Message string `json:"message"`
StackTrace string `json:"stack_trace"`
}
type LoginRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
type LoginResponse struct {
Manager *storage.Manager `json:"manager"`
}
type RegisterRequest struct {
Username string `json:"username"`
Password string `json:"password"`
}
func (r *RegisterRequest) isValid() bool {
return MinUsernameLength <= len(r.Username) &&
len(r.Username) <= MaxUsernameLength &&
MinPasswordLength <= len(r.Password)
}
type GetAccountDetailsResponse struct {
LoggedIn bool `json:"logged_in"`
Manager *storage.Manager `json:"manager,omitempty"`
}
type GetManagerListResponse struct {
Managers *[]storage.Manager `json:"managers"`
}
type GetManagerListWithRoleOnResponse struct {
Managers *[]storage.ManagerRoleOn `json:"managers"`
}
type GetLogRequest struct {
Level storage.LogLevel `json:"level"`
Since int64 `json:"since"`
}
func (r GetLogRequest) isValid() bool {
if r.Since <= 0 {
return false
}
return true
}
type LogRequest struct {
Scope string `json:"scope"`
Message string `json:"Message"`
TimeStamp int64 `json:"timestamp"`
worker *storage.Worker
}
type GetLogResponse struct {
Logs *[]storage.LogEntry `json:"logs"`
}
type GetSnapshotsResponse struct {
Snapshots *[]storage.ProjectMonitoringSnapshot `json:"snapshots,omitempty"`
}
type CreateProjectRequest struct {
Name string `json:"name"`
CloneUrl string `json:"clone_url"`
GitRepo string `json:"git_repo"`
Version string `json:"version"`
Priority int64 `json:"priority"`
Motd string `json:"motd"`
Public bool `json:"public"`
Hidden bool `json:"hidden"`
Chain int64 `json:"chain"`
AssignRate rate.Limit `json:"assign_rate"`
SubmitRate rate.Limit `json:"submit_rate"`
}
func (req *CreateProjectRequest) isValid() bool {
if len(req.Name) <= 0 {
return false
}
if req.Priority < 0 {
return false
}
if req.Hidden && req.Public {
return false
}
return true
}
type UpdateProjectRequest struct {
Name string `json:"name"`
CloneUrl string `json:"clone_url"`
GitRepo string `json:"git_repo"`
Priority int64 `json:"priority"`
Motd string `json:"motd"`
Public bool `json:"public"`
Hidden bool `json:"hidden"`
Chain int64 `json:"chain"`
Paused bool `json:"paused"`
AssignRate rate.Limit `json:"assign_rate"`
SubmitRate rate.Limit `json:"submit_rate"`
Version string `json:"version"`
}
func (req *UpdateProjectRequest) isValid(pid int64) bool {
if len(req.Name) <= 0 {
return false
}
if req.Priority < 0 {
return false
}
if req.Hidden && req.Public {
return false
}
if req.Chain == pid {
return false
}
return true
}
type CreateProjectResponse struct {
Id int64 `json:"id,omitempty"`
}
type GetProjectResponse struct {
Project *storage.Project `json:"project,omitempty"`
}
type GetProjectListResponse struct {
Projects *[]storage.Project `json:"projects,omitempty"`
}
type GetAssigneeStatsForProjectResponse struct {
Assignees *[]storage.AssignedTasks `json:"assignees"`
}
type GetWorkerAccessListForProjectResponse struct {
Accesses *[]storage.WorkerAccess `json:"accesses,omitempty"`
}
type SubmitTaskRequest struct {
Project int64 `json:"project"`
MaxRetries int16 `json:"max_retries"`
Recipe string `json:"recipe"`
Priority int16 `json:"priority"`
MaxAssignTime int64 `json:"max_assign_time"`
Hash64 int64 `json:"hash_u64"`
UniqueString string `json:"unique_string"`
VerificationCount int16 `json:"verification_count"`
}
func (req *SubmitTaskRequest) IsValid() bool {
if req.MaxRetries < 0 {
return false
}
if len(req.Recipe) <= 0 {
return false
}
if req.Hash64 != 0 && len(req.UniqueString) != 0 {
return false
}
if req.Project == 0 {
return false
}
return true
}
type BulkSubmitTaskRequest struct {
Requests []SubmitTaskRequest `json:"requests"`
}
func (reqs BulkSubmitTaskRequest) IsValid() bool {
if reqs.Requests == nil {
return false
}
if len(reqs.Requests) == 0 {
return false
}
for _, req := range reqs.Requests {
if !req.IsValid() {
return false
}
}
return true
}
type ReleaseTaskRequest struct {
TaskId int64 `json:"task_id"`
Result storage.TaskResult `json:"result"`
Verification int64 `json:"verification"`
}
func (r *ReleaseTaskRequest) IsValid() bool {
return r.TaskId != 0
}
type ReleaseTaskResponse struct {
Updated bool `json:"updated"`
}
type CreateTaskResponse struct {
}
type GetTaskResponse struct {
Task *storage.Task `json:"task,omitempty"`
}
type UpdateWorkerRequest struct {
Alias string `json:"alias"`
}
type WorkerSetPausedRequest struct {
Worker int64 `json:"worker"`
Paused bool `json:"paused"`
}
type CreateWorkerRequest struct {
Alias string `json:"alias"`
}
func (req *CreateWorkerRequest) isValid() bool {
if req.Alias == "unassigned" {
//Reserved alias
return false
}
return true
}
type CreateWorkerResponse struct {
Worker *storage.Worker `json:"worker,omitempty"`
}
type GetWorkerResponse struct {
Worker *storage.Worker `json:"worker,omitempty"`
}
type GetAllWorkerStatsResponse struct {
Stats *[]storage.WorkerStats `json:"stats"`
}
type CreateWorkerAccessRequest struct {
Assign bool `json:"assign"`
Submit bool `json:"submit"`
Project int64 `json:"project"`
}
func (w *CreateWorkerAccessRequest) isValid() bool {
if !w.Assign && !w.Submit {
return false
}
return true
}
type SetManagerRoleOnProjectRequest struct {
Manager int64 `json:"manager"`
Role storage.ManagerRole `json:"role"`
}
type Info struct {
Name string `json:"name"`
Version string `json:"version"`
}
type SetSecretRequest struct {
Secret string `json:"secret"`
}
type GetSecretResponse struct {
Secret string `json:"secret"`
}
type SetWebhookSecretRequest struct {
WebhookSecret string `json:"webhook_secret"`
}
type GetWebhookSecretResponse struct {
WebhookSecret string `json:"webhook_secret"`
}
type ResetFailedTaskResponse struct {
AffectedTasks int64 `json:"affected_tasks"`
}
type HardResetResponse struct {
AffectedTasks int64 `json:"affected_tasks"`
}
type ReclaimAssignedTasksResponse struct {
AffectedTasks int64 `json:"affected_tasks"`
}