From 60d759872ac7f13a545d4f2ef6bfdcce8494426e Mon Sep 17 00:00:00 2001 From: fiftin Date: Wed, 27 Mar 2024 12:11:33 +0100 Subject: [PATCH] feat(runners): unregister endpoint --- api/router.go | 1 + api/runners/runners.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/api/router.go b/api/router.go index f472db18..28878916 100644 --- a/api/router.go +++ b/api/router.go @@ -91,6 +91,7 @@ func Route() *mux.Router { routersAPI.Use(StoreMiddleware, JSONMiddleware, runners.RunnerMiddleware) routersAPI.Path("/runners/{runner_id}").HandlerFunc(runners.GetRunner).Methods("GET", "HEAD") routersAPI.Path("/runners/{runner_id}").HandlerFunc(runners.UpdateRunner).Methods("PUT") + routersAPI.Path("/runners/{runner_id}").HandlerFunc(runners.UnregisterRunner).Methods("DELETE") publicWebHookRouter := r.PathPrefix(webPath + "api").Subrouter() publicWebHookRouter.Use(StoreMiddleware, JSONMiddleware) diff --git a/api/runners/runners.go b/api/runners/runners.go index 78c598bf..060408fc 100644 --- a/api/runners/runners.go +++ b/api/runners/runners.go @@ -196,3 +196,19 @@ func RegisterRunner(w http.ResponseWriter, r *http.Request) { helpers.WriteJSON(w, http.StatusOK, res) } + +func UnregisterRunner(w http.ResponseWriter, r *http.Request) { + + runner := context.Get(r, "runner").(db.Runner) + + err := helpers.Store(r).DeleteGlobalRunner(runner.ID) + + if err != nil { + helpers.WriteJSON(w, http.StatusInternalServerError, map[string]string{ + "error": "Unknown error", + }) + return + } + + w.WriteHeader(http.StatusNoContent) +}