Skip to content

Commit

Permalink
split function
Browse files Browse the repository at this point in the history
  • Loading branch information
hasa1K committed Aug 2, 2023
1 parent 46fe62f commit 6cb83f9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
13 changes: 4 additions & 9 deletions sqle/cmd/scannerd/scanners/common/interface_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/actiontech/sqle/sqle/pkg/scanner"
)

func UploadAndAudit(ctx context.Context, sqls []scanners.SQL, c *scanner.Client, apName string, skipAudit bool) error {
func Upload(ctx context.Context, sqls []scanners.SQL, c *scanner.Client, apName string) error {
// key=fingerPrint val=count
counterMap := make(map[string]uint, len(sqls))

Expand All @@ -33,18 +33,13 @@ func UploadAndAudit(ctx context.Context, sqls []scanners.SQL, c *scanner.Client,
}

err := c.UploadReq(scanner.FullUpload, apName, reqBody)
if err != nil {
return err
}

if skipAudit {
return nil
}
return err
}

func Audit(c *scanner.Client, apName string) error {
reportID, err := c.TriggerAuditReq(apName)
if err != nil {
return err
}
return c.GetAuditReportReq(apName, reportID)
}

11 changes: 10 additions & 1 deletion sqle/cmd/scannerd/scanners/mybatis/mybatis.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,14 @@ 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.UploadAndAudit(ctx, mb.sqls, mb.c, mb.apName, mb.skipAudit)
err := common.Upload(ctx, mb.sqls, mb.c, mb.apName)
if err != nil {
return err
}
if mb.skipAudit {
return nil
}

err = common.Audit(mb.c, mb.apName)
return err
}
11 changes: 10 additions & 1 deletion sqle/cmd/scannerd/scanners/sqlfile/sqlfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,14 @@ 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.UploadAndAudit(ctx, sf.sqls, sf.c, sf.apName, sf.skipAudit)
err := common.Upload(ctx, sf.sqls, sf.c, sf.apName)
if err != nil {
return err
}
if sf.skipAudit {
return nil
}

err = common.Audit(sf.c, sf.apName)
return err
}

0 comments on commit 6cb83f9

Please sign in to comment.