Skip to content

Commit b58491b

Browse files
author
wangyue
committed
Feat actiontech/dms-ee/issues/125: plugin interface define
1 parent 5da439b commit b58491b

File tree

12 files changed

+3217
-120
lines changed

12 files changed

+3217
-120
lines changed

driver_v2.pb.go

Lines changed: 2508 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqle/driver/mysql/mysql.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@ func (i *MysqlDriverImpl) getPrimaryKey(stmt *ast.CreateTableStmt) (map[string]s
577577
return pkColumnsName, hasPk, nil
578578
}
579579

580+
func (i *MysqlDriverImpl) GetSQLOp(ctx context.Context, sqls string) ([]*driverV2.SQLObjectOps, error) {
581+
return nil, fmt.Errorf("not implement yet")
582+
}
583+
580584
type PluginProcessor struct{}
581585

582586
func (p *PluginProcessor) GetDriverMetas() (*driverV2.DriverMetas, error) {

sqle/driver/plugin_adapter_v1.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,7 @@ func (p *PluginImplV1) GetTableMetaBySQL(ctx context.Context, conf *GetTableMeta
314314
func (p *PluginImplV1) EstimateSQLAffectRows(ctx context.Context, sql string) (*driverV2.EstimatedAffectRows, error) {
315315
return nil, NewErrPluginAPINotImplement(driverV2.OptionalModuleEstimateSQLAffectRows)
316316
}
317+
318+
func (p *PluginImplV1) GetSQLOp(ctx context.Context, sqls string) ([]*driverV2.SQLObjectOps, error) {
319+
return nil, NewErrPluginAPINotImplement(driverV2.OptionalModuleProvision)
320+
}

sqle/driver/plugin_adapter_v2.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,22 @@ func (s *PluginImplV2) EstimateSQLAffectRows(ctx context.Context, sql string) (*
485485
}, nil
486486
}
487487

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

sqle/driver/plugin_interface.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ type Plugin interface {
4040

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

4549
type PluginProcessor interface {

sqle/driver/v2/driver_grpc_server.go

Lines changed: 15 additions & 0 deletions
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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ type Driver interface {
8888
ExtractTableFromSQL(ctx context.Context, sql string) ([]*Table, error)
8989
EstimateSQLAffectRows(ctx context.Context, sql string) (*EstimatedAffectRows, error)
9090
KillProcess(ctx context.Context) (*KillProcessInfo, error)
91+
92+
// 权限相关接口,目前用于provision的权限校验
93+
// GetSQLOp 获取sql中涉及的对象操作,sql可以是单条语句,也可以是多条语句
94+
GetSQLOp(ctx context.Context, sqls string) ([]*SQLObjectOps, error)
9195
}
9296

9397
type Node struct {
@@ -304,3 +308,49 @@ func NewKillProcessInfo(errorMessage string) *KillProcessInfo {
304308
type RuleKnowledge struct {
305309
Content string
306310
}
311+
312+
type SQLObjectOps struct {
313+
// ObjectOps 表示sql中涉及的对象及对对象的操作
314+
ObjectOps []*SQLObjectOp
315+
Sql SQLInfo
316+
}
317+
318+
type SQLObjectOp struct {
319+
Op SQLOp // 对象操作
320+
Object *SQLObject // 对象
321+
}
322+
323+
type SQLObject struct {
324+
// Type 表示对象的类型
325+
Type SQLObjectType
326+
// SchemaName 表示对象所在的库名,若对象不属于库,或无法从Sql中解析出当前库,则为空字符串
327+
SchemaName string
328+
// TableName 表示对象的表名,如果对象不是表,则为空字符串
329+
TableName string
330+
}
331+
332+
type SQLObjectType string
333+
334+
const (
335+
SQLObjectTypeTable SQLObjectType = "Table"
336+
SQLObjectTypeSchema SQLObjectType = "Schema"
337+
SQLObjectTypeInstance SQLObjectType = "Instance"
338+
)
339+
340+
type SQLInfo struct {
341+
Sql string
342+
}
343+
type SQLOp string
344+
345+
const (
346+
// 增或改操作
347+
SQLOpAddOrUpdate SQLOp = "AddOrUpdate"
348+
// 读取操作
349+
SQLOpRead SQLOp = "Read"
350+
// 删除操作
351+
SQLOpDelete SQLOp = "Delete"
352+
// 授权操作
353+
SQLOpGrant SQLOp = "Grant"
354+
// 高权限操作,如锁表、导出表到文件等
355+
SQLOpAdmin SQLOp = "Admin"
356+
)

0 commit comments

Comments
 (0)