Skip to content

Commit

Permalink
refactor: update adminToken
Browse files Browse the repository at this point in the history
  • Loading branch information
mo3et committed Sep 29, 2024
1 parent 4cc431e commit 161e356
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/livekit/protocol v1.10.1
github.com/mitchellh/mapstructure v1.5.0
github.com/openimsdk/gomake v0.0.14-alpha.5
github.com/openimsdk/protocol v0.0.72-alpha.38
github.com/openimsdk/protocol v0.0.72
github.com/openimsdk/tools v0.0.50-alpha.15
github.com/redis/go-redis/v9 v9.5.1
github.com/spf13/cobra v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OS
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/openimsdk/gomake v0.0.14-alpha.5 h1:VY9c5x515lTfmdhhPjMvR3BBRrRquAUCFsz7t7vbv7Y=
github.com/openimsdk/gomake v0.0.14-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
github.com/openimsdk/protocol v0.0.72-alpha.38 h1:v0GLgS9cNm627NSG3B2k2VF2AMoo90DSKixxiBMKPS4=
github.com/openimsdk/protocol v0.0.72-alpha.38/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
github.com/openimsdk/protocol v0.0.72 h1:K+vslwaR7lDXyBzb07UuEQITaqsgighz7NyXVIWsu6A=
github.com/openimsdk/protocol v0.0.72/go.mod h1:OZQA9FR55lseYoN2Ql1XAHYKHJGu7OMNkUbuekrKCM8=
github.com/openimsdk/tools v0.0.50-alpha.15 h1:HV9aKZ4vvCZCGG4wFDsgUONkkdJeCcrFNn3BT52nUVQ=
github.com/openimsdk/tools v0.0.50-alpha.15/go.mod h1:h1cYmfyaVtgFbKmb1Cfsl8XwUOMTt8ubVUQrdGtsUh4=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
Expand Down
12 changes: 6 additions & 6 deletions internal/api/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (o *Api) AdminLogin(c *gin.Context) {
return
}
imAdminUserID := o.GetDefaultIMAdminUserID()
imToken, err := o.imApiCaller.AdminToken(c, imAdminUserID)
imToken, err := o.imApiCaller.GetAdminToken(c, imAdminUserID)
if err != nil {
apiresp.GinError(c, err)
return
Expand Down Expand Up @@ -127,7 +127,7 @@ func (o *Api) AdminUpdateInfo(c *gin.Context) {
}

imAdminUserID := o.GetDefaultIMAdminUserID()
imToken, err := o.imApiCaller.AdminToken(c, imAdminUserID)
imToken, err := o.imApiCaller.GetAdminToken(c, imAdminUserID)
if err != nil {
log.ZError(c, "AdminUpdateInfo ImAdminTokenWithDefaultAdmin", err, "imAdminUserID", imAdminUserID)
return
Expand Down Expand Up @@ -207,7 +207,7 @@ func (o *Api) AddDefaultGroup(c *gin.Context) {
apiresp.GinError(c, err)
return
}
imToken, err := o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID())
imToken, err := o.imApiCaller.GetAdminToken(c, o.GetDefaultIMAdminUserID())
if err != nil {
apiresp.GinError(c, err)
return
Expand Down Expand Up @@ -255,7 +255,7 @@ func (o *Api) SearchDefaultGroup(c *gin.Context) {
Groups: make([]*sdkws.GroupInfo, 0, len(searchResp.GroupIDs)),
}
if len(searchResp.GroupIDs) > 0 {
imToken, err := o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID())
imToken, err := o.imApiCaller.GetAdminToken(c, o.GetDefaultIMAdminUserID())
if err != nil {
apiresp.GinError(c, err)
return
Expand Down Expand Up @@ -337,7 +337,7 @@ func (o *Api) BlockUser(c *gin.Context) {
apiresp.GinError(c, err)
return
}
imToken, err := o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID())
imToken, err := o.imApiCaller.GetAdminToken(c, o.GetDefaultIMAdminUserID())
if err != nil {
apiresp.GinError(c, err)
return
Expand Down Expand Up @@ -396,7 +396,7 @@ func (o *Api) NewUserCount(c *gin.Context) {
apiresp.GinError(c, err)
return
}
imToken, err := o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID())
imToken, err := o.imApiCaller.GetAdminToken(c, o.GetDefaultIMAdminUserID())
if err != nil {
apiresp.GinError(c, err)
return
Expand Down
2 changes: 1 addition & 1 deletion internal/api/chat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (o *Api) UpdateUserInfo(c *gin.Context) {
if opUserType == constant.NormalUser {
imToken, err = o.imApiCaller.ImAdminTokenWithDefaultAdmin(c)
} else if opUserType == constant.AdminUser {
imToken, err = o.imApiCaller.AdminToken(c, o.GetDefaultIMAdminUserID())
imToken, err = o.imApiCaller.GetAdminToken(c, o.GetDefaultIMAdminUserID())
} else {
apiresp.GinError(c, errs.ErrArgs.WrapMsg("opUserType unknown"))
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/imapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// im caller.
var (
importFriend = NewApiCaller[relation.ImportFriendReq, relation.ImportFriendResp]("/friend/import_friend")
userToken = NewApiCaller[auth.UserTokenReq, auth.UserTokenResp]("/auth/user_token")
getAdminToken = NewApiCaller[auth.GetAdminTokenReq, auth.GetAdminTokenResp]("/auth/get_admin_token")
getuserToken = NewApiCaller[auth.GetUserTokenReq, auth.GetUserTokenResp]("/auth/get_user_token")
inviteToGroup = NewApiCaller[group.InviteUserToGroupReq, group.InviteUserToGroupResp]("/group/invite_user_to_group")
updateUserInfo = NewApiCaller[user.UpdateUserInfoReq, user.UpdateUserInfoResp]("/user/update_user_info")
Expand Down
8 changes: 4 additions & 4 deletions pkg/common/imapi/caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type CallerInterface interface {
ImAdminTokenWithDefaultAdmin(ctx context.Context) (string, error)
ImportFriend(ctx context.Context, ownerUserID string, friendUserID []string) error
GetUserToken(ctx context.Context, userID string, platform int32) (string, error)
AdminToken(ctx context.Context, userID string) (string, error)
GetAdminToken(ctx context.Context, userID string) (string, error)
InviteToGroup(ctx context.Context, userID string, groupIDs []string) error
UpdateUserInfo(ctx context.Context, userID string, nickName string, faceURL string) error
ForceOffLine(ctx context.Context, userID string) error
Expand Down Expand Up @@ -79,7 +79,7 @@ func (c *Caller) ImAdminTokenWithDefaultAdmin(ctx context.Context) (string, erro
defer c.lock.Unlock()
if c.token == "" || c.timeout.Before(time.Now()) {
userID := c.defaultIMUserID
token, err := c.AdminToken(ctx, userID)
token, err := c.GetAdminToken(ctx, userID)
if err != nil {
log.ZError(ctx, "get im admin token", err, "userID", userID)
return "", err
Expand All @@ -91,8 +91,8 @@ func (c *Caller) ImAdminTokenWithDefaultAdmin(ctx context.Context) (string, erro
return c.token, nil
}

func (c *Caller) AdminToken(ctx context.Context, userID string) (string, error) {
resp, err := userToken.Call(ctx, c.imApi, &auth.UserTokenReq{
func (c *Caller) GetAdminToken(ctx context.Context, userID string) (string, error) {
resp, err := getAdminToken.Call(ctx, c.imApi, &auth.GetAdminTokenReq{
Secret: c.imSecret,
UserID: userID,
})
Expand Down
2 changes: 1 addition & 1 deletion tools/check-component/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func CheckRedis(ctx context.Context, config *config.Redis) error {

func CheckOpenIM(ctx context.Context, apiURL, secret, adminUserID string) error {
imAPI := imapi.New(apiURL, secret, adminUserID)
_, err := imAPI.AdminToken(mcontext.SetOperationID(ctx, "CheckOpenIM"+idutil.OperationIDGenerator()), adminUserID)
_, err := imAPI.GetAdminToken(mcontext.SetOperationID(ctx, "CheckOpenIM"+idutil.OperationIDGenerator()), adminUserID)
return err
}

Expand Down

0 comments on commit 161e356

Please sign in to comment.