Skip to content

Commit

Permalink
Set analyzer manager version by environment variable (#935)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored Sep 7, 2023
1 parent d12337c commit fd00f19
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
3 changes: 1 addition & 2 deletions xray/commands/audit/jasrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package audit

import (
"errors"
"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/audit/jas"
"github.com/jfrog/jfrog-cli-core/v2/xray/commands/audit/jas/applicability"
Expand Down Expand Up @@ -49,7 +48,7 @@ func runJasScannersAndSetResults(scanResults *utils.ExtendedScanResults, directD
if err != nil {
return
}
if !version.NewVersion(utils.AnalyzerManagerVersion).AtLeast(utils.MinAnalyzerManagerVersionForSast) {
if !utils.IsSastSupported() {
return
}
if progress != nil {
Expand Down
51 changes: 32 additions & 19 deletions xray/utils/analyzermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"errors"
"fmt"
"github.com/jfrog/gofrog/version"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -38,24 +39,25 @@ var (
)

const (
EntitlementsMinVersion = "3.66.5"
ApplicabilityFeatureId = "contextual_analysis"
AnalyzerManagerZipName = "analyzerManager.zip"
AnalyzerManagerVersion = "1.2.4.1953469"
MinAnalyzerManagerVersionForSast = "1.3"
analyzerManagerDownloadPath = "xsc-gen-exe-analyzer-manager-local/v1"
analyzerManagerDirName = "analyzerManager"
analyzerManagerExecutableName = "analyzerManager"
analyzerManagerLogDirName = "analyzerManagerLogs"
jfUserEnvVariable = "JF_USER"
jfPasswordEnvVariable = "JF_PASS"
jfTokenEnvVariable = "JF_TOKEN"
jfPlatformUrlEnvVariable = "JF_PLATFORM_URL"
logDirEnvVariable = "AM_LOG_DIRECTORY"
notEntitledExitCode = 31
unsupportedCommandExitCode = 13
unsupportedOsExitCode = 55
ErrFailedScannerRun = "failed to run %s scan. Exit code received: %s"
EntitlementsMinVersion = "3.66.5"
ApplicabilityFeatureId = "contextual_analysis"
AnalyzerManagerZipName = "analyzerManager.zip"
defaultAnalyzerManagerVersion = "1.2.4.1953469"
minAnalyzerManagerVersionForSast = "1.3"
analyzerManagerDownloadPath = "xsc-gen-exe-analyzer-manager-local/v1"
analyzerManagerDirName = "analyzerManager"
analyzerManagerExecutableName = "analyzerManager"
analyzerManagerLogDirName = "analyzerManagerLogs"
jfUserEnvVariable = "JF_USER"
jfPasswordEnvVariable = "JF_PASS"
jfTokenEnvVariable = "JF_TOKEN"
jfPlatformUrlEnvVariable = "JF_PLATFORM_URL"
logDirEnvVariable = "AM_LOG_DIRECTORY"
notEntitledExitCode = 31
unsupportedCommandExitCode = 13
unsupportedOsExitCode = 55
ErrFailedScannerRun = "failed to run %s scan. Exit code received: %s"
jfrogCliAnalyzerManagerVersionEnvVariable = "JFROG_CLI_ANALYZER_MANAGER_VERSION"
)

type ApplicabilityStatus string
Expand Down Expand Up @@ -142,7 +144,18 @@ func GetAnalyzerManagerDownloadPath() (string, error) {
if err != nil {
return "", err
}
return path.Join(analyzerManagerDownloadPath, AnalyzerManagerVersion, osAndArc, AnalyzerManagerZipName), nil
return path.Join(analyzerManagerDownloadPath, GetAnalyzerManagerVersion(), osAndArc, AnalyzerManagerZipName), nil
}

func GetAnalyzerManagerVersion() string {
if analyzerManagerVersion, exists := os.LookupEnv(jfrogCliAnalyzerManagerVersionEnvVariable); exists {
return analyzerManagerVersion
}
return defaultAnalyzerManagerVersion
}

func IsSastSupported() bool {
return version.NewVersion(GetAnalyzerManagerVersion()).AtLeast(minAnalyzerManagerVersionForSast)
}

func GetAnalyzerManagerDirAbsolutePath() (string, error) {
Expand Down
3 changes: 1 addition & 2 deletions xray/utils/resultwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strconv"
"strings"

"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/formats"
clientUtils "github.com/jfrog/jfrog-client-go/utils"
Expand Down Expand Up @@ -114,7 +113,7 @@ func printScanResultsTables(results *ExtendedScanResults, isBinaryScan, includeV
if err = PrintIacTable(results.IacScanResults, results.EntitledForJas); err != nil {
return
}
if !version.NewVersion(AnalyzerManagerVersion).AtLeast(MinAnalyzerManagerVersionForSast) {
if !IsSastSupported() {
return
}
return PrintSastTable(results.SastResults, results.EntitledForJas)
Expand Down

0 comments on commit fd00f19

Please sign in to comment.