f
This commit is contained in:
@@ -753,6 +753,38 @@ func (s *ApiApplicationServiceImpl) GetUserApiCalls(ctx context.Context, userID
|
||||
}, nil
|
||||
}
|
||||
|
||||
// resolveAdminRequestParams 解密并返回可读请求参数(供管理端使用,展示由前端开发环境控制)
|
||||
func (s *ApiApplicationServiceImpl) resolveAdminRequestParams(ctx context.Context, call *entities.ApiCall) string {
|
||||
if call.RequestParams == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
requestParamsStr := call.RequestParams
|
||||
if call.UserId == nil || *call.UserId == "" {
|
||||
return requestParamsStr
|
||||
}
|
||||
|
||||
apiUser, err := s.apiUserService.LoadApiUserByUserId(ctx, *call.UserId)
|
||||
if err != nil || apiUser == nil || apiUser.SecretKey == "" {
|
||||
return requestParamsStr
|
||||
}
|
||||
|
||||
decryptedParams, err := s.DecryptParams(ctx, *call.UserId, &commands.DecryptCommand{
|
||||
EncryptedData: call.RequestParams,
|
||||
SecretKey: apiUser.SecretKey,
|
||||
})
|
||||
if err != nil {
|
||||
return requestParamsStr
|
||||
}
|
||||
|
||||
jsonBytes, err := json.Marshal(decryptedParams)
|
||||
if err != nil {
|
||||
return requestParamsStr
|
||||
}
|
||||
|
||||
return string(jsonBytes)
|
||||
}
|
||||
|
||||
// GetAdminApiCalls 获取管理端API调用记录
|
||||
func (s *ApiApplicationServiceImpl) GetAdminApiCalls(ctx context.Context, filters map[string]interface{}, options shared_interfaces.ListOptions) (*dto.ApiCallListResponse, error) {
|
||||
// 查询API调用记录(包含产品名称)
|
||||
@@ -771,50 +803,13 @@ func (s *ApiApplicationServiceImpl) GetAdminApiCalls(ctx context.Context, filter
|
||||
continue
|
||||
}
|
||||
|
||||
// // 解密请求参数
|
||||
// var requestParamsStr string = call.RequestParams // 默认使用原始值
|
||||
// if call.UserId != nil && *call.UserId != "" {
|
||||
// // 获取用户的API密钥信息
|
||||
// apiUser, err := s.apiUserService.LoadApiUserByUserId(ctx, *call.UserId)
|
||||
// if err != nil {
|
||||
// s.logger.Error("获取用户API信息失败",
|
||||
// zap.Error(err),
|
||||
// zap.String("call_id", call.ID),
|
||||
// zap.String("user_id", *call.UserId))
|
||||
// // 获取失败时使用原始值
|
||||
// } else if apiUser.SecretKey != "" {
|
||||
// // 使用用户的SecretKey解密请求参数
|
||||
// decryptedParams, err := s.DecryptParams(ctx, *call.UserId, &commands.DecryptCommand{
|
||||
// EncryptedData: call.RequestParams,
|
||||
// SecretKey: apiUser.SecretKey,
|
||||
// })
|
||||
// if err != nil {
|
||||
// s.logger.Error("解密请求参数失败",
|
||||
// zap.Error(err),
|
||||
// zap.String("call_id", call.ID),
|
||||
// zap.String("user_id", *call.UserId))
|
||||
// // 解密失败时使用原始值
|
||||
// } else {
|
||||
// // 将解密后的数据转换为JSON字符串
|
||||
// if jsonBytes, err := json.Marshal(decryptedParams); err == nil {
|
||||
// requestParamsStr = string(jsonBytes)
|
||||
// } else {
|
||||
// s.logger.Error("序列化解密参数失败",
|
||||
// zap.Error(err),
|
||||
// zap.String("call_id", call.ID))
|
||||
// // 序列化失败时使用原始值
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
item := dto.ApiCallRecordResponse{
|
||||
ID: call.ID,
|
||||
AccessId: call.AccessId,
|
||||
TransactionId: call.TransactionId,
|
||||
ClientIp: call.ClientIp,
|
||||
// RequestParams: requestParamsStr,
|
||||
Status: call.Status,
|
||||
RequestParams: s.resolveAdminRequestParams(ctx, call),
|
||||
Status: call.Status,
|
||||
}
|
||||
|
||||
// 安全设置用户ID
|
||||
|
||||
Reference in New Issue
Block a user