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

Commit

Permalink
Fix #1129: Validate task manifest schedule exists and is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
geauxvirtual committed Aug 16, 2016
1 parent 4027d4a commit e679a34
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/snapctl/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,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 +704,20 @@ func min(a, b int) int {
}
return b
}

func validateTask(t task) error {
if err := validateScheduleExists(t.Schedule); err != nil {
return err
}
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 e679a34

Please sign in to comment.