Skip to content

Commit 4c2b3a3

Browse files
committed
Feat actiontech/dms-ee/issues/125: plugin interface define
1 parent fc55764 commit 4c2b3a3

10 files changed

+670
-121
lines changed

sqle/driver/plugin_adapter_v1.go

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
sqlDriver "database/sql/driver"
66

7+
dmsCommonSQLOp "github.com/actiontech/dms/pkg/dms-common/sql_op"
78
driverV1 "github.com/actiontech/sqle/sqle/driver/v1"
89
driverV2 "github.com/actiontech/sqle/sqle/driver/v2"
910
"github.com/actiontech/sqle/sqle/errors"
@@ -314,3 +315,7 @@ func (p *PluginImplV1) GetTableMetaBySQL(ctx context.Context, conf *GetTableMeta
314315
func (p *PluginImplV1) EstimateSQLAffectRows(ctx context.Context, sql string) (*driverV2.EstimatedAffectRows, error) {
315316
return nil, NewErrPluginAPINotImplement(driverV2.OptionalModuleEstimateSQLAffectRows)
316317
}
318+
319+
func (p *PluginImplV1) GetSQLOp(ctx context.Context, sqls string) ([]*dmsCommonSQLOp.SQLObjectOps, error) {
320+
return nil, NewErrPluginAPINotImplement(driverV2.OptionalModuleProvision)
321+
}

sqle/driver/plugin_adapter_v2.go

+17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"sync"
99

10+
dmsCommonSQLOp "github.com/actiontech/dms/pkg/dms-common/sql_op"
1011
driverV2 "github.com/actiontech/sqle/sqle/driver/v2"
1112
protoV2 "github.com/actiontech/sqle/sqle/driver/v2/proto"
1213
"github.com/actiontech/sqle/sqle/log"
@@ -485,6 +486,22 @@ func (s *PluginImplV2) EstimateSQLAffectRows(ctx context.Context, sql string) (*
485486
}, nil
486487
}
487488

489+
func (s *PluginImplV2) GetSQLOp(ctx context.Context, sqls string) ([]*dmsCommonSQLOp.SQLObjectOps, error) {
490+
api := "GetSQLOp"
491+
s.preLog(api)
492+
resp, err := s.client.GetSQLOp(ctx, &protoV2.GetSQLOpRequest{
493+
Session: s.Session,
494+
SqlText: &protoV2.GetSQLOpSQL{
495+
Sql: sqls,
496+
},
497+
})
498+
s.afterLog(api, err)
499+
if err != nil {
500+
return nil, err
501+
}
502+
return driverV2.ConvertProtoSQLOpsResponseToDriver(resp)
503+
}
504+
488505
type dbDriverResult struct {
489506
lastInsertId int64
490507
lastInsertIdErr string

sqle/driver/plugin_interface.go

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"database/sql/driver"
66

77
driverV2 "github.com/actiontech/sqle/sqle/driver/v2"
8+
dmsCommonSQLOp "github.com/actiontech/dms/pkg/dms-common/sql_op"
89

910
"github.com/sirupsen/logrus"
1011
)
@@ -40,6 +41,10 @@ type Plugin interface {
4041

4142
// Introduced from v2.2304.0
4243
EstimateSQLAffectRows(ctx context.Context, sql string) (*driverV2.EstimatedAffectRows, error)
44+
45+
// 权限相关接口,目前用于provision的权限校验
46+
// GetSqlOp 获取sql中涉及的对象操作,sql可以是单条语句,也可以是多条语句
47+
GetSQLOp(ctx context.Context, sqls string) ([]*dmsCommonSQLOp.SQLObjectOps, error)
4348
}
4449

4550
type PluginProcessor interface {

sqle/driver/v2/driver_grpc_server.go

+15
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,18 @@ func (d *DriverGrpcServer) KillProcess(ctx context.Context, req *protoV2.KillPro
449449
ErrMessage: info.ErrMessage,
450450
}, nil
451451
}
452+
453+
func (d *DriverGrpcServer) GetSQLOp(ctx context.Context, req *protoV2.GetSQLOpRequest) (*protoV2.GetSQLOpResponse, error) {
454+
driver, err := d.getDriverBySession(req.Session)
455+
if err != nil {
456+
return &protoV2.GetSQLOpResponse{}, err
457+
}
458+
if req.GetSqlText() == nil {
459+
return &protoV2.GetSQLOpResponse{}, ErrSQLisEmpty
460+
}
461+
ops, err := driver.GetSQLOp(ctx, req.GetSqlText().Sql)
462+
if err != nil {
463+
return &protoV2.GetSQLOpResponse{}, err
464+
}
465+
return ConvertDriverSQLOpsResponseToProto(ops)
466+
}

sqle/driver/v2/driver_interface.go

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"sort"
99
"strings"
1010

11+
dmsCommonSQLOp "github.com/actiontech/dms/pkg/dms-common/sql_op"
1112
"github.com/actiontech/sqle/sqle/driver/common"
1213
protoV2 "github.com/actiontech/sqle/sqle/driver/v2/proto"
1314
"github.com/actiontech/sqle/sqle/pkg/params"
@@ -88,6 +89,10 @@ type Driver interface {
8889
ExtractTableFromSQL(ctx context.Context, sql string) ([]*Table, error)
8990
EstimateSQLAffectRows(ctx context.Context, sql string) (*EstimatedAffectRows, error)
9091
KillProcess(ctx context.Context) (*KillProcessInfo, error)
92+
93+
// 权限相关接口,目前用于provision的权限校验
94+
// GetSQLOp 获取sql中涉及的对象操作,sql可以是单条语句,也可以是多条语句
95+
GetSQLOp(ctx context.Context, sqls string) ([]*dmsCommonSQLOp.SQLObjectOps, error)
9196
}
9297

9398
type Node struct {

0 commit comments

Comments
 (0)