mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
52a932bc6b
Add validation for user password creation/reset - at least 7 chars - 1 number - 1 symbol consolidated service errors to a single file.
36 lines
1013 B
Go
36 lines
1013 B
Go
package service
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
kithttp "github.com/go-kit/kit/transport/http"
|
|
"github.com/kolide/kolide-ose/server/contexts/token"
|
|
"github.com/kolide/kolide-ose/server/contexts/viewer"
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
// setRequestsContexts updates the request with necessary context values for a request
|
|
func setRequestsContexts(svc kolide.Service, jwtKey string) kithttp.RequestFunc {
|
|
return func(ctx context.Context, r *http.Request) context.Context {
|
|
bearer := token.FromHTTPRequest(r)
|
|
ctx = token.NewContext(ctx, bearer)
|
|
v, err := authViewer(ctx, jwtKey, bearer, svc)
|
|
if err == nil {
|
|
ctx = viewer.NewContext(ctx, *v)
|
|
}
|
|
|
|
// get the user-id for request
|
|
if strings.Contains(r.URL.Path, "users/") {
|
|
ctx = withUserIDFromRequest(r, ctx)
|
|
}
|
|
return ctx
|
|
}
|
|
}
|
|
|
|
func withUserIDFromRequest(r *http.Request, ctx context.Context) context.Context {
|
|
id, _ := idFromRequest(r, "id")
|
|
return context.WithValue(ctx, "request-id", id)
|
|
}
|