fix(be): null pointer in new task params field

This commit is contained in:
Denis Gukov 2024-11-24 23:28:00 +05:00
parent 289cd6d937
commit 89c9042d1e
4 changed files with 28 additions and 10 deletions

View File

@ -67,19 +67,35 @@ type Task struct {
InventoryID *int `db:"inventory_id" json:"inventory_id"`
TaskParams MapStringAnyField `db:"params" json:"params"`
Params MapStringAnyField `db:"params" json:"params"`
}
func (task *Task) GetParams(target interface{}) error {
content, err := json.Marshal(task.TaskParams)
func (task *Task) GetParams(target interface{}) (err error) {
content, err := json.Marshal(task.Params)
if err != nil {
return err
return
}
return json.Unmarshal(content, target)
err = json.Unmarshal(content, target)
return
}
func (task *Task) PreInsert(gorp.SqlExecutor) error {
task.Created = task.Created.UTC()
// Init params from old fields for backward compatibility
if task.Debug {
task.Params["debug"] = true
}
if task.DryRun {
task.Params["dry_run"] = true
}
if task.Diff {
task.Params["diff"] = true
}
return nil
}

View File

@ -102,6 +102,8 @@ type Template struct {
App TemplateApp `db:"app" json:"app"`
Tasks int `db:"tasks" json:"tasks" backup:"-"`
TaskParams MapStringAnyField `db:"task_params" json:"task_params"`
}
func (tpl *Template) Validate() error {

View File

@ -431,13 +431,13 @@ func (t *LocalJob) Run(username string, incomingVersion *string) (err error) {
switch t.Template.App {
case db.AppAnsible:
args, inputs, err = t.getPlaybookArgs(username, incomingVersion)
params = db.AnsibleTaskParams{}
params = &db.AnsibleTaskParams{}
case db.AppTerraform, db.AppTofu:
args, err = t.getTerraformArgs(username, incomingVersion)
params = db.TerraformTaskParams{}
params = &db.TerraformTaskParams{}
default:
args, err = t.getShellArgs(username, incomingVersion)
params = db.DefaultTaskParams{}
params = &db.DefaultTaskParams{}
}
if err != nil {

View File

@ -262,11 +262,11 @@ export default {
responseType: 'json',
})).data;
this.user = (await axios({
this.user = this.item.user_id ? (await axios({
method: 'get',
url: `/api/users/${this.item.user_id}`,
responseType: 'json',
})).data;
})).data : null;
},
},
};