From e679a3448f9342a8bb7fbce17b303c45dd39a42d Mon Sep 17 00:00:00 2001 From: geauxvirtual Date: Tue, 16 Aug 2016 16:43:38 -0700 Subject: [PATCH 1/2] Fix #1129: Validate task manifest schedule exists and is not empty --- cmd/snapctl/task.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cmd/snapctl/task.go b/cmd/snapctl/task.go index 31c6f7483..605ae4e0f 100644 --- a/cmd/snapctl/task.go +++ b/cmd/snapctl/task.go @@ -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 { @@ -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 +} From ce765fc91d937e663b895aad48031021f7267609 Mon Sep 17 00:00:00 2001 From: geauxvirtual Date: Tue, 16 Aug 2016 16:50:18 -0700 Subject: [PATCH 2/2] Move version check into validateTask() --- cmd/snapctl/task.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cmd/snapctl/task.go b/cmd/snapctl/task.go index 605ae4e0f..9ccffc0a4 100644 --- a/cmd/snapctl/task.go +++ b/cmd/snapctl/task.go @@ -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) @@ -709,6 +705,9 @@ 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 }