feat: analysis user auth and ws
This commit is contained in:
@@ -33,6 +33,7 @@ const (
|
||||
CtxGroupId ctxKey = "X-Group-Id"
|
||||
CtxGroupName ctxKey = "X-Group-Name"
|
||||
CtxUserType ctxKey = "X-User-Type"
|
||||
CtxBizId ctxKey = "X-Biz-Id"
|
||||
CtxRawBody ctxKey = "X-Raw-Body"
|
||||
)
|
||||
|
||||
@@ -59,6 +60,7 @@ type UserInfo struct {
|
||||
StoreName string
|
||||
GroupId string
|
||||
GroupName string
|
||||
BizId string
|
||||
RawBody string
|
||||
Valid bool
|
||||
}
|
||||
@@ -79,6 +81,7 @@ func GetUserInfo(ctx context.Context) UserInfo {
|
||||
storeName, _ := ctx.Value(CtxStoreName).(string)
|
||||
groupId, _ := ctx.Value(CtxGroupId).(string)
|
||||
groupName, _ := ctx.Value(CtxGroupName).(string)
|
||||
bizId, _ := ctx.Value(CtxBizId).(string)
|
||||
rawBody, _ := ctx.Value(CtxRawBody).(string)
|
||||
|
||||
info := UserInfo{
|
||||
@@ -97,6 +100,7 @@ func GetUserInfo(ctx context.Context) UserInfo {
|
||||
StoreName: storeName,
|
||||
GroupId: groupId,
|
||||
GroupName: groupName,
|
||||
BizId: bizId,
|
||||
RawBody: rawBody,
|
||||
}
|
||||
if rawUID == "" {
|
||||
@@ -151,6 +155,7 @@ func UserReadMiddleware(next http.HandlerFunc) http.HandlerFunc {
|
||||
newCtx = context.WithValue(newCtx, CtxStoreName, r.Header.Get("X-Store-Name"))
|
||||
newCtx = context.WithValue(newCtx, CtxGroupId, r.Header.Get("X-Group-Id"))
|
||||
newCtx = context.WithValue(newCtx, CtxGroupName, r.Header.Get("X-Group-Name"))
|
||||
newCtx = context.WithValue(newCtx, CtxBizId, r.Header.Get("X-Biz-Id"))
|
||||
next(w, r.WithContext(newCtx))
|
||||
}
|
||||
}
|
||||
@@ -201,6 +206,7 @@ func UserClientInterceptor(ctx context.Context, method string, req, reply any, c
|
||||
if user.GroupName != utils.StringEmpty {
|
||||
md.Set("x-group-name", url.QueryEscape(user.GroupName))
|
||||
}
|
||||
setMDIfNotEmpty(md, "x-biz-id", user.BizId)
|
||||
|
||||
ctx = metadata.NewOutgoingContext(ctx, md)
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
@@ -238,6 +244,7 @@ func UserStreamInterceptor(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.
|
||||
if user.GroupName != utils.StringEmpty {
|
||||
md.Set("x-group-name", url.QueryEscape(user.GroupName))
|
||||
}
|
||||
setMDIfNotEmpty(md, "x-biz-id", user.BizId)
|
||||
|
||||
newCtx := metadata.NewOutgoingContext(ctx, md)
|
||||
return streamer(newCtx, desc, cc, method, opts...)
|
||||
|
||||
Reference in New Issue
Block a user