diff --git a/sqle/cmd/scannerd/scanners/common/file.go b/sqle/cmd/scannerd/scanners/common/file.go index 3d5cf3e7ec..f87d419087 100644 --- a/sqle/cmd/scannerd/scanners/common/file.go +++ b/sqle/cmd/scannerd/scanners/common/file.go @@ -11,6 +11,7 @@ import ( mybatisParser "github.com/actiontech/mybatis-mapper-2-sql" driverV2 "github.com/actiontech/sqle/sqle/driver/v2" + "github.com/actiontech/sqle/sqle/cmd/scannerd/scanners" ) func GetSQLFromPath(pathName string, skipErrorQuery, skipErrorFile bool, fileExtenssion string) (allSQL []driverV2.Node, err error) { @@ -54,7 +55,7 @@ func GetSQLFromFile(file string, skipErrorQuery bool, fileExtenssion string) (r return nil, err } switch fileExtenssion { - case "xml": + case scanners.MybatisFileExtension: sqls, err := mybatisParser.ParseXMLQuery(content, skipErrorQuery) if err != nil { return nil, err @@ -66,7 +67,7 @@ func GetSQLFromFile(file string, skipErrorQuery bool, fileExtenssion string) (r } r = append(r, n...) } - case "sql": + case scanners.SQLFileExtension: n, err := Parse(context.TODO(), content) if err != nil { return nil, err diff --git a/sqle/cmd/scannerd/scanners/common/interface_func.go b/sqle/cmd/scannerd/scanners/common/interface_func.go index aef686d96d..f40af9d743 100644 --- a/sqle/cmd/scannerd/scanners/common/interface_func.go +++ b/sqle/cmd/scannerd/scanners/common/interface_func.go @@ -9,7 +9,7 @@ import ( "github.com/actiontech/sqle/sqle/pkg/scanner" ) -func Upload(ctx context.Context, sqls []scanners.SQL, c *scanner.Client, apName string, skipAudit bool) error { +func UploadAndAudit(ctx context.Context, sqls []scanners.SQL, c *scanner.Client, apName string, skipAudit bool) error { // key=fingerPrint val=count counterMap := make(map[string]uint, len(sqls)) diff --git a/sqle/cmd/scannerd/scanners/mybatis/mybatis.go b/sqle/cmd/scannerd/scanners/mybatis/mybatis.go index 17e5866b76..9280818289 100644 --- a/sqle/cmd/scannerd/scanners/mybatis/mybatis.go +++ b/sqle/cmd/scannerd/scanners/mybatis/mybatis.go @@ -49,7 +49,7 @@ func New(params *Params, l *logrus.Entry, c *scanner.Client) (*MyBatis, error) { } func (mb *MyBatis) Run(ctx context.Context) error { - sqls, err := common.GetSQLFromPath(mb.xmlDir, mb.skipErrorQuery, mb.skipErrorXml, "xml") + sqls, err := common.GetSQLFromPath(mb.xmlDir, mb.skipErrorQuery, mb.skipErrorXml, scanners.MybatisFileExtension) if err != nil { return err } @@ -80,5 +80,5 @@ func (mb *MyBatis) SQLs() <-chan scanners.SQL { func (mb *MyBatis) Upload(ctx context.Context, sqls []scanners.SQL) error { mb.sqls = append(mb.sqls, sqls...) - return common.Upload(ctx, mb.sqls, mb.c, mb.apName, mb.skipAudit) + return common.UploadAndAudit(ctx, mb.sqls, mb.c, mb.apName, mb.skipAudit) } diff --git a/sqle/cmd/scannerd/scanners/scanner.go b/sqle/cmd/scannerd/scanners/scanner.go index 1cc67f7805..06db2e6fc6 100644 --- a/sqle/cmd/scannerd/scanners/scanner.go +++ b/sqle/cmd/scannerd/scanners/scanner.go @@ -4,6 +4,11 @@ import ( "context" ) +const ( + MybatisFileExtension = "xml" + SQLFileExtension = "sql" +) + type SQL struct { Fingerprint string RawText string diff --git a/sqle/cmd/scannerd/scanners/sqlfile/sqlfile.go b/sqle/cmd/scannerd/scanners/sqlfile/sqlfile.go index 8732d1624d..f9dddb222c 100644 --- a/sqle/cmd/scannerd/scanners/sqlfile/sqlfile.go +++ b/sqle/cmd/scannerd/scanners/sqlfile/sqlfile.go @@ -47,7 +47,7 @@ func New(params *Params, l *logrus.Entry, c *scanner.Client) (*SQLFile, error) { } func (sf *SQLFile) Run(ctx context.Context) error { - sqls, err := common.GetSQLFromPath(sf.sqlDir, false, sf.skipErrorSqlFile, "sql") + sqls, err := common.GetSQLFromPath(sf.sqlDir, false, sf.skipErrorSqlFile, scanners.SQLFileExtension) if err != nil { return err } @@ -78,5 +78,5 @@ func (sf *SQLFile) SQLs() <-chan scanners.SQL { func (sf *SQLFile) Upload(ctx context.Context, sqls []scanners.SQL) error { sf.sqls = append(sf.sqls, sqls...) - return common.Upload(ctx, sf.sqls, sf.c, sf.apName, sf.skipAudit) + return common.UploadAndAudit(ctx, sf.sqls, sf.c, sf.apName, sf.skipAudit) }