feat(task): explicitly handle orgs when finding run logs

Per #905, we will eventually support inferring organization from token.
In the meantime, allow the user to specify the org for their task.

No tests for this change; there is some test coverage in enterprise.
pull/10616/head
Mark Rushakoff 2018-10-01 09:53:06 -07:00 committed by Mark Rushakoff
parent f2283fe827
commit 94b5cd7d63
2 changed files with 30 additions and 8 deletions

View File

@ -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 {

View File

@ -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