Skip to content

Commit

Permalink
Fix sast
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Sep 11, 2023
1 parent afed554 commit b0fc755
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions xray/commands/audit/jas/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func CreateScannersConfigFile(fileName string, fileContent interface{}) error {
return err
}
err = os.WriteFile(fileName, yamlData, 0644)
log.Debug("Input YAML:\n" + string(yamlData))
return errorutils.CheckError(err)
}

Expand Down
9 changes: 7 additions & 2 deletions xray/commands/audit/jas/sast/sastscanner.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package sast

import (
"path/filepath"

jfrogappsconfig "github.com/jfrog/jfrog-apps-config/go"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/audit/jas"
"github.com/jfrog/jfrog-cli-core/v2/xray/utils"
"github.com/jfrog/jfrog-client-go/utils/log"
)

const (
sastScannerType = "sast"
sastScanCommand = "zd"
)

Expand Down Expand Up @@ -44,7 +47,7 @@ func (ssm *SastScanManager) Run(module jfrogappsconfig.Module) (err error) {
if err = ssm.createConfigFile(module); err != nil {
return
}
if err = ssm.runAnalyzerManager(module.SourceRoot); err != nil {
if err = ssm.runAnalyzerManager(filepath.Dir(ssm.scanner.AnalyzerManager.AnalyzerManagerFullPath)); err != nil {
return
}
var workingDirResults []utils.SourceCodeScanResult
Expand All @@ -60,6 +63,7 @@ type sastScanConfig struct {
}

type scanConfiguration struct {
Type string `yaml:"type"`
Roots []string `yaml:"roots,omitempty"`
Languages []string `yaml:"language,omitempty"`
ExcludePatterns []string `yaml:"exclude_patterns,omitempty"`
Expand All @@ -78,6 +82,7 @@ func (ssm *SastScanManager) createConfigFile(module jfrogappsconfig.Module) erro
configFileContent := sastScanConfig{
Scans: []scanConfiguration{
{
Type: sastScannerType,
Roots: roots,
Languages: []string{sastScanner.Language},
ExcludedRules: sastScanner.ExcludedRules,
Expand All @@ -89,5 +94,5 @@ func (ssm *SastScanManager) createConfigFile(module jfrogappsconfig.Module) erro
}

func (ssm *SastScanManager) runAnalyzerManager(wd string) error {
return ssm.scanner.AnalyzerManager.ExecWithOutputFile(ssm.scanner.ResultsFileName, sastScanCommand, wd, ssm.scanner.ResultsFileName, ssm.scanner.ServerDetails)
return ssm.scanner.AnalyzerManager.ExecWithOutputFile(ssm.scanner.ConfigFileName, sastScanCommand, wd, ssm.scanner.ResultsFileName, ssm.scanner.ServerDetails)
}
10 changes: 8 additions & 2 deletions xray/utils/analyzermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,14 @@ func (am *AnalyzerManager) ExecWithOutputFile(configFile, scanCommand, workingDi
if err = SetAnalyzerManagerEnvVariables(serverDetails); err != nil {
return err
}
log.Debug("Executing", am.AnalyzerManagerFullPath, scanCommand, outputFile, configFile)
cmd := exec.Command(am.AnalyzerManagerFullPath, scanCommand, outputFile, configFile)
var cmd *exec.Cmd
if len(outputFile) > 0 {
log.Debug("Executing", am.AnalyzerManagerFullPath, scanCommand, configFile, outputFile)
cmd = exec.Command(am.AnalyzerManagerFullPath, scanCommand, configFile, outputFile)
} else {
log.Debug("Executing", am.AnalyzerManagerFullPath, scanCommand, configFile)
cmd = exec.Command(am.AnalyzerManagerFullPath, scanCommand, configFile)
}
defer func() {
if !cmd.ProcessState.Exited() {
if killProcessError := cmd.Process.Kill(); errorutils.CheckError(killProcessError) != nil {
Expand Down

0 comments on commit b0fc755

Please sign in to comment.