Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 9756cf4

Browse files
committed
Fix #1130: Validate task workflow and schedule when creating task
request.
1 parent e316401 commit 9756cf4

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

core/task.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ type TaskCreationRequest struct {
161161
Version int `json:"version"`
162162
Deadline string `json:"deadline"`
163163
Workflow *wmap.WorkflowMap `json:"workflow"`
164-
Schedule Schedule `json:"schedule"`
164+
Schedule *Schedule `json:"schedule"`
165165
Start bool `json:"start"`
166166
MaxFailures int `json:"max-failures"`
167167
}
@@ -224,7 +224,11 @@ func CreateTaskFromContent(body io.ReadCloser,
224224
return nil, err
225225
}
226226

227-
sch, err := makeSchedule(tr.Schedule)
227+
if err := validateTaskRequest(tr); err != nil {
228+
return nil, err
229+
}
230+
231+
sch, err := makeSchedule(*tr.Schedule)
228232
if err != nil {
229233
return nil, err
230234
}
@@ -285,3 +289,14 @@ func UnmarshalBody(in interface{}, body io.ReadCloser) (int, error) {
285289
}
286290
return 0, nil
287291
}
292+
293+
func validateTaskRequest(tr *TaskCreationRequest) error {
294+
if tr.Schedule == nil || *tr.Schedule == (Schedule{}) {
295+
return fmt.Errorf("Task must include a schedule, and the schedule must not be empty")
296+
}
297+
298+
if tr.Workflow == nil || *tr.Workflow == (wmap.WorkflowMap{}) {
299+
return fmt.Errorf("Task must include a workflow, and the workflow must not be empty")
300+
}
301+
return nil
302+
}

mgmt/rest/client/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Schedule struct {
5050
// A ScheduledTask is returned if it succeeds, otherwise an error is returned.
5151
func (c *Client) CreateTask(s *Schedule, wf *wmap.WorkflowMap, name string, deadline string, startTask bool, maxFailures int) *CreateTaskResult {
5252
t := core.TaskCreationRequest{
53-
Schedule: core.Schedule{
53+
Schedule: &core.Schedule{
5454
Type: s.Type,
5555
Interval: s.Interval,
5656
},

mgmt/rest/rest_func_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func createTask(sample, name, interval string, noStart bool, port int) *rbody.AP
252252
uri := fmt.Sprintf("http://localhost:%d/v1/tasks", port)
253253

254254
t := core.TaskCreationRequest{
255-
Schedule: core.Schedule{Type: "simple", Interval: interval},
255+
Schedule: &core.Schedule{Type: "simple", Interval: interval},
256256
Workflow: wf,
257257
Name: name,
258258
Start: !noStart,

0 commit comments

Comments
 (0)