Add nginx exec

This commit is contained in:
Jamie Curnow
2022-07-15 14:26:12 +10:00
parent b8008606fd
commit 5b6dbaf43e
6 changed files with 101 additions and 14 deletions

View File

@ -9,6 +9,9 @@ import (
h "npm/internal/api/http"
"npm/internal/api/middleware"
"npm/internal/entity/host"
"npm/internal/jobqueue"
"npm/internal/logger"
"npm/internal/nginx"
"npm/internal/validator"
)
@ -80,6 +83,8 @@ func CreateHost() func(http.ResponseWriter, *http.Request) {
return
}
configureHost(newHost)
h.ResultResponseJSON(w, r, http.StatusOK, newHost)
}
}
@ -114,6 +119,8 @@ func UpdateHost() func(http.ResponseWriter, *http.Request) {
// nolint: errcheck,gosec
hostObject.Expand(getExpandFromContext(r))
configureHost(hostObject)
h.ResultResponseJSON(w, r, http.StatusOK, hostObject)
}
}
@ -138,3 +145,15 @@ func DeleteHost() func(http.ResponseWriter, *http.Request) {
}
}
}
func configureHost(h host.Model) {
err := jobqueue.AddJob(jobqueue.Job{
Name: "NginxConfigureHost",
Action: func() error {
return nginx.ConfigureHost(h)
},
})
if err != nil {
logger.Error("ConfigureHostError", err)
}
}