diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2025-01-22 18:41:20 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-01-27 08:57:27 +0000 |
| commit | 83bb17d041cb6e2e513510609ebf5ba8906feb6a (patch) | |
| tree | 0c1aa920cf9bb56619b0bce3abc88b59fad5f121 | |
| parent | e6c1954040ddd50faa6a7a04c7055a2cd4ffdb46 (diff) | |
syz-cluster: use Request.Context()
| -rw-r--r-- | syz-cluster/controller/api.go | 18 | ||||
| -rw-r--r-- | syz-cluster/dashboard/handler.go | 11 |
2 files changed, 11 insertions, 18 deletions
diff --git a/syz-cluster/controller/api.go b/syz-cluster/controller/api.go index 676ee4f35..e5cb18a27 100644 --- a/syz-cluster/controller/api.go +++ b/syz-cluster/controller/api.go @@ -5,7 +5,6 @@ package main import ( - "context" "encoding/json" "errors" "fmt" @@ -45,8 +44,7 @@ func (c ControllerAPI) Mux() *http.ServeMux { } func (c ControllerAPI) getSessionSeries(w http.ResponseWriter, r *http.Request) { - ctx := context.Background() - resp, err := c.seriesService.GetSessionSeries(ctx, r.PathValue("session_id")) + resp, err := c.seriesService.GetSessionSeries(r.Context(), r.PathValue("session_id")) if err == ErrSeriesNotFound || err == ErrSessionNotFound { http.Error(w, fmt.Sprint(err), http.StatusNotFound) return @@ -62,8 +60,7 @@ func (c ControllerAPI) skipSession(w http.ResponseWriter, r *http.Request) { if req == nil { return } - ctx := context.Background() - err := c.seriesService.SkipSession(ctx, r.PathValue("session_id"), req) + err := c.seriesService.SkipSession(r.Context(), r.PathValue("session_id"), req) if errors.Is(err, ErrSessionNotFound) { http.Error(w, fmt.Sprint(err), http.StatusNotFound) return @@ -75,8 +72,7 @@ func (c ControllerAPI) skipSession(w http.ResponseWriter, r *http.Request) { } func (c ControllerAPI) getSeries(w http.ResponseWriter, r *http.Request) { - ctx := context.Background() - resp, err := c.seriesService.GetSeries(ctx, r.PathValue("series_id")) + resp, err := c.seriesService.GetSeries(r.Context(), r.PathValue("series_id")) if err == ErrSeriesNotFound { http.Error(w, fmt.Sprint(err), http.StatusNotFound) return @@ -92,7 +88,7 @@ func (c ControllerAPI) uploadBuild(w http.ResponseWriter, r *http.Request) { if req == nil { return } - resp, err := c.buildService.Upload(context.Background(), req) + resp, err := c.buildService.Upload(r.Context(), req) if err != nil { // TODO: sometimes it's not StatusInternalServerError. http.Error(w, fmt.Sprint(err), http.StatusInternalServerError) @@ -107,7 +103,7 @@ func (c ControllerAPI) uploadTest(w http.ResponseWriter, r *http.Request) { return } // TODO: add parameters validation. - err := c.testService.Save(context.Background(), req) + err := c.testService.Save(r.Context(), req) if err != nil { http.Error(w, fmt.Sprint(err), http.StatusInternalServerError) return @@ -121,7 +117,7 @@ func (c ControllerAPI) uploadFinding(w http.ResponseWriter, r *http.Request) { return } // TODO: add parameters validation. - err := c.findingService.Save(context.Background(), req) + err := c.findingService.Save(r.Context(), req) if err != nil { http.Error(w, fmt.Sprint(err), http.StatusInternalServerError) return @@ -134,7 +130,7 @@ func (c ControllerAPI) getLastBuild(w http.ResponseWriter, r *http.Request) { if req == nil { return } - resp, err := c.buildService.LastBuild(context.Background(), req) + resp, err := c.buildService.LastBuild(r.Context(), req) if err != nil { http.Error(w, fmt.Sprint(err), http.StatusInternalServerError) return diff --git a/syz-cluster/dashboard/handler.go b/syz-cluster/dashboard/handler.go index 5e562ee11..e85a587c8 100644 --- a/syz-cluster/dashboard/handler.go +++ b/syz-cluster/dashboard/handler.go @@ -4,7 +4,6 @@ package main import ( - "context" "embed" "fmt" "html/template" @@ -56,7 +55,7 @@ func (h *dashboardHandler) seriesList(w http.ResponseWriter, r *http.Request) { } var data MainPageData var err error - data.List, err = h.seriesRepo.ListLatest(context.Background(), time.Time{}, 0) + data.List, err = h.seriesRepo.ListLatest(r.Context(), time.Time{}, 0) if err != nil { http.Error(w, fmt.Sprintf("failed to query the list: %v", err), http.StatusInternalServerError) return @@ -85,7 +84,7 @@ func (h *dashboardHandler) seriesInfo(w http.ResponseWriter, r *http.Request) { } var data SeriesData var err error - ctx := context.Background() + ctx := r.Context() data.Series, err = h.seriesRepo.GetByID(ctx, r.PathValue("id")) if err != nil { http.Error(w, fmt.Sprint(err), http.StatusInternalServerError) @@ -142,8 +141,7 @@ func groupFindings(findings []*db.Finding) map[string][]*db.Finding { // nolint:dupl func (h *dashboardHandler) sessionLog(w http.ResponseWriter, r *http.Request) { - ctx := context.Background() - session, err := h.sessionRepo.GetByID(ctx, r.PathValue("id")) + session, err := h.sessionRepo.GetByID(r.Context(), r.PathValue("id")) if err != nil { http.Error(w, fmt.Sprint(err), http.StatusInternalServerError) return @@ -157,8 +155,7 @@ func (h *dashboardHandler) sessionLog(w http.ResponseWriter, r *http.Request) { // nolint:dupl func (h *dashboardHandler) patchContent(w http.ResponseWriter, r *http.Request) { - ctx := context.Background() - patch, err := h.seriesRepo.PatchByID(ctx, r.PathValue("id")) + patch, err := h.seriesRepo.PatchByID(r.Context(), r.PathValue("id")) if err != nil { http.Error(w, fmt.Sprint(err), http.StatusInternalServerError) return |
