45 lines
1003 B
Go
45 lines
1003 B
Go
package user
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"tianyuan-api/apps/sentinel/sentinel"
|
||
|
||
"tianyuan-api/apps/gateway/internal/svc"
|
||
"tianyuan-api/apps/gateway/internal/types"
|
||
|
||
"github.com/zeromicro/go-zero/core/logx"
|
||
)
|
||
|
||
type GetSecretInfoLogic struct {
|
||
logx.Logger
|
||
ctx context.Context
|
||
svcCtx *svc.ServiceContext
|
||
}
|
||
|
||
func NewGetSecretInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSecretInfoLogic {
|
||
return &GetSecretInfoLogic{
|
||
Logger: logx.WithContext(ctx),
|
||
ctx: ctx,
|
||
svcCtx: svcCtx,
|
||
}
|
||
}
|
||
|
||
func (l *GetSecretInfoLogic) GetSecretInfo() (resp *types.SecretInfoResp, err error) {
|
||
// 从上下文中解析 JWT,获取用户ID
|
||
userId, ok := l.ctx.Value("userId").(int64)
|
||
if !ok {
|
||
return nil, errors.New("无法获取 userId")
|
||
}
|
||
secret, err := l.svcCtx.SecretRpc.GetSecretByUserId(l.ctx, &sentinel.GetRecordByIdRequest{
|
||
Id: userId,
|
||
})
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
return &types.SecretInfoResp{
|
||
AccessId: secret.SecretId,
|
||
AccessKey: secret.AesKey,
|
||
}, nil
|
||
}
|