Skip to content

Commit 83f16ba

Browse files
authored
Merge pull request #3017 from actiontech/3008-commits
update 5 api related to environment tag
2 parents c938da1 + 2ec36a2 commit 83f16ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2547
-3336
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.19
55
require (
66
github.com/DATA-DOG/go-sqlmock v1.5.0
77
github.com/Masterminds/semver/v3 v3.1.1
8-
github.com/actiontech/dms v0.0.0-20241223063204-661bd1bf229b
8+
github.com/actiontech/dms v0.0.0-20250411082853-ffd0db983e12
99
github.com/actiontech/java-sql-extractor v0.0.0-20231120024232-2b8c3c0894a1
1010
github.com/actiontech/mybatis-mapper-2-sql v0.5.1-0.20250307064901-aabaceee2249
1111
github.com/agiledragon/gomonkey v2.0.2+incompatible
@@ -68,6 +68,7 @@ require (
6868
github.com/hashicorp/go-version v1.7.0
6969
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.69
7070
github.com/nicksnyder/go-i18n/v2 v2.4.0
71+
golang.org/x/crypto v0.14.0
7172
golang.org/x/text v0.14.0
7273
gorm.io/driver/mysql v1.4.7
7374
gorm.io/gorm v1.24.3
@@ -166,7 +167,6 @@ require (
166167
go.uber.org/atomic v1.7.0 // indirect
167168
go.uber.org/multierr v1.6.0 // indirect
168169
go.uber.org/zap v1.17.0 // indirect
169-
golang.org/x/crypto v0.14.0 // indirect
170170
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
171171
golang.org/x/mod v0.12.0 // indirect
172172
golang.org/x/sys v0.15.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdc
4646
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
4747
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
4848
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
49-
github.com/actiontech/dms v0.0.0-20241223063204-661bd1bf229b h1:ROmTjEcA8/yVI2ohKfkuPyIz/MpJ39qpTg5pHfVdRGY=
50-
github.com/actiontech/dms v0.0.0-20241223063204-661bd1bf229b/go.mod h1:Jm+tDoBYmX8R8zqgPJRq1NwZXdxO/F+HxVRJVF65WXA=
49+
github.com/actiontech/dms v0.0.0-20250411082853-ffd0db983e12 h1:6wtTVErpbEabvlqdQ+IRAmX7ALxY0nTZNmkZTnk6B9I=
50+
github.com/actiontech/dms v0.0.0-20250411082853-ffd0db983e12/go.mod h1:Jm+tDoBYmX8R8zqgPJRq1NwZXdxO/F+HxVRJVF65WXA=
5151
github.com/actiontech/java-sql-extractor v0.0.0-20231120024232-2b8c3c0894a1 h1:/UHUgr+645xeXCqXzvOc3IqwOK5gLM+bU/C+s2Xe/Kk=
5252
github.com/actiontech/java-sql-extractor v0.0.0-20231120024232-2b8c3c0894a1/go.mod h1:adDZHhAf2LRMx2h0JzofPXn12x2XlyQjVE116KXquwo=
5353
github.com/actiontech/mybatis-mapper-2-sql v0.5.1-0.20250307064901-aabaceee2249 h1:BjbL364Bl45WMARnEqZrT7Pd0rMhd4vvnQbMvxX3iQw=

sqle/api/app.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
251251
v1ProjectOpRouter.POST("/:project_name/audit_plans/:audit_plan_name/sqls/full", v1.FullSyncAuditPlanSQLs, sqleMiddleware.ScannerVerifier())
252252
v1ProjectOpRouter.POST("/:project_name/audit_plans/:audit_plan_name/sqls/partial", v1.PartialSyncAuditPlanSQLs, sqleMiddleware.ScannerVerifier())
253253

254-
// instance audti plan 实例智能扫描任务
254+
// instance audit plan 实例智能扫描任务
255255
v1ProjectOpRouter.POST("/:project_name/instance_audit_plans", v1.CreateInstanceAuditPlan)
256256
v1ProjectOpRouter.DELETE("/:project_name/instance_audit_plans/:instance_audit_plan_id/", v1.DeleteInstanceAuditPlan)
257257
v1ProjectOpRouter.PUT("/:project_name/instance_audit_plans/:instance_audit_plan_id/", v1.UpdateInstanceAuditPlan)
@@ -310,7 +310,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
310310

311311
v1ProjectViewRouter.GET("/:project_name/instances/:instance_name/connection", v1.CheckInstanceIsConnectableByName)
312312
v1ProjectViewRouter.GET("/:project_name/instances/:instance_name/schemas", v1.GetInstanceSchemas)
313-
v1ProjectViewRouter.GET("/:project_name/instance_tips", v1.GetInstanceTips)
313+
v1ProjectViewRouter.GET("/:project_name/instance_tips", DeprecatedBy(apiV2))
314314
v1ProjectViewRouter.GET("/:project_name/instances/:instance_name/rules", v1.GetInstanceRules)
315315
v1ProjectViewRouter.GET("/:project_name/instances/:instance_name/schemas/:schema_name/tables", v1.ListTableBySchema)
316316
v1ProjectViewRouter.GET("/:project_name/instances/:instance_name/schemas/:schema_name/tables/:table_name/metadata", v1.GetTableMetadata)
@@ -345,12 +345,12 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
345345
v1ProjectViewRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/sqls", v1.GetAuditPlanReportSQLsV1)
346346
v1ProjectViewRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/export", v1.ExportAuditPlanReportV1)
347347

348-
v1ProjectViewRouter.GET("/:project_name/instance_audit_plans", v1.GetInstanceAuditPlans)
349-
v1ProjectViewRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id", v1.GetInstanceAuditPlanDetail)
348+
v1ProjectViewRouter.GET("/:project_name/instance_audit_plans", DeprecatedBy(apiV2))
349+
v1ProjectViewRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id", DeprecatedBy(apiV2))
350350
v1ProjectViewRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id/audit_plans", v1.GetInstanceAuditPlanOverview)
351351

352352
v1ProjectViewRouter.GET("/:project_name/sql_manages", v1.GetSqlManageList)
353-
v1ProjectViewRouter.GET("/:project_name/sql_manages/exports", v1.ExportSqlManagesV1)
353+
v1ProjectViewRouter.GET("/:project_name/sql_manages/exports", DeprecatedBy(apiV2))
354354
v1ProjectViewRouter.GET("/:project_name/sql_manages/rule_tips", v1.GetSqlManageRuleTips)
355355
v1ProjectViewRouter.GET("/:project_name/sql_manages/:sql_manage_id/sql_analysis", v1.GetSqlManageSqlAnalysisV1)
356356
v1ProjectViewRouter.GET("/:project_name/sql_manages/:sql_manage_id/sql_analysis_chart", v1.GetSqlManageSqlAnalysisChartV1)
@@ -414,6 +414,10 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
414414
v3ProjectOpRouter.POST("/:project_name/workflows/complete", v3.BatchCompleteWorkflowsV3)
415415

416416
}
417+
v3ProjectViewRouter := v3Router.Group("/projects", sqleMiddleware.ProjectMemberViewAllowed())
418+
{
419+
v3ProjectViewRouter.GET("/:project_name/sql_manages", v3.GetSqlManageList)
420+
}
417421

418422
v2ProjectViewRouter := v2Router.Group("/projects", sqleMiddleware.ProjectMemberViewAllowed())
419423
{
@@ -425,9 +429,13 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
425429
v2ProjectViewRouter.GET("/:project_name/audit_plans", v2.GetAuditPlans)
426430
v2ProjectViewRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/sqls/:number/analysis", v2.GetAuditPlanAnalysisData)
427431
v2ProjectViewRouter.GET("/:project_name/audit_plans/:audit_plan_name/reports/:audit_plan_report_id/sqls", v2.GetAuditPlanReportSQLs)
432+
v2ProjectViewRouter.GET("/:project_name/instance_tips", v2.GetInstanceTips)
428433

429434
// sql managers
430-
v2ProjectViewRouter.GET("/:project_name/sql_manages", v2.GetSqlManageList)
435+
v2ProjectViewRouter.GET("/:project_name/sql_manages", DeprecatedBy(apiV3))
436+
v2ProjectViewRouter.GET("/:project_name/sql_manages/exports", v2.ExportSqlManagesV2)
437+
v2ProjectViewRouter.GET("/:project_name/instance_audit_plans", v2.GetInstanceAuditPlans)
438+
v2ProjectViewRouter.GET("/:project_name/instance_audit_plans/:instance_audit_plan_id", v2.GetInstanceAuditPlanDetail)
431439
}
432440

433441
{

sqle/api/controller/v1/audit_plan.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ func CreateAuditPlan(c echo.Context) error {
334334
return controller.JSONBaseErrorReq(c, errAuditPlanInstanceConflict)
335335
}
336336

337-
projectUid, err := dms.GetPorjectUIDByName(c.Request().Context(), c.Param("project_name"), true)
337+
projectUid, err := dms.GetProjectUIDByName(c.Request().Context(), c.Param("project_name"), true)
338338
if err != nil {
339339
return controller.JSONBaseErrorReq(c, err)
340340
}
@@ -479,7 +479,7 @@ func autoSelectRuleTemplate(ctx context.Context, customRuleTemplateName string,
479479
// @router /v1/projects/{project_name}/audit_plans/{audit_plan_name}/ [delete]
480480
func DeleteAuditPlan(c echo.Context) error {
481481
s := model.GetStorage()
482-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"), true)
482+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"), true)
483483
if err != nil {
484484
return controller.JSONBaseErrorReq(c, err)
485485
}
@@ -523,7 +523,7 @@ func UpdateAuditPlan(c echo.Context) error {
523523
if err := controller.BindAndValidateReq(c, req); err != nil {
524524
return err
525525
}
526-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"), true)
526+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"), true)
527527
if err != nil {
528528
return controller.JSONBaseErrorReq(c, err)
529529
}
@@ -640,7 +640,7 @@ func GetAuditPlans(c echo.Context) error {
640640
if err := controller.BindAndValidateReq(c, req); err != nil {
641641
return err
642642
}
643-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
643+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
644644
if err != nil {
645645
return controller.JSONBaseErrorReq(c, err)
646646
}
@@ -718,7 +718,7 @@ type GetAuditPlanResV1 struct {
718718
// @Success 200 {object} v1.GetAuditPlanResV1
719719
// @router /v1/projects/{project_name}/audit_plans/{audit_plan_name}/ [get]
720720
func GetAuditPlan(c echo.Context) error {
721-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
721+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
722722
if err != nil {
723723
return controller.JSONBaseErrorReq(c, err)
724724
}
@@ -791,7 +791,7 @@ func GetAuditPlanReports(c echo.Context) error {
791791
return err
792792
}
793793

794-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
794+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
795795
if err != nil {
796796
return controller.JSONBaseErrorReq(c, err)
797797
}
@@ -851,7 +851,7 @@ type GetAuditPlanReportResV1 struct {
851851
// @Success 200 {object} v1.GetAuditPlanReportResV1
852852
// @router /v1/projects/{project_name}/audit_plans/{audit_plan_name}/reports/{audit_plan_report_id}/ [get]
853853
func GetAuditPlanReport(c echo.Context) error {
854-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
854+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
855855
if err != nil {
856856
return controller.JSONBaseErrorReq(c, err)
857857
}
@@ -929,7 +929,7 @@ func FullSyncAuditPlanSQLs(c echo.Context) error {
929929

930930
s := model.GetStorage()
931931

932-
projectUid, err := dms.GetPorjectUIDByName(c.Request().Context(), c.Param("project_name"), true)
932+
projectUid, err := dms.GetProjectUIDByName(c.Request().Context(), c.Param("project_name"), true)
933933
if err != nil {
934934
return controller.JSONBaseErrorReq(c, err)
935935
}
@@ -979,7 +979,7 @@ func PartialSyncAuditPlanSQLs(c echo.Context) error {
979979
apName := c.Param("audit_plan_name")
980980

981981
s := model.GetStorage()
982-
projectUid, err := dms.GetPorjectUIDByName(c.Request().Context(), c.Param("project_name"), true)
982+
projectUid, err := dms.GetProjectUIDByName(c.Request().Context(), c.Param("project_name"), true)
983983
if err != nil {
984984
return controller.JSONBaseErrorReq(c, err)
985985
}
@@ -1098,7 +1098,7 @@ type TriggerAuditPlanResV1 struct {
10981098
// @Success 200 {object} v1.TriggerAuditPlanResV1
10991099
// @router /v1/projects/{project_name}/audit_plans/{audit_plan_name}/trigger [post]
11001100
func TriggerAuditPlan(c echo.Context) error {
1101-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"), true)
1101+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"), true)
11021102
if err != nil {
11031103
return controller.JSONBaseErrorReq(c, err)
11041104
}
@@ -1155,7 +1155,7 @@ func UpdateAuditPlanNotifyConfig(c echo.Context) error {
11551155
return err
11561156
}
11571157

1158-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"), true)
1158+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"), true)
11591159
if err != nil {
11601160
return controller.JSONBaseErrorReq(c, err)
11611161
}
@@ -1219,7 +1219,7 @@ type GetAuditPlanNotifyConfigResDataV1 struct {
12191219
// @Success 200 {object} v1.GetAuditPlanNotifyConfigResV1
12201220
// @router /v1/projects/{project_name}/audit_plans/{audit_plan_name}/notify_config [get]
12211221
func GetAuditPlanNotifyConfig(c echo.Context) error {
1222-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
1222+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
12231223
if err != nil {
12241224
return controller.JSONBaseErrorReq(c, err)
12251225
}
@@ -1266,7 +1266,7 @@ type TestAuditPlanNotifyConfigResDataV1 struct {
12661266
// @Success 200 {object} v1.TestAuditPlanNotifyConfigResV1
12671267
// @router /v1/projects/{project_name}/audit_plans/{audit_plan_name}/notify_config/test [get]
12681268
func TestAuditPlanNotifyConfig(c echo.Context) error {
1269-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
1269+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
12701270
if err != nil {
12711271
return controller.JSONBaseErrorReq(c, err)
12721272
}
@@ -1395,7 +1395,7 @@ func GetAuditPlanSQLs(c echo.Context) error {
13951395
return err
13961396
}
13971397

1398-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
1398+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
13991399
if err != nil {
14001400
return controller.JSONBaseErrorReq(c, err)
14011401
}
@@ -1476,7 +1476,7 @@ func GetAuditPlanReportSQLsV1(c echo.Context) error {
14761476
if err := controller.BindAndValidateReq(c, req); err != nil {
14771477
return err
14781478
}
1479-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
1479+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
14801480
if err != nil {
14811481
return controller.JSONBaseErrorReq(c, err)
14821482
}
@@ -1518,7 +1518,7 @@ func GetAuditPlanReportSQLsV1(c echo.Context) error {
15181518
})
15191519
}
15201520

1521-
func spliceAuditResults(ctx context.Context, auditResults []model.AuditResult) string {
1521+
func SpliceAuditResults(ctx context.Context, auditResults []model.AuditResult) string {
15221522
lang := locale.Bundle.GetLangTagFromCtx(ctx)
15231523
results := []string{}
15241524
for _, auditResult := range auditResults {
@@ -1596,7 +1596,7 @@ func ExportAuditPlanReportV1(c echo.Context) error {
15961596

15971597
sqlInfo := [][]string{}
15981598
for idx, sql := range reportInfo.AuditPlanReportSQLs {
1599-
sqlInfo = append(sqlInfo, []string{strconv.Itoa(idx + 1), sql.SQL, spliceAuditResults(ctx, sql.AuditResults)})
1599+
sqlInfo = append(sqlInfo, []string{strconv.Itoa(idx + 1), sql.SQL, SpliceAuditResults(ctx, sql.AuditResults)})
16001600
}
16011601

16021602
err = csvBuilder.WriteRows(sqlInfo)

sqle/api/controller/v1/blacklist.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func CreateBlacklist(c echo.Context) error {
3636
return controller.JSONBaseErrorReq(c, err)
3737
}
3838

39-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"), true)
39+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"), true)
4040
if err != nil {
4141
return controller.JSONBaseErrorReq(c, err)
4242
}
@@ -66,7 +66,7 @@ func CreateBlacklist(c echo.Context) error {
6666
func DeleteBlacklist(c echo.Context) error {
6767
blacklistId := c.Param("blacklist_id")
6868

69-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
69+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
7070
if err != nil {
7171
return controller.JSONBaseErrorReq(c, err)
7272
}
@@ -113,7 +113,7 @@ func UpdateBlacklist(c echo.Context) error {
113113
}
114114

115115
blacklistId := c.Param("blacklist_id")
116-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
116+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
117117
if err != nil {
118118
return controller.JSONBaseErrorReq(c, err)
119119
}
@@ -192,7 +192,7 @@ func GetBlacklist(c echo.Context) error {
192192
return controller.JSONBaseErrorReq(c, err)
193193
}
194194

195-
projectUid, err := dms.GetPorjectUIDByName(context.TODO(), c.Param("project_name"))
195+
projectUid, err := dms.GetProjectUIDByName(context.TODO(), c.Param("project_name"))
196196
if err != nil {
197197
return controller.JSONBaseErrorReq(c, err)
198198
}

sqle/api/controller/v1/dashboard.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Dashboard(c echo.Context) error {
4545
if err := controller.BindAndValidateReq(c, req); err != nil {
4646
return controller.JSONBaseErrorReq(c, err)
4747
}
48-
projectUid, err := dms.GetPorjectUIDByName(c.Request().Context(), req.FilterProjectName)
48+
projectUid, err := dms.GetProjectUIDByName(c.Request().Context(), req.FilterProjectName)
4949
if err != nil {
5050
return controller.JSONBaseErrorReq(c, err)
5151
}

0 commit comments

Comments
 (0)