fix(runner): check token

This commit is contained in:
Denis Gukov 2024-01-07 21:32:30 +05:00
parent 1ae8eb1376
commit 5596943433

View File

@ -13,6 +13,8 @@ import (
func RunnerMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("X-API-Token")
runnerID, err := helpers.GetIntParam("runner_id", w, r)
if err != nil {
@ -26,6 +28,13 @@ func RunnerMiddleware(next http.Handler) http.Handler {
runner, err := store.GetGlobalRunner(runnerID)
if runner.Token != token {
helpers.WriteJSON(w, http.StatusUnauthorized, map[string]string{
"error": "Invalid token",
})
return
}
if err != nil {
helpers.WriteJSON(w, http.StatusNotFound, map[string]string{
"error": "Runner not found",