mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-07 04:57:03 +08:00
aes key rpc
This commit is contained in:
parent
edf40893b9
commit
068c2d4729
19
cmd/openim-rpc/openim-rpc-aesKey/main.go
Normal file
19
cmd/openim-rpc/openim-rpc-aesKey/main.go
Normal file
@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/open-im-server/v3/internal/rpc/aes_key"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rpcCmd := cmd.NewRpcCmd(cmd.RpcAesKeyServer)
|
||||
rpcCmd.AddPortFlag()
|
||||
rpcCmd.AddPrometheusPortFlag()
|
||||
if err := rpcCmd.Exec(); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImAesKeyName, aes_key.Start); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
@ -173,6 +173,7 @@ rpcPort:
|
||||
openImPushPort: [ 10170 ]
|
||||
openImConversationPort: [ 10180 ]
|
||||
openImThirdPort: [ 10190 ]
|
||||
openImAesKeyPort: [10200]
|
||||
|
||||
###################### RPC Register Name Configuration ######################
|
||||
# RPC service names for registration, it's not recommended to modify these
|
||||
@ -186,6 +187,7 @@ rpcRegisterName:
|
||||
openImAuthName: Auth
|
||||
openImConversationName: Conversation
|
||||
openImThirdName: Third
|
||||
openImAesKeyName: AesKey
|
||||
|
||||
###################### Log Configuration ######################
|
||||
# Log configuration
|
||||
@ -396,3 +398,4 @@ prometheus:
|
||||
rtcPrometheusPort: [ 21300 ]
|
||||
thirdPrometheusPort: [ 21301 ]
|
||||
messageTransferPrometheusPort: [ 21400, 21401, 21402, 21403 ] # List of ports
|
||||
aesKeyPrometheusPort: [21500]
|
||||
|
||||
1
go.mod
1
go.mod
@ -32,6 +32,7 @@ require (
|
||||
gorm.io/driver/mysql v1.5.2
|
||||
gorm.io/gorm v1.25.5
|
||||
)
|
||||
replace github.com/OpenIMSDK/protocol v0.0.31 => ../protocol
|
||||
|
||||
require github.com/google/uuid v1.3.1
|
||||
|
||||
|
||||
53
internal/rpc/aes_key/aes_key.go
Normal file
53
internal/rpc/aes_key/aes_key.go
Normal file
@ -0,0 +1,53 @@
|
||||
package aes_key
|
||||
|
||||
import (
|
||||
"context"
|
||||
key "github.com/OpenIMSDK/protocol/aeskey"
|
||||
registry "github.com/OpenIMSDK/tools/discoveryregistry"
|
||||
"github.com/OpenIMSDK/tools/utils"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/controller"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/relation"
|
||||
tablerelation "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type aesKeyServer struct {
|
||||
aesKeyDatabase controller.AesKeyDatabase
|
||||
RegisterCenter registry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
|
||||
db, err := relation.NewGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := db.AutoMigrate(&tablerelation.AesKeyModel{}); err != nil {
|
||||
return err
|
||||
}
|
||||
gorm := relation.NewAesKeyGorm(db)
|
||||
key.RegisterAesKeyServer(server, &aesKeyServer{
|
||||
aesKeyDatabase: controller.NewAesKeyDatabase(gorm),
|
||||
RegisterCenter: client,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
func (a *aesKeyServer) AcquireAesKey(ctx context.Context, req *key.AcquireAesKeyReq) (*key.AcquireAesKeyResp, error) {
|
||||
aesKey, err := a.aesKeyDatabase.AcquireAesKey(ctx, req.ConversationType, req.OwnerUserID, req.FriendUserID, req.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := key.AcquireAesKeyResp{}
|
||||
utils.CopyStructFields(resp.AesKey, &aesKey)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (a *aesKeyServer) AcquireAesKeys(ctx context.Context, req *key.AcquireAesKeysReq) (*key.AcquireAesKeysResp, error) {
|
||||
keysm, err := a.aesKeyDatabase.AcquireAesKeys(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var keys []*key.AesKey
|
||||
resp := key.AcquireAesKeysResp{AesKeys: keys}
|
||||
utils.CopyStructFields(&resp.AesKeys, &keysm)
|
||||
return &resp, nil
|
||||
}
|
||||
@ -9,4 +9,5 @@ const (
|
||||
RpcMsgServer = "msg"
|
||||
RpcThirdServer = "third"
|
||||
RpcUserServer = "user"
|
||||
RpcAesKeyServer = "aesKey"
|
||||
)
|
||||
|
||||
@ -113,6 +113,13 @@ func (a *RpcCmd) GetPortFromConfig(portType string) int {
|
||||
if portType == constant.FlagPrometheusPort {
|
||||
return config2.Config.Prometheus.UserPrometheusPort[0]
|
||||
}
|
||||
case RpcAesKeyServer:
|
||||
if portType == constant.FlagPort {
|
||||
return config2.Config.RpcPort.OpenImAesKeyPort[0]
|
||||
}
|
||||
if portType == constant.FlagPrometheusPort {
|
||||
return config2.Config.Prometheus.AesKeyPrometheusPort[0]
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -166,6 +166,7 @@ type configStruct struct {
|
||||
OpenImConversationPort []int `yaml:"openImConversationPort"`
|
||||
OpenImRtcPort []int `yaml:"openImRtcPort"`
|
||||
OpenImThirdPort []int `yaml:"openImThirdPort"`
|
||||
OpenImAesKeyPort []int `yaml:"openImAesKeyPort"`
|
||||
} `yaml:"rpcPort"`
|
||||
|
||||
RpcRegisterName struct {
|
||||
@ -178,6 +179,7 @@ type configStruct struct {
|
||||
OpenImAuthName string `yaml:"openImAuthName"`
|
||||
OpenImConversationName string `yaml:"openImConversationName"`
|
||||
OpenImThirdName string `yaml:"openImThirdName"`
|
||||
OpenImAesKeyName string `yaml:"openImAesKeyName"`
|
||||
} `yaml:"rpcRegisterName"`
|
||||
|
||||
Log struct {
|
||||
@ -280,6 +282,7 @@ type configStruct struct {
|
||||
RtcPrometheusPort []int `yaml:"rtcPrometheusPort"`
|
||||
MessageTransferPrometheusPort []int `yaml:"messageTransferPrometheusPort"`
|
||||
ThirdPrometheusPort []int `yaml:"thirdPrometheusPort"`
|
||||
AesKeyPrometheusPort []int `yaml:"aesKeyPrometheusPort"`
|
||||
} `yaml:"prometheus"`
|
||||
Notification notification `yaml:"notification"`
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/protocol/constant"
|
||||
"github.com/OpenIMSDK/tools/tx"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
|
||||
"sort"
|
||||
"strings"
|
||||
@ -19,11 +18,10 @@ type AesKeyDatabase interface {
|
||||
|
||||
type aesKeyDatabase struct {
|
||||
key relation.AesKeyModelInterface
|
||||
tx tx.Tx
|
||||
}
|
||||
|
||||
func NewAesKeyDatabase(key relation.AesKeyModelInterface, tx tx.Tx) *aesKeyDatabase {
|
||||
return &aesKeyDatabase{key: key, tx: tx}
|
||||
func NewAesKeyDatabase(key relation.AesKeyModelInterface) *aesKeyDatabase {
|
||||
return &aesKeyDatabase{key: key}
|
||||
}
|
||||
|
||||
func (a *aesKeyDatabase) AcquireAesKey(ctx context.Context, conversationType int32, userId, friendId, groupId string) (key *relation.AesKeyModel, err error) {
|
||||
|
||||
@ -11,8 +11,14 @@ type AesKeyGorm struct {
|
||||
*MetaDB
|
||||
}
|
||||
|
||||
/*
|
||||
func NewAesKeyGorm(db *gorm.DB) *AesKeyGorm {
|
||||
return &AesKeyGorm{NewMetaDB(db, &relation.AesKeyModel{})}
|
||||
return &AesKeyGorm{NewMetaDB(db, &relation.AesKeyModel{})}
|
||||
}
|
||||
*/
|
||||
func NewAesKeyGorm(db *gorm.DB) relation.AesKeyModelInterface {
|
||||
return &AesKeyGorm{NewMetaDB(db, relation.AesKeyModel{})}
|
||||
|
||||
}
|
||||
|
||||
func (a *AesKeyGorm) Installs(ctx context.Context, keys []*relation.AesKeyModel) (err error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user