-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
fake_auth.go
42 lines (34 loc) · 1.12 KB
/
fake_auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package loki
import (
"context"
"net/http"
"github.com/weaveworks/common/middleware"
"github.com/weaveworks/common/user"
"google.golang.org/grpc"
)
// Fake auth middlewares just injects a fake userID, so the rest of the code
// can continue to be multitenant.
var fakeHTTPAuthMiddleware = middleware.Func(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := user.InjectOrgID(r.Context(), "fake")
next.ServeHTTP(w, r.WithContext(ctx))
})
})
var fakeGRPCAuthUniaryMiddleware = func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
ctx = user.InjectOrgID(ctx, "fake")
return handler(ctx, req)
}
var fakeGRPCAuthStreamMiddleware = func(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
ctx := user.InjectOrgID(ss.Context(), "fake")
return handler(srv, serverStream{
ctx: ctx,
ServerStream: ss,
})
}
type serverStream struct {
ctx context.Context
grpc.ServerStream
}
func (ss serverStream) Context() context.Context {
return ss.ctx
}