From 289cd6d9370efe11140c9c1742fce59b669f300f Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Sun, 24 Nov 2024 22:06:05 +0500 Subject: [PATCH] feat(terraform): auto approve and plan flags --- db/Task.go | 22 +++++++++++++++++++--- services/tasks/LocalJob.go | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/db/Task.go b/db/Task.go index 4a33b4d6..ca2fccb3 100644 --- a/db/Task.go +++ b/db/Task.go @@ -1,6 +1,7 @@ package db import ( + "encoding/json" "fmt" "github.com/go-gorp/gorp/v3" "time" @@ -9,7 +10,7 @@ import ( "github.com/semaphoreui/semaphore/util" ) -type ShellTaskParams struct { +type DefaultTaskParams struct { } type TerraformTaskParams struct { @@ -70,7 +71,11 @@ type Task struct { } func (task *Task) GetParams(target interface{}) error { - return nil + content, err := json.Marshal(task.TaskParams) + if err != nil { + return err + } + return json.Unmarshal(content, target) } func (task *Task) PreInsert(gorp.SqlExecutor) error { @@ -124,7 +129,18 @@ func (task *Task) GetUrl() *string { } func (task *Task) ValidateNewTask(template Template) error { - return nil + + var params interface{} + switch template.App { + case AppAnsible: + params = &AnsibleTaskParams{} + case AppTerraform, AppTofu: + params = &TerraformTaskParams{} + default: + params = &DefaultTaskParams{} + } + + return task.GetParams(params) } func (task *TaskWithTpl) Fill(d Store) error { diff --git a/services/tasks/LocalJob.go b/services/tasks/LocalJob.go index e0704c0a..71cbb6d5 100644 --- a/services/tasks/LocalJob.go +++ b/services/tasks/LocalJob.go @@ -437,7 +437,7 @@ func (t *LocalJob) Run(username string, incomingVersion *string) (err error) { params = db.TerraformTaskParams{} default: args, err = t.getShellArgs(username, incomingVersion) - params = db.ShellTaskParams{} + params = db.DefaultTaskParams{} } if err != nil {