From 92104764c0e10c1d802a51f23c6c010fe77b0b59 Mon Sep 17 00:00:00 2001 From: Or Geva Date: Wed, 12 Jan 2022 23:14:25 -0800 Subject: [PATCH] Remove pointer from embedded checksum struct (#504) --- artifactory/services/download.go | 9 ++++++--- artifactory/services/upload.go | 12 +++++++----- artifactory/services/utils/resultutils.go | 17 ++++++---------- artifactory/services/utils/searchutil.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- tests/utils_test.go | 2 +- utils/io/fileutils/files.go | 24 ++++++++++------------- utils/utils.go | 9 ++------- 9 files changed, 37 insertions(+), 46 deletions(-) diff --git a/artifactory/services/download.go b/artifactory/services/download.go index 44a681789..c2501777a 100644 --- a/artifactory/services/download.go +++ b/artifactory/services/download.go @@ -1,14 +1,17 @@ package services import ( - biutils "github.com/jfrog/build-info-go/utils" - "github.com/jfrog/gofrog/version" "net/http" "os" "path" "path/filepath" "sort" + biutils "github.com/jfrog/build-info-go/utils" + "github.com/jfrog/gofrog/version" + + "github.com/jfrog/build-info-go/entities" + "github.com/jfrog/jfrog-client-go/http/httpclient" "github.com/jfrog/gofrog/parallel" @@ -344,7 +347,7 @@ func createDependencyTransferDetails(downloadPath, localPath, localFileName stri func createDependencyArtifactDetails(resultItem utils.ResultItem) utils.ArtifactDetails { fileInfo := utils.ArtifactDetails{ ArtifactoryPath: resultItem.GetItemRelativePath(), - Checksums: utils.Checksums{ + Checksums: entities.Checksum{ Sha1: resultItem.Actual_Sha1, Md5: resultItem.Actual_Md5, }, diff --git a/artifactory/services/upload.go b/artifactory/services/upload.go index accfda869..6ca78e80f 100644 --- a/artifactory/services/upload.go +++ b/artifactory/services/upload.go @@ -3,7 +3,6 @@ package services import ( "archive/zip" "fmt" - biutils "github.com/jfrog/build-info-go/utils" "io" "net/http" "os" @@ -13,6 +12,9 @@ import ( "strconv" "strings" + "github.com/jfrog/build-info-go/entities" + biutils "github.com/jfrog/build-info-go/utils" + "github.com/jfrog/gofrog/parallel" "github.com/jfrog/jfrog-client-go/artifactory/services/fspatterns" "github.com/jfrog/jfrog-client-go/artifactory/services/utils" @@ -911,7 +913,7 @@ func newResultManager() (*resultsManager, error) { } // Write a result of a successful upload -func (rm *resultsManager) addFinalResult(localPath, targetPath, targetUrl, sha256 string, checksums *fileutils.ChecksumDetails) { +func (rm *resultsManager) addFinalResult(localPath, targetPath, targetUrl, sha256 string, checksums *entities.Checksum) { fileTransferDetails := clientutils.FileTransferDetails{ SourcePath: localPath, TargetPath: targetUrl, @@ -920,7 +922,7 @@ func (rm *resultsManager) addFinalResult(localPath, targetPath, targetUrl, sha25 rm.singleFinalTransfersWriter.Write(fileTransferDetails) artifactDetails := utils.ArtifactDetails{ ArtifactoryPath: targetPath, - Checksums: utils.Checksums{ + Checksums: entities.Checksum{ Sha256: checksums.Sha256, Sha1: checksums.Sha1, Md5: checksums.Md5, @@ -947,7 +949,7 @@ func (rm *resultsManager) addNotFinalResult(localPath, targetUrl string) error { } // Mark all the transfers to a specific target as completed successfully -func (rm *resultsManager) finalizeResult(targetPath string, checksums *fileutils.ChecksumDetails) error { +func (rm *resultsManager) finalizeResult(targetPath string, checksums *entities.Checksum) error { writer := rm.notFinalTransfersWriters[targetPath] e := writer.Close() if e != nil { @@ -957,7 +959,7 @@ func (rm *resultsManager) finalizeResult(targetPath string, checksums *fileutils delete(rm.notFinalTransfersWriters, targetPath) artifactDetails := utils.ArtifactDetails{ ArtifactoryPath: targetPath, - Checksums: utils.Checksums{ + Checksums: entities.Checksum{ Sha256: checksums.Sha256, Sha1: checksums.Sha1, Md5: checksums.Md5, diff --git a/artifactory/services/utils/resultutils.go b/artifactory/services/utils/resultutils.go index 696672f7d..fdbeb77f5 100644 --- a/artifactory/services/utils/resultutils.go +++ b/artifactory/services/utils/resultutils.go @@ -1,10 +1,11 @@ package utils import ( + "strings" + buildinfo "github.com/jfrog/build-info-go/entities" "github.com/jfrog/jfrog-client-go/utils/io/content" "github.com/jfrog/jfrog-client-go/utils/io/fileutils" - "strings" ) type Result struct { @@ -36,8 +37,8 @@ type OperationSummary struct { type ArtifactDetails struct { // Path of the artifact in Artifactory - ArtifactoryPath string `json:"artifactoryPath,omitempty"` - Checksums Checksums `json:"checksums,omitempty"` + ArtifactoryPath string `json:"artifactoryPath,omitempty"` + Checksums buildinfo.Checksum `json:"checksums,omitempty"` } func (cs *OperationSummary) Close() error { @@ -49,7 +50,7 @@ func (cs *OperationSummary) Close() error { } func (ad *ArtifactDetails) ToBuildInfoArtifact() buildinfo.Artifact { - artifact := buildinfo.Artifact{Checksum: &buildinfo.Checksum{}} + artifact := buildinfo.Artifact{Checksum: buildinfo.Checksum{}} artifact.Sha1 = ad.Checksums.Sha1 artifact.Md5 = ad.Checksums.Md5 // Artifact name in build info as the name in artifactory @@ -63,7 +64,7 @@ func (ad *ArtifactDetails) ToBuildInfoArtifact() buildinfo.Artifact { } func (ad *ArtifactDetails) ToBuildInfoDependency() buildinfo.Dependency { - dependency := buildinfo.Dependency{Checksum: &buildinfo.Checksum{}} + dependency := buildinfo.Dependency{Checksum: buildinfo.Checksum{}} dependency.Sha1 = ad.Checksums.Sha1 dependency.Md5 = ad.Checksums.Md5 // Artifact name in build info as the name in artifactory @@ -87,9 +88,3 @@ func ConvertArtifactsDetailsToBuildInfoDependencies(artifactsDetailsReader *cont } return buildDependencies, artifactsDetailsReader.GetError() } - -type Checksums struct { - Sha256 string `json:"sha256,omitempty"` - Sha1 string `json:"sha1,omitempty"` - Md5 string `json:"md5,omitempty"` -} diff --git a/artifactory/services/utils/searchutil.go b/artifactory/services/utils/searchutil.go index febe99015..0e1e294b7 100644 --- a/artifactory/services/utils/searchutil.go +++ b/artifactory/services/utils/searchutil.go @@ -370,11 +370,11 @@ func addSeparator(str1, separator, str2 string) string { } func (item *ResultItem) ToArtifact() buildinfo.Artifact { - return buildinfo.Artifact{Name: item.Name, Checksum: &buildinfo.Checksum{Sha1: item.Actual_Sha1, Md5: item.Actual_Md5}, Path: path.Join(item.Path, item.Name)} + return buildinfo.Artifact{Name: item.Name, Checksum: buildinfo.Checksum{Sha1: item.Actual_Sha1, Md5: item.Actual_Md5}, Path: path.Join(item.Path, item.Name)} } func (item *ResultItem) ToDependency() buildinfo.Dependency { - return buildinfo.Dependency{Id: item.Name, Checksum: &buildinfo.Checksum{Sha1: item.Actual_Sha1, Md5: item.Actual_Md5}} + return buildinfo.Dependency{Id: item.Name, Checksum: buildinfo.Checksum{Sha1: item.Actual_Sha1, Md5: item.Actual_Md5}} } type AqlSearchResultItemFilter func(SearchBasedContentItem, *content.ContentReader) (*content.ContentReader, error) diff --git a/go.mod b/go.mod index d36c5ff76..e7c279f5c 100644 --- a/go.mod +++ b/go.mod @@ -56,6 +56,6 @@ exclude ( golang.org/x/text v0.3.4 ) -//replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v0.1.5-0.20211209071650-c5f4d2e581c3 +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.0.1-0.20220112142814-65cb52a6452a //replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.0.7-0.20211128152632-e218c460d703 diff --git a/go.sum b/go.sum index 94efff2f7..d0e61a5b1 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,8 @@ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= -github.com/jfrog/build-info-go v1.0.0 h1:4JsL8zfHDZqVpMwKICPY7qqyrqsFZzT0XzobI1Eu840= -github.com/jfrog/build-info-go v1.0.0/go.mod h1:QyeMfNGt4W0eWazrd7j6uZVN5KTpB05nxF/MwvGnTqs= +github.com/jfrog/build-info-go v1.0.1-0.20220112142814-65cb52a6452a h1:nrAWFSt+6JokebYeohWvZ6A/rbcy1IY5JOhwHkH/G6E= +github.com/jfrog/build-info-go v1.0.1-0.20220112142814-65cb52a6452a/go.mod h1:QyeMfNGt4W0eWazrd7j6uZVN5KTpB05nxF/MwvGnTqs= github.com/jfrog/gofrog v1.1.1 h1:uRjeZWidQl4FmKP4Zpj5hSKJp3gSIWW9VUwbQdVEVRU= github.com/jfrog/gofrog v1.1.1/go.mod h1:9YN5v4LlsCfLIXpwQnzSf1wVtgjdHM20FzuIu58RMI4= github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgyYSX4TO5NpyC606/Z4SxnNYbT+WX27or6Ck= diff --git a/tests/utils_test.go b/tests/utils_test.go index 1f6deb5ce..06fb8f32d 100644 --- a/tests/utils_test.go +++ b/tests/utils_test.go @@ -874,7 +874,7 @@ func createDummyBuild(buildName string) error { { Type: "gz", Name: "c.tar.gz", - Checksum: &buildinfo.Checksum{ + Checksum: buildinfo.Checksum{ Sha1: "9d4336ff7bc2d2348aee4e27ad55e42110df4a80", Md5: "b4918187cc9b3bf1b0772546d9398d7d", }, diff --git a/utils/io/fileutils/files.go b/utils/io/fileutils/files.go index 05367c4f3..965e241a6 100644 --- a/utils/io/fileutils/files.go +++ b/utils/io/fileutils/files.go @@ -5,7 +5,6 @@ import ( "bytes" "encoding/json" "errors" - biutils "github.com/jfrog/build-info-go/utils" "io" "io/ioutil" "net/url" @@ -15,6 +14,9 @@ import ( "reflect" "strings" + "github.com/jfrog/build-info-go/entities" + biutils "github.com/jfrog/build-info-go/utils" + "github.com/jfrog/jfrog-client-go/utils/errorutils" ) @@ -350,7 +352,7 @@ func GetFileDetails(filePath string, includeChecksums bool) (*FileDetails, error return details, err } } else { - details.Checksum = ChecksumDetails{} + details.Checksum = entities.Checksum{} } file, err := os.Open(filePath) @@ -366,11 +368,11 @@ func GetFileDetails(filePath string, includeChecksums bool) (*FileDetails, error return details, nil } -func calcChecksumDetails(filePath string) (ChecksumDetails, error) { +func calcChecksumDetails(filePath string) (entities.Checksum, error) { file, err := os.Open(filePath) defer file.Close() if errorutils.CheckError(err) != nil { - return ChecksumDetails{}, err + return entities.Checksum{}, err } return calcChecksumDetailsFromReader(file) } @@ -393,25 +395,19 @@ func GetFileDetailsFromReader(reader io.Reader, includeChecksusms bool) (*FileDe return details, err } -func calcChecksumDetailsFromReader(reader io.Reader) (ChecksumDetails, error) { +func calcChecksumDetailsFromReader(reader io.Reader) (entities.Checksum, error) { checksumInfo, err := biutils.CalcChecksums(reader) if err != nil { - return ChecksumDetails{}, errorutils.CheckError(err) + return entities.Checksum{}, errorutils.CheckError(err) } - return ChecksumDetails{Md5: checksumInfo[biutils.MD5], Sha1: checksumInfo[biutils.SHA1], Sha256: checksumInfo[biutils.SHA256]}, nil + return entities.Checksum{Md5: checksumInfo[biutils.MD5], Sha1: checksumInfo[biutils.SHA1], Sha256: checksumInfo[biutils.SHA256]}, nil } type FileDetails struct { - Checksum ChecksumDetails + Checksum entities.Checksum Size int64 } -type ChecksumDetails struct { - Md5 string - Sha1 string - Sha256 string -} - func CopyFile(dst, src string) error { srcFile, err := os.Open(src) if err != nil { diff --git a/utils/utils.go b/utils/utils.go index a0a779586..688b7bb68 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" + "github.com/jfrog/build-info-go/entities" "github.com/jfrog/gofrog/stringutils" "github.com/jfrog/jfrog-client-go/utils/io/fileutils" @@ -507,13 +508,7 @@ func (details *DeployableArtifactDetails) CreateFileTransferDetails(rtUrl, targe } type UploadResponseBody struct { - Checksums ChecksumDetails `json:"checksums,omitempty"` -} - -type ChecksumDetails struct { - Md5 string - Sha1 string - Sha256 string + Checksums entities.Checksum `json:"checksums,omitempty"` } func SaveFileTransferDetailsInTempFile(filesDetails *[]FileTransferDetails) (string, error) {