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

Commit

Permalink
Fix #1130: Validate task workflow and schedule when creating task
Browse files Browse the repository at this point in the history
request.
  • Loading branch information
geauxvirtual committed Sep 7, 2016
1 parent e316401 commit 9756cf4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ type TaskCreationRequest struct {
Version int `json:"version"`
Deadline string `json:"deadline"`
Workflow *wmap.WorkflowMap `json:"workflow"`
Schedule Schedule `json:"schedule"`
Schedule *Schedule `json:"schedule"`
Start bool `json:"start"`
MaxFailures int `json:"max-failures"`
}
Expand Down Expand Up @@ -224,7 +224,11 @@ func CreateTaskFromContent(body io.ReadCloser,
return nil, err
}

sch, err := makeSchedule(tr.Schedule)
if err := validateTaskRequest(tr); err != nil {
return nil, err
}

sch, err := makeSchedule(*tr.Schedule)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -285,3 +289,14 @@ func UnmarshalBody(in interface{}, body io.ReadCloser) (int, error) {
}
return 0, nil
}

func validateTaskRequest(tr *TaskCreationRequest) error {
if tr.Schedule == nil || *tr.Schedule == (Schedule{}) {
return fmt.Errorf("Task must include a schedule, and the schedule must not be empty")
}

if tr.Workflow == nil || *tr.Workflow == (wmap.WorkflowMap{}) {
return fmt.Errorf("Task must include a workflow, and the workflow must not be empty")
}
return nil
}
2 changes: 1 addition & 1 deletion mgmt/rest/client/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Schedule struct {
// A ScheduledTask is returned if it succeeds, otherwise an error is returned.
func (c *Client) CreateTask(s *Schedule, wf *wmap.WorkflowMap, name string, deadline string, startTask bool, maxFailures int) *CreateTaskResult {
t := core.TaskCreationRequest{
Schedule: core.Schedule{
Schedule: &core.Schedule{
Type: s.Type,
Interval: s.Interval,
},
Expand Down
2 changes: 1 addition & 1 deletion mgmt/rest/rest_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func createTask(sample, name, interval string, noStart bool, port int) *rbody.AP
uri := fmt.Sprintf("http://localhost:%d/v1/tasks", port)

t := core.TaskCreationRequest{
Schedule: core.Schedule{Type: "simple", Interval: interval},
Schedule: &core.Schedule{Type: "simple", Interval: interval},
Workflow: wf,
Name: name,
Start: !noStart,
Expand Down

0 comments on commit 9756cf4

Please sign in to comment.