66 "context"
77 "encoding/base64"
88 "encoding/json"
9+ "errors"
910 "fmt"
1011 "io"
1112 "net/http"
@@ -22,6 +23,7 @@ import (
2223 "github.com/actiontech/dms/internal/dms/biz"
2324 pkgConst "github.com/actiontech/dms/internal/dms/pkg/constant"
2425 "github.com/actiontech/dms/internal/dms/storage"
26+ "github.com/actiontech/dms/internal/pkg/locale"
2527 dbmodel "github.com/actiontech/dms/internal/dms/storage/model"
2628 "github.com/actiontech/dms/internal/sql_workbench/client"
2729 config "github.com/actiontech/dms/internal/sql_workbench/config"
@@ -1020,7 +1022,7 @@ func (sqlWorkbenchService *SqlWorkbenchService) AuditMiddleware() echo.Middlewar
10201022 bodyBytes , err := io .ReadAll (c .Request ().Body )
10211023 if err != nil {
10221024 sqlWorkbenchService .log .Errorf ("failed to read request body: %v" , err )
1023- return fmt . Errorf ( "failed to read request body: %w" , err )
1025+ return errors . New ( locale . Bundle . LocalizeMsgByCtx ( c . Request (). Context (), locale . SqlWorkbenchAuditReadReqBodyErr ) )
10241026 }
10251027 // 恢复请求体,供后续处理使用
10261028 c .Request ().Body = io .NopCloser (bytes .NewBuffer (bodyBytes ))
@@ -1029,51 +1031,51 @@ func (sqlWorkbenchService *SqlWorkbenchService) AuditMiddleware() echo.Middlewar
10291031 sql , datasourceID , err := sqlWorkbenchService .parseStreamExecuteRequest (bodyBytes )
10301032 if err != nil {
10311033 sqlWorkbenchService .log .Errorf ("failed to parse streamExecute request, skipping audit: %v" , err )
1032- return fmt . Errorf ( "failed to parse streamExecute request, skipping audit: %v" , err )
1034+ return errors . New ( locale . Bundle . LocalizeMsgByCtx ( c . Request (). Context (), locale . SqlWorkbenchAuditParseReqErr ) )
10331035 }
10341036
10351037 if sql == "" || datasourceID == "" {
10361038 sqlWorkbenchService .log .Debugf ("SQL or datasource ID is empty, skipping audit" )
1037- return fmt . Errorf ( "SQL or datasource ID is empty, skipping audit" )
1039+ return errors . New ( locale . Bundle . LocalizeMsgByCtx ( c . Request (). Context (), locale . SqlWorkbenchAuditMissingSQLOrDatasourceErr ) )
10381040 }
10391041
10401042 // 获取当前用户 ID
10411043 dmsUserId , err := sqlWorkbenchService .getDMSUserIdFromRequest (c )
10421044 if err != nil {
10431045 sqlWorkbenchService .log .Errorf ("failed to get DMS user ID: %v" , err )
1044- return fmt . Errorf ( "failed to get DMS user ID: %v" , err )
1046+ return errors . New ( locale . Bundle . LocalizeMsgByCtx ( c . Request (). Context (), locale . SqlWorkbenchAuditGetDMSUserErr ) )
10451047 }
10461048
10471049 // 从缓存表获取 dms_db_service_id
10481050 dmsDBServiceID , err := sqlWorkbenchService .getDMSDBServiceIDFromCache (c .Request ().Context (), datasourceID , dmsUserId )
10491051 if err != nil {
10501052 sqlWorkbenchService .log .Errorf ("failed to get dms_db_service_id from cache: %v" , err )
1051- return fmt . Errorf ( "failed to get dms_db_service_id from cache: %v" , err )
1053+ return errors . New ( locale . Bundle . LocalizeMsgByCtx ( c . Request (). Context (), locale . SqlWorkbenchAuditGetDBServiceMappingErr ) )
10521054 }
10531055
10541056 if dmsDBServiceID == "" {
10551057 sqlWorkbenchService .log .Debugf ("dms_db_service_id not found in cache for datasource: %s" , datasourceID )
1056- return fmt . Errorf ( "dms_db_service_id not found in cache for datasource: %s" , datasourceID )
1058+ return errors . New ( locale . Bundle . LocalizeMsgByCtx ( c . Request (). Context (), locale . SqlWorkbenchAuditDBServiceMappingNotFoundErr ) )
10571059 }
10581060
10591061 // 获取 DBService 信息
10601062 dbService , err := sqlWorkbenchService .dbServiceUsecase .GetDBService (c .Request ().Context (), dmsDBServiceID )
10611063 if err != nil {
10621064 sqlWorkbenchService .log .Errorf ("failed to get DBService: %v" , err )
1063- return fmt . Errorf ( "failed to get DBService: %v" , err )
1065+ return errors . New ( locale . Bundle . LocalizeMsgByCtx ( c . Request (). Context (), locale . SqlWorkbenchAuditGetDBServiceErr ) )
10641066 }
10651067
10661068 // 检查是否启用 SQL 审核
10671069 if ! sqlWorkbenchService .isEnableSQLAudit (dbService ) {
10681070 sqlWorkbenchService .log .Debugf ("SQL audit is not enabled for DBService: %s" , dmsDBServiceID )
1069- return fmt . Errorf ( "SQL audit is not enabled for DBService: %s" , dmsDBServiceID )
1071+ return errors . New ( locale . Bundle . LocalizeMsgByCtx ( c . Request (). Context (), locale . SqlWorkbenchAuditNotEnabledErr ) )
10701072 }
10711073
10721074 // 调用 SQLE 审核接口
10731075 auditResult , err := sqlWorkbenchService .callSQLEAudit (c .Request ().Context (), sql , dbService )
10741076 if err != nil {
10751077 sqlWorkbenchService .log .Errorf ("call SQLE audit failed: %v" , err )
1076- return fmt . Errorf ( "call SQLE audit failed: %v" , err )
1078+ return errors . New ( locale . Bundle . LocalizeMsgByCtx ( c . Request (). Context (), locale . SqlWorkbenchAuditCallSQLEErr ) )
10771079 }
10781080
10791081 // 拦截响应并添加审核结果
0 commit comments