fleet/server/service/http_auth.go
Zach Wasserman 72fc9dc524
Remove unused request-id in context (#3632)
This seems to be left over from the older authorization system in Fleet.
I couldn't find any other reference to the `request-id` in the code.
2022-01-13 14:12:56 -08:00

32 lines
853 B
Go

package service
import (
"context"
"net/http"
"github.com/fleetdm/fleet/v4/server/contexts/logging"
"github.com/fleetdm/fleet/v4/server/contexts/token"
"github.com/fleetdm/fleet/v4/server/contexts/viewer"
"github.com/fleetdm/fleet/v4/server/fleet"
kithttp "github.com/go-kit/kit/transport/http"
)
// setRequestsContexts updates the request with necessary context values for a request
func setRequestsContexts(svc fleet.Service) kithttp.RequestFunc {
return func(ctx context.Context, r *http.Request) context.Context {
bearer := token.FromHTTPRequest(r)
ctx = token.NewContext(ctx, bearer)
if bearer != "" {
v, err := authViewer(ctx, string(bearer), svc)
if err == nil {
ctx = viewer.NewContext(ctx, *v)
}
}
ctx = logging.NewContext(ctx, &logging.LoggingContext{})
ctx = logging.WithStartTime(ctx)
return ctx
}
}