refactor(token): remove context token
parent
022bdc86d6
commit
c54df3d052
|
@ -29,33 +29,3 @@ func GetAuthorizer(ctx context.Context) (platform.Authorizer, error) {
|
|||
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// SetToken sets an token on context.
|
||||
func SetToken(ctx context.Context, t string) context.Context {
|
||||
return context.WithValue(ctx, tokenCtxKey, t)
|
||||
}
|
||||
|
||||
// GeToken retrieves an token from context.
|
||||
func GetToken(ctx context.Context) (string, error) {
|
||||
t, ok := ctx.Value(tokenCtxKey).(string)
|
||||
if !ok {
|
||||
return "", errors.InternalErrorf("token not found on context")
|
||||
}
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// SetAuthorization sets an authorization on context.
|
||||
func SetAuthorization(ctx context.Context, a *platform.Authorization) context.Context {
|
||||
return context.WithValue(ctx, authorizationCtxKey, a)
|
||||
}
|
||||
|
||||
// GetAuthorization retrieves an authorization from context.
|
||||
func GetAuthorization(ctx context.Context) (*platform.Authorization, error) {
|
||||
a, ok := ctx.Value(authorizationCtxKey).(*platform.Authorization)
|
||||
if !ok {
|
||||
return nil, errors.InternalErrorf("authorization not found on context")
|
||||
}
|
||||
|
||||
return a, nil
|
||||
}
|
||||
|
|
|
@ -273,11 +273,7 @@ func (s *FluxService) Query(ctx context.Context, w io.Writer, r *query.ProxyRequ
|
|||
return 0, err
|
||||
}
|
||||
|
||||
tok, err := pcontext.GetToken(ctx)
|
||||
if err != nil {
|
||||
tok = s.Token
|
||||
}
|
||||
SetToken(tok, hreq)
|
||||
SetToken(s.Token, hreq)
|
||||
|
||||
hreq.Header.Set("Content-Type", "application/json")
|
||||
hreq.Header.Set("Accept", "text/csv")
|
||||
|
@ -333,11 +329,7 @@ func (s *FluxQueryService) Query(ctx context.Context, r *query.Request) (flux.Re
|
|||
return nil, err
|
||||
}
|
||||
|
||||
tok, err := pcontext.GetToken(ctx)
|
||||
if err != nil {
|
||||
tok = s.Token
|
||||
}
|
||||
SetToken(tok, hreq)
|
||||
SetToken(s.Token, hreq)
|
||||
|
||||
hreq.Header.Set("Content-Type", "application/json")
|
||||
hreq.Header.Set("Accept", "text/csv")
|
||||
|
|
|
@ -308,7 +308,7 @@ func (h *TaskHandler) handleGetLogs(w http.ResponseWriter, r *http.Request) {
|
|||
EncodeError(ctx, kerrors.Wrap(err, "invalid token", kerrors.InvalidData), w)
|
||||
return
|
||||
}
|
||||
ctx = pcontext.SetAuthorization(ctx, auth)
|
||||
ctx = pcontext.SetAuthorizer(ctx, auth)
|
||||
|
||||
req, err := decodeGetLogsRequest(ctx, r, h.OrganizationService)
|
||||
if err != nil {
|
||||
|
@ -382,7 +382,7 @@ func (h *TaskHandler) handleGetRuns(w http.ResponseWriter, r *http.Request) {
|
|||
EncodeError(ctx, kerrors.Wrap(err, "invalid token", kerrors.InvalidData), w)
|
||||
return
|
||||
}
|
||||
ctx = pcontext.SetAuthorization(ctx, auth)
|
||||
ctx = pcontext.SetAuthorizer(ctx, auth)
|
||||
|
||||
req, err := decodeGetRunsRequest(ctx, r, h.OrganizationService)
|
||||
if err != nil {
|
||||
|
@ -479,7 +479,7 @@ func (h *TaskHandler) handleGetRun(w http.ResponseWriter, r *http.Request) {
|
|||
EncodeError(ctx, kerrors.Wrap(err, "invalid token", kerrors.InvalidData), w)
|
||||
return
|
||||
}
|
||||
ctx = pcontext.SetAuthorization(ctx, auth)
|
||||
ctx = pcontext.SetAuthorizer(ctx, auth)
|
||||
|
||||
req, err := decodeGetRunRequest(ctx, r, h.OrganizationService)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue