Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Audit command technology detection #910

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions utils/coreutils/techutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,11 @@ func detectTechnologiesByFilePaths(paths []string, isCiSetup bool) (detected map
return detected
}

// DetectTechnologiesToString returns a string that includes all the names of the detected technologies separated by a comma.
func DetectedTechnologiesToString(detected map[Technology]bool) string {
keys := DetectedTechnologiesToSlice(detected)
if len(keys) > 0 {
detectedTechnologiesString := strings.Join(keys, ", ")
detectedTechnologiesString += "."
return detectedTechnologiesString
}
return ""
}

// DetectedTechnologiesToSlice returns a string slice that includes all the names of the detected technologies.
func DetectedTechnologiesToSlice(detected map[Technology]bool) []string {
keys := make([]string, len(detected))
i := 0
keys := make([]string, 0, len(detected))
for tech := range detected {
keys[i] = string(tech)
i++
keys = append(keys, string(tech))
}
return keys
}
Expand Down
17 changes: 9 additions & 8 deletions xray/commands/audit/generic/auditmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,16 @@ func runScaScanOnWorkingDir(params *Params, results *Results, workingDir, rootDi
err = errors.Join(err, os.Chdir(rootDir))
}()

// If no technologies were given, try to detect all types of technologies used.
// Otherwise, run audit for requested technologies only.
technologies := params.Technologies()
if len(technologies) == 0 {
var technologies []string
requestedTechnologies := params.Technologies()
if len(requestedTechnologies) != 0 {
technologies = requestedTechnologies
} else {
technologies = commandsutils.DetectedTechnologies()
if len(technologies) == 0 {
log.Info("Skipping vulnerable dependencies scanning...")
return
}
}
if len(technologies) == 0 {
log.Info("Couldn't determine a package manager or build tool used by this project. Skipping the SCA scan...")
return
}
serverDetails, err := params.ServerDetails()
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions xray/commands/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/v2/xray/utils"
Expand All @@ -12,6 +13,7 @@ import (
"golang.org/x/text/cases"
"golang.org/x/text/language"
"os"
"strings"
)

const (
Expand Down Expand Up @@ -194,13 +196,12 @@ func DetectedTechnologies() (technologies []string) {
if err != nil {
return
}
detectedTechnologiesString := coreutils.DetectedTechnologiesToString(detectedTechnologies)
if detectedTechnologiesString == "" {
log.Info("Couldn't determine a package manager or build tool used by this project in the current path:", wd)
if len(detectedTechnologies) == 0 {
return
}
log.Info("Detected: " + detectedTechnologiesString)
return coreutils.DetectedTechnologiesToSlice(detectedTechnologies)
techStringsList := coreutils.DetectedTechnologiesToSlice(detectedTechnologies)
log.Info(fmt.Sprintf("Detected: %s." + strings.Join(techStringsList, ",")))
return techStringsList
}

func DetectNumOfThreads(threadsCount int) (int, error) {
Expand Down
Loading