diff --git a/artifactory/commands/golang/go.go b/artifactory/commands/golang/go.go index 6395c5b0c..93ce330e0 100644 --- a/artifactory/commands/golang/go.go +++ b/artifactory/commands/golang/go.go @@ -16,9 +16,7 @@ import ( "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/jfrog/jfrog-client-go/utils/io/fileutils" "github.com/jfrog/jfrog-client-go/utils/log" - "io/fs" "net/http" - "os" "path" "path/filepath" "strings" @@ -221,16 +219,7 @@ func copyGoPackageFiles(destPath, packageName, rtTargetRepo string, authArtDetai return fmt.Errorf("couldn't find suitable package files: %s", packageFilesPath) } // Set permission recursively - return filepath.WalkDir(destPath, func(path string, info fs.DirEntry, err error) error { - if err != nil { - return err - } - err = os.Chmod(path, 0700) - if err != nil { - return err - } - return nil - }) + return coreutils.SetPermissionsRecursively(destPath, 0700) } // getPackageFilePathFromArtifactory returns a string that represents the package files cache path. diff --git a/artifactory/utils/dependenciesutils.go b/artifactory/utils/dependenciesutils.go index 790fd01fe..9591c532b 100644 --- a/artifactory/utils/dependenciesutils.go +++ b/artifactory/utils/dependenciesutils.go @@ -57,7 +57,7 @@ func DownloadAnalyzerManagerIfNeeded() error { downloadUrl := artDetails.ArtifactoryUrl + remotePath remoteFileDetails, _, err := client.GetRemoteFileDetails(downloadUrl, &httpClientDetails) if err != nil { - return err + return errors.New("couldn't get remote file details for " + downloadUrl) } analyzerManagerDir, err := xrayutils.GetAnalyzerManagerDirAbsolutePath() if err != nil { @@ -70,7 +70,8 @@ func DownloadAnalyzerManagerIfNeeded() error { return err } if exist { - sha2, err := fileutils.ReadFile(checksumFilePath) + var sha2 []byte + sha2, err = fileutils.ReadFile(checksumFilePath) if err != nil { return err } @@ -84,17 +85,6 @@ func DownloadAnalyzerManagerIfNeeded() error { if err = DownloadDependency(artDetails, remotePath, filepath.Join(analyzerManagerDir, xrayutils.AnalyzerManagerZipName), true); err != nil { return err } - // Add permission for all unzipped files - filesList, err := fileutils.ListFilesRecursiveWalkIntoDirSymlink(analyzerManagerDir, false) - if err != nil { - return err - } - for _, file := range filesList { - if err = os.Chmod(file, 0777); err != nil { - return errorutils.CheckError(err) - } - } - return createChecksumFile(checksumFilePath, remoteFileDetails.Checksum.Sha256) } @@ -219,9 +209,13 @@ func DownloadDependency(artDetails *config.ServerDetails, downloadPath, targetPa return err } resp, err := client.DownloadFile(downloadFileDetails, "", &httpClientDetails, shouldExplode, false) - if err == nil && resp.StatusCode != http.StatusOK { - err = errorutils.CheckErrorf(resp.Status + " received when attempting to download " + downloadUrl) + if err != nil { + err = errorutils.CheckErrorf("received error while attempting to download '%s': %s"+downloadUrl, err.Error()) + } + if err = errorutils.CheckResponseStatus(resp, http.StatusOK); err != nil { + return err } + err = coreutils.SetPermissionsRecursively(tempDirPath, 0700) if err != nil { return err } diff --git a/utils/coreutils/techutils.go b/utils/coreutils/techutils.go index bba09ba3f..26a11eeed 100644 --- a/utils/coreutils/techutils.go +++ b/utils/coreutils/techutils.go @@ -189,7 +189,7 @@ func DetectedTechnologiesList() (technologies []string) { return } techStringsList := DetectedTechnologiesToSlice(detectedTechnologies) - log.Info(fmt.Sprintf("Detected: %s.", strings.Join(techStringsList, ","))) + log.Info(fmt.Sprintf("Detected: %s.", strings.Join(techStringsList, ", "))) return techStringsList } diff --git a/utils/coreutils/utils.go b/utils/coreutils/utils.go index 15bb5809f..463a65d50 100644 --- a/utils/coreutils/utils.go +++ b/utils/coreutils/utils.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "io/fs" "os" "os/exec" "path/filepath" @@ -599,3 +600,20 @@ func GetMaskedCommandString(cmd *exec.Cmd) string { } return cmdString } + +func SetPermissionsRecursively(dirPath string, mode os.FileMode) error { + err := filepath.WalkDir(dirPath, func(path string, info fs.DirEntry, e error) error { + if e != nil { + return e + } + e = os.Chmod(path, mode) + if e != nil { + return e + } + return nil + }) + if err != nil { + return errorutils.CheckErrorf("failed while setting permission to '%s' files: %s", dirPath, err.Error()) + } + return nil +} diff --git a/xray/commands/audit/audit.go b/xray/commands/audit/audit.go index 285703371..41eca4ae7 100644 --- a/xray/commands/audit/audit.go +++ b/xray/commands/audit/audit.go @@ -181,7 +181,7 @@ func RunAudit(auditParams *AuditParams) (results *Results, err error) { // Wait for the Download of the AnalyzerManager to complete. if err = errGroup.Wait(); err != nil { - return + err = errors.New("failed while trying to get Analyzer Manager: " + err.Error()) } // Run scanners only if the user is entitled for Advanced Security diff --git a/xray/utils/analyzermanager.go b/xray/utils/analyzermanager.go index 70400d80e..51087cae5 100644 --- a/xray/utils/analyzermanager.go +++ b/xray/utils/analyzermanager.go @@ -122,7 +122,7 @@ func GetAnalyzerManagerDownloadPath() (string, error) { } func GetAnalyzerManagerVersion() string { - if analyzerManagerVersion, exists := os.LookupEnv(jfrogCliAnalyzerManagerVersionEnvVariable); exists { + if analyzerManagerVersion := os.Getenv(jfrogCliAnalyzerManagerVersionEnvVariable); analyzerManagerVersion != "" { return analyzerManagerVersion } return defaultAnalyzerManagerVersion