diff --git a/http/task_service.go b/http/task_service.go index cd7235a607..1edf83ca29 100644 --- a/http/task_service.go +++ b/http/task_service.go @@ -7,6 +7,7 @@ import ( "strconv" "github.com/influxdata/platform" + pcontext "github.com/influxdata/platform/context" kerrors "github.com/influxdata/platform/kit/errors" "github.com/julienschmidt/httprouter" "go.uber.org/zap" @@ -15,8 +16,11 @@ import ( // TaskHandler represents an HTTP API handler for tasks. type TaskHandler struct { *httprouter.Router - logger *zap.Logger - TaskService platform.TaskService + logger *zap.Logger + + TaskService platform.TaskService + AuthorizationService platform.AuthorizationService + OrganizationService platform.OrganizationService } // NewTaskHandler returns a new instance of TaskHandler. @@ -315,7 +319,20 @@ func decodeGetLogsRequest(ctx context.Context, r *http.Request) (*getLogsRequest func (h *TaskHandler) handleGetRuns(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - req, err := decodeGetRunsRequest(ctx, r) + tok, err := GetToken(r) + if err != nil { + EncodeError(ctx, err, w) + return + } + + auth, err := h.AuthorizationService.FindAuthorizationByToken(ctx, tok) + if err != nil { + EncodeError(ctx, kerrors.Wrap(err, "invalid token", kerrors.InvalidData), w) + return + } + ctx = pcontext.SetAuthorization(ctx, auth) + + req, err := decodeGetRunsRequest(ctx, r, h.OrganizationService) if err != nil { EncodeError(ctx, err, w) return @@ -337,7 +354,7 @@ type getRunsRequest struct { filter platform.RunFilter } -func decodeGetRunsRequest(ctx context.Context, r *http.Request) (*getRunsRequest, error) { +func decodeGetRunsRequest(ctx context.Context, r *http.Request, orgs platform.OrganizationService) (*getRunsRequest, error) { params := httprouter.ParamsFromContext(ctx) id := params.ByName("tid") if id == "" { @@ -352,6 +369,15 @@ func decodeGetRunsRequest(ctx context.Context, r *http.Request) (*getRunsRequest qp := r.URL.Query() + if orgName := qp.Get("org"); orgName != "" { + o, err := orgs.FindOrganization(ctx, platform.OrganizationFilter{Name: &orgName}) + if err != nil { + return nil, err + } + + req.filter.Org = &o.ID + } + if id := qp.Get("after"); id != "" { req.filter.After = &platform.ID{} if err := req.filter.After.DecodeFromString(id); err != nil { diff --git a/task.go b/task.go index 917d8e2a03..803b10f716 100644 --- a/task.go +++ b/task.go @@ -75,8 +75,6 @@ type TaskFilter struct { // RunFilter represents a set of filters that restrict the returned results type RunFilter struct { - // TODO(lh): Org is temporary here. - // We will be removing it when the token in context contains org information. Org *ID Task *ID After *ID @@ -87,8 +85,6 @@ type RunFilter struct { // LogFilter represents a set of filters that restrict the returned results type LogFilter struct { - // TODO(lh): Org is temporary here. - // We will be removing it when the token in context contains org information. Org *ID Task *ID Run *ID