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

Commit

Permalink
Merge pull request #1149 from geauxvirtual/tb/1129
Browse files Browse the repository at this point in the history
Fix #1129 - Add schedule validation check for task manifests in snapctl
  • Loading branch information
jcooklin authored Aug 26, 2016
2 parents 67417ef + ce765fc commit ee89c87
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions cmd/snapctl/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ func (t *task) mergeCliOptions(ctx *cli.Context) error {
}
t.MaxFailures = maxFailures
}
// shouldn't ever happen, but...
if t.Version != 1 {
return fmt.Errorf("Invalid version provided while creating task")
}
// set the schedule for the task from the CLI options (and return the results
// of that method call, indicating whether or not an error was encountered while
// setting up that schedule)
Expand Down Expand Up @@ -343,6 +339,11 @@ func createTaskUsingTaskManifest(ctx *cli.Context) error {
return fmt.Errorf("Unsupported file type %s\n", ext)
}

// Validate task manifest includes schedule, workflow, and version
if err := validateTask(t); err != nil {
return err
}

// merge any CLI options specified by the user (if any) into the current task;
// if an error is encountered, return it
if err := t.mergeCliOptions(ctx); err != nil {
Expand Down Expand Up @@ -699,3 +700,23 @@ func min(a, b int) int {
}
return b
}

func validateTask(t task) error {
if err := validateScheduleExists(t.Schedule); err != nil {
return err
}
if t.Version != 1 {
return fmt.Errorf("Error: Invalid version provided for task manifest")
}
return nil
}

func validateScheduleExists(schedule *client.Schedule) error {
if schedule == nil {
return fmt.Errorf("Error: Task manifest did not include a schedule")
}
if *schedule == (client.Schedule{}) {
return fmt.Errorf("Error: Task manifest included an empty schedule. Task manifests need to include a schedule.")
}
return nil
}

0 comments on commit ee89c87

Please # to comment.