Skip to content

Commit

Permalink
feat: 支持标准扫描器适配器根据参数动态生成启动命令 #73
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlkl committed Nov 13, 2024
1 parent f7e7a46 commit 19623e8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions standard-adapter/pkg/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import (
"github.com/TencentBlueKing/ci-repoAnalysis/analysis-tool-sdk-golang/object"
"github.com/TencentBlueKing/ci-repoAnalysis/analysis-tool-sdk-golang/util"
"os"
"strings"
)

type CmdBuilder interface {
// Build 生成扫描执行器启动命令, 返回(命令名,参数列表)
Build(input *object.ToolInput) (string, []string, error)
}

// StandardAdapterExecutor 标准扫描器适配器
type StandardAdapterExecutor struct {
Cmd string
WorkDir string
CmdBuilder CmdBuilder
WorkDir string
}

// Execute 执行扫描
Expand All @@ -38,15 +42,12 @@ func (e StandardAdapterExecutor) Execute(

// 执行扫描
toolOutputFile := util.WorkDir + "/output.json"
var args []string
cmd := e.Cmd
splitCmd := strings.Split(e.Cmd, " ")
if len(splitCmd) > 1 {
cmd = splitCmd[0]
args = append(args, splitCmd[1:]...)
cmd, args, err := e.CmdBuilder.Build(newToolInput)
if err != nil {
return nil, err
}
args = append(args, "--input", toolInputFile, "--output", toolOutputFile)
err := util.ExecAndLog(ctx, cmd, args, e.WorkDir)
err = util.ExecAndLog(ctx, cmd, args, e.WorkDir)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 19623e8

Please sign in to comment.