Skip to content

Commit

Permalink
Fix CR
Browse files Browse the repository at this point in the history
  • Loading branch information
asafambar committed Mar 13, 2024
1 parent d33ed32 commit d35e85e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
35 changes: 18 additions & 17 deletions commands/audit/scarunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ func getDirectDependenciesFromTree(dependencyTrees []*xrayCmdUtils.GraphNode) []

func getCurationCacheByTech(tech coreutils.Technology) (string, error) {
if tech == coreutils.Maven {
return xrayutils.GetCurationMavenCacheFolder(true)
return xrayutils.GetCurationMavenCacheFolder()
}
return "", nil
}

func GetTechDependencyTree(params xrayutils.AuditParams, tech coreutils.Technology) (flatTree *xrayCmdUtils.GraphNode, fullDependencyTrees []*xrayCmdUtils.GraphNode, err error) {
logMessage := fmt.Sprintf("Calculating %s dependencies", tech.ToFormal())
// in case it's not curation command these params will be empty
curationLogMsg, curationCacheFolder, err := getCurationCacheFolderAndLogMsg(params, tech)
if err != nil {
return
}
// In case it's not curation command these 'curationLogMsg' be empty
logMessage += curationLogMsg
log.Info(logMessage + "...")
if params.Progress() != nil {
Expand Down Expand Up @@ -248,25 +248,26 @@ func GetTechDependencyTree(params xrayutils.AuditParams, tech coreutils.Technolo
}

func getCurationCacheFolderAndLogMsg(params xrayutils.AuditParams, tech coreutils.Technology) (logMessage string, curationCacheFolder string, err error) {
if params.IsCurationCmd() {
curationCacheFolder, err = getCurationCacheByTech(tech)
if err != nil {
return logMessage, curationCacheFolder, err
}
if !params.IsCurationCmd() {
return
}
if curationCacheFolder, err = getCurationCacheByTech(tech); err != nil {
return
}

if isExist, err := fileutils.IsDirExists(curationCacheFolder, false); isExist {
if isEmpty, err := fileutils.IsDirEmpty(curationCacheFolder); !isEmpty {
return logMessage, curationCacheFolder, err
} else if err != nil {
return logMessage, curationCacheFolder, err
}
} else if err != nil {
return logMessage, curationCacheFolder, err
dirExist, err := fileutils.IsDirExists(curationCacheFolder, false)
if err != nil {
return
}

if dirExist {
if dirIsEmpty, err := fileutils.IsDirEmpty(curationCacheFolder); err != nil || !dirIsEmpty {

Check failure on line 264 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Static-Check

inner declaration of var err error) (typecheck)

Check failure on line 264 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Static-Check

inner declaration of var err error (typecheck)

Check failure on line 264 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Static-Check

inner declaration of var err error) (typecheck)

Check failure on line 264 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Go-Sec

inner declaration of var err error

Check failure on line 264 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Go-Sec

inner declaration of var err error

Check failure on line 264 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / test (ubuntu)

inner declaration of var err error

Check failure on line 264 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / test (windows)

inner declaration of var err error

Check failure on line 264 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / test (macos)

inner declaration of var err error
return

Check failure on line 265 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Static-Check

result parameter err not in scope at return

Check failure on line 265 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Static-Check

result parameter err not in scope at return

Check failure on line 265 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Static-Check

result parameter err not in scope at return

Check failure on line 265 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Go-Sec

result parameter err not in scope at return

Check failure on line 265 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / Go-Sec

result parameter err not in scope at return

Check failure on line 265 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / test (ubuntu)

result parameter err not in scope at return

Check failure on line 265 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / test (windows)

result parameter err not in scope at return

Check failure on line 265 in commands/audit/scarunner.go

View workflow job for this annotation

GitHub Actions / test (macos)

result parameter err not in scope at return
}
}

logMessage = ". Project's cache is currently empty, so this run may take longer to complete"
logMessage = ". Project's cache is currently empty, so this run may take longer to complete"

}
return logMessage, curationCacheFolder, err
}

Expand Down
2 changes: 1 addition & 1 deletion commands/curation/curationaudit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func getTestCasesForDoCurationAudit() []testCase {
assert.NoError(t, err)
// set the cache to test project dir, in order to fill its cache with dependencies
callbackPreTest := clienttestutils.ChangeDirWithCallback(t, rootDir, filepath.Join("..", "test"))
curationCache, err := utils.GetCurationMavenCacheFolder(true)
curationCache, err := utils.GetCurationMavenCacheFolder()
callbackPreTest()
require.NoError(t, err)
return []string{"com.jfrog:maven-dep-tree:tree", "-DdepsTreeOutputFile=output", "-Dmaven.repo.local=" + curationCache}
Expand Down
27 changes: 12 additions & 15 deletions utils/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,21 @@ func GetCurationCacheFolder() (string, error) {
return filepath.Join(curationFolder, "cache"), nil
}

func GetCurationMavenCacheFolder(withProjectDir bool) (string, error) {
func GetCurationMavenCacheFolder() (projectDir string, err error) {
curationFolder, err := GetCurationCacheFolder()
if err != nil {
return "", err
}
projectDir := ""
if withProjectDir {
workingDir, err := os.Getwd()
if err != nil {
return "", err
}
// #nosec G401 -- Not a secret hash.
hasher := sha1.New()
_, err = hasher.Write([]byte(workingDir))
if err != nil {
return "", err
}
projectDir = hex.EncodeToString(hasher.Sum(nil))
workingDir, err := os.Getwd()
if err != nil {
return "", err
}
// #nosec G401 -- Not a secret hash.
hasher := sha1.New()
_, err = hasher.Write([]byte(workingDir))
if err != nil {
return "", err
}
return filepath.Join(curationFolder, "maven", projectDir), nil
projectDir = filepath.Join(curationFolder, "maven", hex.EncodeToString(hasher.Sum(nil)))
return
}

0 comments on commit d35e85e

Please sign in to comment.