Rearranged script hook UI

This commit is contained in:
Magnus Åhall 2025-08-08 15:36:32 +02:00
parent 5145830f65
commit 2cab8c3ddb
5 changed files with 177 additions and 50 deletions

View file

@ -162,7 +162,7 @@ func SearchScripts(search string) (scripts []Script, err error) { // {{{
return
} // }}}
func HookScript(nodeID, scriptID int) (err error) { // {{{
_, err = db.Exec(`INSERT INTO hook(node_id, script_id, ssh, env) VALUES($1, $2, '<host>')`, nodeID, scriptID)
_, err = db.Exec(`INSERT INTO hook(node_id, script_id, ssh) VALUES($1, $2, '<host>')`, nodeID, scriptID)
return
} // }}}
@ -197,7 +197,8 @@ func GetHook(hookID int) (hook Hook, err error) { // {{{
return
} // }}}
func UpdateHook(hook Hook) (err error) { // {{{
_, err = db.Exec(`UPDATE hook SET ssh=$2 WHERE id=$1`, hook.ID, strings.TrimSpace(hook.SSH))
j, _ := json.Marshal(hook.Env)
_, err = db.Exec(`UPDATE hook SET ssh=$2, env=$3 WHERE id=$1`, hook.ID, strings.TrimSpace(hook.SSH), j)
if err != nil {
err = werr.Wrap(err)
return