@@ -3,12 +3,6 @@ package services
33import (
44 "encoding/json"
55 "fmt"
6- "net"
7- "os"
8- "os/exec"
9- "path/filepath"
10- "strings"
11- "time"
126
137 "github.com/checkmarx/ast-cli/internal/commands/asca/ascaconfig"
148 "github.com/checkmarx/ast-cli/internal/logger"
@@ -19,7 +13,14 @@ import (
1913 "github.com/checkmarx/ast-cli/internal/wrappers/configuration"
2014 "github.com/checkmarx/ast-cli/internal/wrappers/grpcs"
2115 getport "github.com/jsumners/go-getport"
16+ "github.com/pkg/errors"
2217 "github.com/spf13/viper"
18+ "net"
19+ "os"
20+ "os/exec"
21+ "path/filepath"
22+ "strings"
23+ "time"
2324)
2425
2526const (
@@ -39,22 +40,53 @@ type AscaWrappersParam struct {
3940 ASCAWrapper grpcs.AscaWrapper
4041}
4142
42- func CreateASCAScanRequest ( ascaParams AscaScanParams , wrapperParams AscaWrappersParam ) ( * grpcs. ScanResult , error ) {
43- err := manageASCAInstallation ( ascaParams , wrapperParams )
43+ func validateVorpalDirExist ( dirPath string ) error {
44+ info , err := os . Stat ( dirPath )
4445 if err != nil {
45- return nil , err
46+ if os .IsNotExist (err ) {
47+ return errors .Errorf ("%s path does not exist" , dirPath )
48+ }
49+ if errors .Is (err , os .ErrPermission ) {
50+ return errors .Errorf ("permission denied while accessing path %s" , dirPath )
51+ }
52+ return errors .Errorf ("cannot access path %s: %v" , dirPath , err )
53+ }
54+ if ! info .IsDir () {
55+ return errors .Errorf ("provided path is not a directory %s" , dirPath )
4656 }
57+ return nil
58+ }
59+
60+ func ValidateCustomASCAInstallation (vorpalLocation string ) error {
61+ if err := validateVorpalDirExist (vorpalLocation ); err != nil {
62+ return errors .Wrap (err , "Failed to validate ASCA location" )
63+ }
64+ ascaconfig .Params .SetVorpalCustomPath (vorpalLocation )
65+ ASCAInstalled , _ := osinstaller .FileExists (ascaconfig .Params .ExecutableFilePath ())
66+ if ! ASCAInstalled {
67+ return errors .Errorf ("No ASCA executable found in provided location: %s" , vorpalLocation )
68+ }
69+ return nil
70+ }
4771
72+ func CreateASCAScanRequest (ascaParams AscaScanParams , wrapperParams AscaWrappersParam , vorpalLocation string ) (* grpcs.ScanResult , error ) {
73+ var err error
74+ if vorpalLocation == "" {
75+ err = manageASCAInstallation (ascaParams , wrapperParams )
76+ if err != nil {
77+ return nil , err
78+ }
79+ } else if err = ValidateCustomASCAInstallation (vorpalLocation ); err != nil {
80+ return nil , err
81+ }
4882 err = ensureASCAServiceRunning (wrapperParams , ascaParams )
4983 if err != nil {
5084 return nil , err
5185 }
52-
5386 emptyResults := validateFilePath (ascaParams .FilePath )
5487 if emptyResults != nil {
5588 return emptyResults , nil
5689 }
57-
5890 ignoredResults := validateIgnoredFilePath (ascaParams .IgnoredFilePath )
5991 if ignoredResults != nil {
6092 return ignoredResults , nil
@@ -266,7 +298,6 @@ func RunASCAEngine(port int) error {
266298 if err != nil {
267299 return err
268300 }
269-
270301 ready := waitForServer (fmt .Sprintf ("localhost:%d" , port ), dialTimeout )
271302 if ! ready {
272303 return fmt .Errorf ("server did not become ready in time" )
0 commit comments