Skip to content

Commit

Permalink
aes key api
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanJey committed Nov 15, 2023
1 parent 068c2d4 commit aa3169f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
22 changes: 22 additions & 0 deletions internal/api/aesKey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package api

import (
aesKey "github.com/OpenIMSDK/protocol/aeskey"

Check failure on line 4 in internal/api/aesKey.go

View workflow job for this annotation

GitHub Actions / Build OpenIM Docker Image

github.com/OpenIMSDK/[email protected] (replaced by ../protocol): reading ../protocol/go.mod: open /home/runner/work/open-im-server/protocol/go.mod: no such file or directory
"github.com/OpenIMSDK/tools/a2r"
"github.com/gin-gonic/gin"
"github.com/openimsdk/open-im-server/v3/pkg/rpcclient"
)

type AesKeyApi rpcclient.AesKey

func NewAesKeyApi(client rpcclient.AesKey) AesKeyApi {
return AesKeyApi(client)
}

func (a *AesKeyApi) GetKey(c *gin.Context) {
a2r.Call(aesKey.AesKeyClient.AcquireAesKey, a.Client, c)
}

func (a *AesKeyApi) GetKeys(c *gin.Context) {
a2r.Call(aesKey.AesKeyClient.AcquireAesKeys, a.Client, c)
}
7 changes: 7 additions & 0 deletions internal/api/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
conversationRpc := rpcclient.NewConversation(discov)
authRpc := rpcclient.NewAuth(discov)
thirdRpc := rpcclient.NewThird(discov)
aesKeyRpc := rpcclient.NewAesKey(discov)

u := NewUserApi(*userRpc)
m := NewMessageApi(messageRpc, userRpc)
k := NewAesKeyApi(*aesKeyRpc)
ParseToken := GinParseToken(rdb)
userRouterGroup := r.Group("/user")
{
Expand Down Expand Up @@ -205,6 +207,11 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
statisticsGroup.POST("/group/create", g.GroupCreateCount)
statisticsGroup.POST("/group/active", m.GetActiveGroup)
}
aesKeyGroup := r.Group("/aes_key", ParseToken)
{
aesKeyGroup.POST("/get_key", k.GetKey)
aesKeyGroup.POST("/get_keys", k.GetKeys)
}
return r
}

Expand Down
38 changes: 38 additions & 0 deletions pkg/rpcclient/aes_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package rpcclient

import (
"context"
aesKey "github.com/OpenIMSDK/protocol/aeskey"
"github.com/OpenIMSDK/tools/discoveryregistry"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"google.golang.org/grpc"
)

type AesKey struct {
conn grpc.ClientConnInterface
Client aesKey.AesKeyClient
Discov discoveryregistry.SvcDiscoveryRegistry
}

func NewAesKey(discov discoveryregistry.SvcDiscoveryRegistry) *AesKey {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAesKeyName)
if err != nil {
panic(err)
}
client := aesKey.NewAesKeyClient(conn)
return &AesKey{Discov: discov, Client: client, conn: conn}
}

type AesKeyRpcClient AesKey

func NewAesKeyRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) AesKeyRpcClient {
return AesKeyRpcClient(*NewAesKey(discov))
}

func (a *AesKeyRpcClient) AcquireAesKey(ctx context.Context, conversationType int32, userID, friendUserID, groupID string) (*aesKey.AcquireAesKeyResp, error) {
return a.Client.AcquireAesKey(ctx, &aesKey.AcquireAesKeyReq{ConversationType: conversationType, OwnerUserID: userID, FriendUserID: friendUserID, GroupID: groupID})
}

func (a *AesKeyRpcClient) AcquireAesKeys(ctx context.Context, userID string) (*aesKey.AcquireAesKeysResp, error) {
return a.Client.AcquireAesKeys(ctx, &aesKey.AcquireAesKeysReq{UserID: userID})
}

0 comments on commit aa3169f

Please sign in to comment.