From 01bb7dcd43fc42436689fd23893b2a8595c00ac3 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Tue, 6 Aug 2024 19:24:39 +0300 Subject: [PATCH 1/4] Unite http content type header code (#996) --- access/services/accesstoken.go | 3 +- access/services/invite.go | 3 +- access/services/login.go | 3 +- artifactory/services/discardBuilds.go | 3 +- artifactory/services/distribute.go | 3 +- artifactory/services/dockerpromote.go | 3 +- artifactory/services/export.go | 3 +- artifactory/services/federation.go | 7 ++-- artifactory/services/permissiontarget.go | 4 +- artifactory/services/props.go | 2 - artifactory/services/repository.go | 3 +- artifactory/services/upload.go | 4 +- .../services/utils/artifactoryutils.go | 14 ++++--- artifactory/services/xrayscan.go | 2 +- artifactory/usage/reportusage.go | 3 +- distribution/services/create.go | 3 +- distribution/services/deletelocal.go | 3 +- distribution/services/deleteremote.go | 3 +- distribution/services/setsigningkey.go | 3 +- distribution/services/sign.go | 3 +- distribution/services/update.go | 3 +- evidence/services/operation.go | 3 +- lifecycle/services/delete.go | 3 +- lifecycle/services/operation.go | 2 +- pipelines/services/run.go | 5 +-- tests/utils_test.go | 4 +- utils/distribution/distribute.go | 3 +- utils/io/content/contentreader.go | 2 +- utils/io/content/contentwriter.go | 4 +- utils/io/httputils/httpclient.go | 37 ++++++++++++------- xray/services/binMgr.go | 3 +- xray/services/buildscan.go | 5 +-- xray/services/enrich.go | 4 +- xray/services/ignorerule.go | 5 +-- xray/services/policy.go | 7 ++-- xray/services/report.go | 9 ++--- xray/services/scan.go | 7 ++-- xray/services/summary.go | 4 +- xray/services/watch.go | 5 +-- xray/usage/reportusage.go | 3 +- 40 files changed, 86 insertions(+), 107 deletions(-) diff --git a/access/services/accesstoken.go b/access/services/accesstoken.go index 8659701a6..65d3b15cc 100644 --- a/access/services/accesstoken.go +++ b/access/services/accesstoken.go @@ -3,7 +3,6 @@ package services import ( "encoding/json" "fmt" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" clientutils "github.com/jfrog/jfrog-client-go/utils" @@ -51,7 +50,7 @@ func (ps *TokenService) RefreshAccessToken(params CreateTokenParams) (auth.Creat // createAccessToken is used to create & refresh access tokens. func (ps *TokenService) createAccessToken(params CreateTokenParams) (tokenInfo auth.CreateTokenResponseData, err error) { httpDetails := ps.ServiceDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpDetails.Headers) + httpDetails.SetContentTypeApplicationJson() if err = ps.handleUnauthenticated(params, &httpDetails); err != nil { return tokenInfo, err } diff --git a/access/services/invite.go b/access/services/invite.go index 7f5a651d8..9e7f2e1f8 100644 --- a/access/services/invite.go +++ b/access/services/invite.go @@ -3,7 +3,6 @@ package services import ( "encoding/json" "fmt" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -40,7 +39,7 @@ func (us *InviteService) InviteUser(email, source string) error { if err != nil { return errorutils.CheckError(err) } - utils.SetContentType("application/json", &httpDetails.Headers) + httpDetails.SetContentTypeApplicationJson() resp, body, err := us.client.SendPost(url, requestContent, &httpDetails) if err != nil { return err diff --git a/access/services/login.go b/access/services/login.go index 5dd9fdbf1..6fa0fe4fe 100644 --- a/access/services/login.go +++ b/access/services/login.go @@ -6,7 +6,6 @@ import ( "path" "time" - artifactoryutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils" @@ -51,7 +50,7 @@ func (ls *LoginService) SendLoginAuthenticationRequest(uuid string) error { return errorutils.CheckError(err) } httpClientsDetails := ls.ServiceDetails.CreateHttpClientDetails() - artifactoryutils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := ls.client.SendPost(fullUrl, requestContent, &httpClientsDetails) if err != nil { return err diff --git a/artifactory/services/discardBuilds.go b/artifactory/services/discardBuilds.go index 7a4085d3a..88cd2226d 100644 --- a/artifactory/services/discardBuilds.go +++ b/artifactory/services/discardBuilds.go @@ -10,7 +10,6 @@ import ( buildinfo "github.com/jfrog/build-info-go/entities" - artifactoryutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils" @@ -65,7 +64,7 @@ func (ds *DiscardBuildsService) DiscardBuilds(params DiscardBuildsParams) error } httpClientsDetails := ds.getArtifactoryDetails().CreateHttpClientDetails() - artifactoryutils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := ds.client.SendPost(requestFullUrl, requestContent, &httpClientsDetails) if err != nil { diff --git a/artifactory/services/distribute.go b/artifactory/services/distribute.go index e0dd48d6b..375381aac 100644 --- a/artifactory/services/distribute.go +++ b/artifactory/services/distribute.go @@ -6,7 +6,6 @@ import ( "path" "strings" - artifactoryutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils" @@ -71,7 +70,7 @@ func (ds *DistributeService) BuildDistribute(params BuildDistributionParams) err } httpClientsDetails := ds.getArtifactoryDetails().CreateHttpClientDetails() - artifactoryutils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := ds.client.SendPost(requestFullUrl, requestContent, &httpClientsDetails) if err != nil { diff --git a/artifactory/services/dockerpromote.go b/artifactory/services/dockerpromote.go index e51a573bd..eaa17cd5c 100644 --- a/artifactory/services/dockerpromote.go +++ b/artifactory/services/dockerpromote.go @@ -5,7 +5,6 @@ import ( "net/http" "path" - artifactoryutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils" @@ -58,7 +57,7 @@ func (ps *DockerPromoteService) PromoteDocker(params DockerPromoteParams) error // Send POST request httpClientsDetails := ps.GetArtifactoryDetails().CreateHttpClientDetails() - artifactoryutils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := ps.client.SendPost(url, requestContent, &httpClientsDetails) if err != nil { return err diff --git a/artifactory/services/export.go b/artifactory/services/export.go index 6995bb015..4c45b07ac 100644 --- a/artifactory/services/export.go +++ b/artifactory/services/export.go @@ -4,7 +4,6 @@ import ( "encoding/json" "net/http" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" clientutils "github.com/jfrog/jfrog-client-go/utils" @@ -42,7 +41,7 @@ func (drs *ExportService) Export(exportParams ExportParams) error { } log.Info(exportMessage) - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := drs.client.SendPost(drs.artDetails.GetUrl()+"api/export/system", requestContent, &httpClientsDetails) if err != nil { return err diff --git a/artifactory/services/federation.go b/artifactory/services/federation.go index 5373d8641..4c43baea4 100644 --- a/artifactory/services/federation.go +++ b/artifactory/services/federation.go @@ -4,7 +4,6 @@ import ( "net/http" "net/url" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -26,7 +25,7 @@ func (fs *FederationService) SetArtifactoryDetails(rt auth.ServiceDetails) { func (fs *FederationService) ConvertLocalToFederated(repoKey string) error { httpClientsDetails := fs.ArtDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = fs.ArtDetails.GetUrl() + "api/federation/migrate/" + url.PathEscape(repoKey) log.Info("Converting local repository to federated repository...") resp, body, err := fs.client.SendPost(url, nil, &httpClientsDetails) @@ -43,7 +42,7 @@ func (fs *FederationService) ConvertLocalToFederated(repoKey string) error { func (fs *FederationService) TriggerFederatedFullSyncAll(repoKey string) error { httpClientsDetails := fs.ArtDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = fs.ArtDetails.GetUrl() + "api/federation/fullSync/" + url.PathEscape(repoKey) log.Info("Triggering full federated repository synchronisation...") resp, body, err := fs.client.SendPost(url, nil, &httpClientsDetails) @@ -60,7 +59,7 @@ func (fs *FederationService) TriggerFederatedFullSyncAll(repoKey string) error { func (fs *FederationService) TriggerFederatedFullSyncMirror(repoKey string, mirrorUrl string) error { httpClientsDetails := fs.ArtDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = fs.ArtDetails.GetUrl() + "api/federation/fullSync/" + url.PathEscape(repoKey) + "?mirror=" + url.QueryEscape(mirrorUrl) log.Info("Triggering federated repository synchronisation...") resp, body, err := fs.client.SendPost(url, nil, &httpClientsDetails) diff --git a/artifactory/services/permissiontarget.go b/artifactory/services/permissiontarget.go index 1ad5e57f2..ac1eb3bb4 100644 --- a/artifactory/services/permissiontarget.go +++ b/artifactory/services/permissiontarget.go @@ -4,8 +4,6 @@ import ( "encoding/json" "net/http" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" - "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -78,7 +76,7 @@ func (pts *PermissionTargetService) performRequest(params PermissionTargetParams return errorutils.CheckError(err) } httpClientsDetails := pts.ArtDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = pts.ArtDetails.GetUrl() + "api/v2/security/permissions/" + params.Name var operationString string var resp *http.Response diff --git a/artifactory/services/props.go b/artifactory/services/props.go index 54c94b190..2cc06822b 100644 --- a/artifactory/services/props.go +++ b/artifactory/services/props.go @@ -146,7 +146,6 @@ func (ps *PropsService) performRequest(propsParams PropsParams, isDelete bool) ( func (ps *PropsService) sendDeleteRequest(logMsgPrefix, relativePath, setPropertiesUrl string) (resp *http.Response, body []byte, err error) { log.Info(logMsgPrefix+"Deleting properties on:", relativePath) - log.Debug(logMsgPrefix+"Sending delete properties request:", setPropertiesUrl) httpClientsDetails := ps.GetArtifactoryDetails().CreateHttpClientDetails() resp, body, err = ps.client.SendDelete(setPropertiesUrl, nil, &httpClientsDetails) return @@ -154,7 +153,6 @@ func (ps *PropsService) sendDeleteRequest(logMsgPrefix, relativePath, setPropert func (ps *PropsService) sendPutRequest(logMsgPrefix, relativePath, setPropertiesUrl string) (resp *http.Response, body []byte, err error) { log.Info(logMsgPrefix+"Setting properties on:", relativePath) - log.Debug(logMsgPrefix+"Sending set properties request:", setPropertiesUrl) httpClientsDetails := ps.GetArtifactoryDetails().CreateHttpClientDetails() resp, body, err = ps.client.SendPut(setPropertiesUrl, nil, &httpClientsDetails) return diff --git a/artifactory/services/repository.go b/artifactory/services/repository.go index eb7e84702..42aff5ee6 100644 --- a/artifactory/services/repository.go +++ b/artifactory/services/repository.go @@ -5,7 +5,6 @@ import ( "net/http" "net/url" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -32,7 +31,7 @@ func (rs *RepositoryService) performRequest(params interface{}, repoKey string) return err } httpClientsDetails := rs.ArtDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = rs.ArtDetails.GetUrl() + "api/repositories/" + url.PathEscape(repoKey) var operationString string var resp *http.Response diff --git a/artifactory/services/upload.go b/artifactory/services/upload.go index 7c64a0db9..b279a6f35 100644 --- a/artifactory/services/upload.go +++ b/artifactory/services/upload.go @@ -679,14 +679,14 @@ func logUploadResponse(logMsgPrefix string, resp *http.Response, body []byte, ch func addExplodeHeader(httpClientsDetails *httputils.HttpClientDetails, isExplode bool) { if isExplode { - utils.AddHeader("X-Explode-Archive", "true", &httpClientsDetails.Headers) + httpClientsDetails.AddHeader("X-Explode-Archive", "true") } } func (us *UploadService) doChecksumDeploy(details *fileutils.FileDetails, targetPath string, httpClientsDetails httputils.HttpClientDetails, client *jfroghttpclient.JfrogHttpClient) (resp *http.Response, body []byte, err error) { requestClientDetails := httpClientsDetails.Clone() - utils.AddHeader("X-Checksum-Deploy", "true", &requestClientDetails.Headers) + httpClientsDetails.AddHeader("X-Checksum-Deploy", "true") utils.AddChecksumHeaders(requestClientDetails.Headers, details) utils.AddAuthHeaders(requestClientDetails.Headers, us.ArtDetails) diff --git a/artifactory/services/utils/artifactoryutils.go b/artifactory/services/utils/artifactoryutils.go index c294f184c..50bcbef7b 100644 --- a/artifactory/services/utils/artifactoryutils.go +++ b/artifactory/services/utils/artifactoryutils.go @@ -114,7 +114,7 @@ func GetProjectQueryParam(projectKey string) string { } // paths - Sorted array. -// index - Index of the current path which we want to check if it a prefix of any of the other previous paths. +// index - Index of the current path which we want to check if it is a prefix of any of the other previous paths. // separator - File separator. // Returns true paths[index] is a prefix of any of the paths[i] where i= 1; i-- { @@ -379,7 +379,7 @@ func loadMissingProperties(reader *content.ContentReader, readerWithProps *conte return nil, err } reader.Reset() - if err := updateProps(readerWithProps, resultFile, buffer, writeOrder); err != nil { + if err = updateProps(readerWithProps, resultFile, buffer, writeOrder); err != nil { return nil, err } return content.NewContentReader(resultFile.GetFilePath(), content.DefaultKey), nil @@ -387,7 +387,7 @@ func loadMissingProperties(reader *content.ContentReader, readerWithProps *conte // Load the properties from readerWithProps into buffer's ResultItem and write its values into the resultWriter. // buffer - Search result buffer Key -> relative path, value -> ResultItem. We use this to load the props into the item by matching the uniqueness of relevant path. -// crWithProps - File containing all the results with proprties. +// crWithProps - File containing all the results with properties. // writeOrder - List of sorted buffer's searchResults(Map is an unordered collection). // resultWriter - Search results (sorted) with props. func updateProps(readerWithProps *content.ContentReader, resultWriter *content.ContentWriter, buffer map[string]*ResultItem, writeOrder []*ResultItem) error { @@ -413,13 +413,15 @@ func updateProps(readerWithProps *content.ContentReader, resultWriter *content.C // Run AQL to retrieve artifacts or dependencies which are associated with a specific build. // Return a map of the items' SHA1. -func fetchBuildArtifactsOrDependenciesSha1(flags CommonConf, artifacts bool, builds []Build) (map[string]int, error) { +func fetchBuildArtifactsOrDependenciesSha1(flags CommonConf, artifacts bool, builds []Build) (buildArtifactsSha1 map[string]int, err error) { buildQuery := createAqlQueryForBuild(buildIncludeQueryPart([]string{"name", "repo", "path", "actual_sha1"}), artifacts, builds) reader, err := aqlSearch(buildQuery, flags) if err != nil { return nil, err } - defer reader.Close() + defer func() { + err = errors.Join(err, reader.Close()) + }() return extractSha1FromAqlResponse(reader) } diff --git a/artifactory/services/xrayscan.go b/artifactory/services/xrayscan.go index 99542adbe..29fe32efe 100644 --- a/artifactory/services/xrayscan.go +++ b/artifactory/services/xrayscan.go @@ -106,7 +106,7 @@ func checkForXrayResponseError(content []byte, ignoreFatalError bool) error { func (ps *XrayScanService) execScanRequest(url string, content []byte) (*http.Response, error) { httpClientsDetails := ps.ArtDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() // The scan build operation can take a long time to finish. // To keep the connection open, when Xray starts scanning the build, it starts sending new-lines diff --git a/artifactory/usage/reportusage.go b/artifactory/usage/reportusage.go index 2d4c14074..7ecb32a25 100644 --- a/artifactory/usage/reportusage.go +++ b/artifactory/usage/reportusage.go @@ -6,7 +6,6 @@ import ( "net/http" "github.com/jfrog/jfrog-client-go/artifactory" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" clientutils "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/jfrog/jfrog-client-go/utils/io/httputils" @@ -52,7 +51,7 @@ func validateAndGetUsageServerInfo(serviceManager artifactory.ArtifactoryService } func sendReport(url string, serviceManager artifactory.ArtifactoryServicesManager, clientDetails httputils.HttpClientDetails, bodyContent []byte) error { - utils.AddHeader("Content-Type", "application/json", &clientDetails.Headers) + clientDetails.SetContentTypeApplicationJson() resp, body, err := serviceManager.Client().SendPost(url, bodyContent, &clientDetails) if err != nil { return errors.New("Couldn't send usage info. Error: " + err.Error()) diff --git a/distribution/services/create.go b/distribution/services/create.go index 47e08471f..32777ba32 100644 --- a/distribution/services/create.go +++ b/distribution/services/create.go @@ -2,7 +2,6 @@ package services import ( "encoding/json" - artifactoryUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" distributionServiceUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" @@ -59,7 +58,7 @@ func (cb *CreateReleaseBundleService) execCreateReleaseBundle(gpgPassphrase stri url := cb.DistDetails.GetUrl() + "api/v1/release_bundle" distributionServiceUtils.AddGpgPassphraseHeader(gpgPassphrase, &httpClientsDetails.Headers) - artifactoryUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := cb.client.SendPost(url, content, &httpClientsDetails) if err != nil { return summary, err diff --git a/distribution/services/deletelocal.go b/distribution/services/deletelocal.go index ecdd5b622..57ee8b753 100644 --- a/distribution/services/deletelocal.go +++ b/distribution/services/deletelocal.go @@ -3,7 +3,6 @@ package services import ( "net/http" - artifactoryUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -37,7 +36,7 @@ func (dlr *DeleteLocalReleaseBundleService) execDeleteLocalDistribution(name, ve log.Info("Deleting release bundle:", name, version) httpClientsDetails := dlr.DistDetails.CreateHttpClientDetails() url := dlr.DistDetails.GetUrl() + "api/v1/release_bundle/" + name + "/" + version - artifactoryUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := dlr.client.SendDelete(url, nil, &httpClientsDetails) if err != nil { return err diff --git a/distribution/services/deleteremote.go b/distribution/services/deleteremote.go index 90007c345..9845ae9fc 100644 --- a/distribution/services/deleteremote.go +++ b/distribution/services/deleteremote.go @@ -3,7 +3,6 @@ package services import ( "encoding/json" "fmt" - artifactoryUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils" @@ -86,7 +85,7 @@ func (dr *DeleteReleaseBundleService) execDeleteDistribute(name, version string, return errorutils.CheckError(err) } url := dr.DistDetails.GetUrl() + "api/v1/distribution/" + name + "/" + version + "/delete" - artifactoryUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := dr.client.SendPost(url, content, &httpClientsDetails) if err != nil { return err diff --git a/distribution/services/setsigningkey.go b/distribution/services/setsigningkey.go index e87854960..54b5f3c48 100644 --- a/distribution/services/setsigningkey.go +++ b/distribution/services/setsigningkey.go @@ -4,7 +4,6 @@ import ( "encoding/json" "net/http" - artifactoryUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils" @@ -40,7 +39,7 @@ func (ssk *SetSigningKeyService) execSetSigningKey(setSigningKeyBody *SetSigning return errorutils.CheckError(err) } url := ssk.DistDetails.GetUrl() + "/api/v1/keys/pgp" - artifactoryUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := ssk.client.SendPut(url, content, &httpClientsDetails) if err != nil { return err diff --git a/distribution/services/sign.go b/distribution/services/sign.go index df129c92b..1d30c042c 100644 --- a/distribution/services/sign.go +++ b/distribution/services/sign.go @@ -2,7 +2,6 @@ package services import ( "encoding/json" - artifactoryUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" distributionServiceUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" @@ -40,7 +39,7 @@ func (sb *SignBundleService) execSignReleaseBundle(name, version, gpgPassphrase return summary, errorutils.CheckError(err) } url := sb.DistDetails.GetUrl() + "api/v1/release_bundle/" + name + "/" + version + "/sign" - artifactoryUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() distributionServiceUtils.AddGpgPassphraseHeader(gpgPassphrase, &httpClientsDetails.Headers) resp, body, err := sb.client.SendPost(url, content, &httpClientsDetails) if err != nil { diff --git a/distribution/services/update.go b/distribution/services/update.go index 04dd8cf20..2c7bdf3f2 100644 --- a/distribution/services/update.go +++ b/distribution/services/update.go @@ -2,7 +2,6 @@ package services import ( "encoding/json" - artifactoryUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" distributionServiceUtils "github.com/jfrog/jfrog-client-go/distribution/services/utils" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" @@ -55,7 +54,7 @@ func (ur *UpdateReleaseBundleService) execUpdateReleaseBundle(name, version, gpg url := ur.DistDetails.GetUrl() + "api/v1/release_bundle/" + name + "/" + version distributionServiceUtils.AddGpgPassphraseHeader(gpgPassphrase, &httpClientsDetails.Headers) - artifactoryUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := ur.client.SendPut(url, content, &httpClientsDetails) if err != nil { return summary, err diff --git a/evidence/services/operation.go b/evidence/services/operation.go index c59beff12..f7f94d559 100644 --- a/evidence/services/operation.go +++ b/evidence/services/operation.go @@ -1,7 +1,6 @@ package services import ( - rtUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -35,7 +34,7 @@ func (es *EvidenceService) doOperation(operation EvidenceOperation) ([]byte, err } httpClientDetails := es.GetEvidenceDetails().CreateHttpClientDetails() - rtUtils.SetContentType("application/json", &httpClientDetails.Headers) + httpClientDetails.SetContentTypeApplicationJson() resp, body, err := es.client.SendPost(requestFullUrl.String(), operation.getRequestBody(), &httpClientDetails) if err != nil { diff --git a/lifecycle/services/delete.go b/lifecycle/services/delete.go index 054ef13db..1384dfa28 100644 --- a/lifecycle/services/delete.go +++ b/lifecycle/services/delete.go @@ -3,7 +3,6 @@ package services import ( "encoding/json" "fmt" - rtUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/distribution" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -67,7 +66,7 @@ func (rbs *ReleaseBundlesService) RemoteDeleteReleaseBundle(rbDetails ReleaseBun } httpClientDetails := rbs.GetLifecycleDetails().CreateHttpClientDetails() - rtUtils.SetContentType("application/json", &httpClientDetails.Headers) + httpClientDetails.SetContentTypeApplicationJson() resp, body, err := rbs.client.SendPost(requestFullUrl, content, &httpClientDetails) if err != nil { return err diff --git a/lifecycle/services/operation.go b/lifecycle/services/operation.go index e37fc1279..13e88ca34 100644 --- a/lifecycle/services/operation.go +++ b/lifecycle/services/operation.go @@ -78,7 +78,7 @@ func prepareRequest(operation ReleaseBundleOperation, rbs *ReleaseBundlesService } httpClientDetails = rbs.GetLifecycleDetails().CreateHttpClientDetails() rtUtils.AddSigningKeyNameHeader(operation.getSigningKeyName(), &httpClientDetails.Headers) - rtUtils.SetContentType("application/json", &httpClientDetails.Headers) + httpClientDetails.SetContentTypeApplicationJson() return } diff --git a/pipelines/services/run.go b/pipelines/services/run.go index 15e69242b..2b8d25894 100644 --- a/pipelines/services/run.go +++ b/pipelines/services/run.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -93,7 +92,7 @@ func (rs *RunService) TriggerPipelineRun(branch, pipeline string, isMultiBranch } // URL Construction - utils.AddHeader("Content-Type", "application/json", &httpDetails.Headers) + httpDetails.SetContentTypeApplicationJson() uri, err := constructPipelinesURL(queryParams, rs.ServiceDetails.GetUrl(), triggerpipeline) if err != nil { return err @@ -130,7 +129,7 @@ func (rs *RunService) CancelRun(runID int) error { } // URL Construction - utils.AddHeader("Content-Type", "application/json", &httpDetails.Headers) + httpDetails.SetContentTypeApplicationJson() uri, err := constructPipelinesURL(queryParams, rs.ServiceDetails.GetUrl(), cancelRun) if err != nil { return err diff --git a/tests/utils_test.go b/tests/utils_test.go index dc3b5c98b..8c338017e 100644 --- a/tests/utils_test.go +++ b/tests/utils_test.go @@ -1023,7 +1023,7 @@ func deleteBuild(buildName string) error { func getIndexedBuilds() ([]string, error) { xrayDetails := GetXrayDetails() artHTTPDetails := xrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &artHTTPDetails.Headers) + artHTTPDetails.SetContentTypeApplicationJson() client, err := httpclient.ClientBuilder().Build() if err != nil { return []string{}, err @@ -1062,7 +1062,7 @@ func deleteBuildIndex(buildName string) error { // Delete build index xrayDetails := GetXrayDetails() artHTTPDetails := xrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &artHTTPDetails.Headers) + artHTTPDetails.SetContentTypeApplicationJson() client, err := httpclient.ClientBuilder().Build() if err != nil { return err diff --git a/utils/distribution/distribute.go b/utils/distribution/distribute.go index 4b051cb59..c8badb781 100644 --- a/utils/distribution/distribute.go +++ b/utils/distribution/distribute.go @@ -2,7 +2,6 @@ package distribution import ( "encoding/json" - artifactoryUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" clientUtils "github.com/jfrog/jfrog-client-go/utils" @@ -62,7 +61,7 @@ func execDistribute(dr DistributeReleaseBundleExecutor, name, version string) (j } httpClientsDetails := dr.ServiceDetails().CreateHttpClientDetails() - artifactoryUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() resp, body, err := dr.GetHttpClient().SendPost(requestFullUrl, content, &httpClientsDetails) if err != nil { return "", err diff --git a/utils/io/content/contentreader.go b/utils/io/content/contentreader.go index f1737dfa4..1d2c09dd2 100644 --- a/utils/io/content/contentreader.go +++ b/utils/io/content/contentreader.go @@ -209,7 +209,7 @@ func MergeReaders(arr []*ContentReader, arrayKey string) (contentReader *Content for item := new(interface{}); cr.NextRecord(item) == nil; item = new(interface{}) { cw.Write(*item) } - if err := cr.GetError(); err != nil { + if err = cr.GetError(); err != nil { return nil, err } } diff --git a/utils/io/content/contentwriter.go b/utils/io/content/contentwriter.go index e74f52c8a..ff49a4036 100644 --- a/utils/io/content/contentwriter.go +++ b/utils/io/content/contentwriter.go @@ -135,8 +135,8 @@ func (rw *ContentWriter) run() { rw.errorsQueue.AddError(errorutils.CheckError(err)) continue } - record := recordPrefix + string(bytes.TrimRight(buf.Bytes(), "\n")) - _, err = rw.outputFile.WriteString(record) + recordString := recordPrefix + string(bytes.TrimRight(buf.Bytes(), "\n")) + _, err = rw.outputFile.WriteString(recordString) if err != nil { rw.errorsQueue.AddError(errorutils.CheckError(err)) continue diff --git a/utils/io/httputils/httpclient.go b/utils/io/httputils/httpclient.go index 9d86a7eb1..d652bb146 100644 --- a/utils/io/httputils/httpclient.go +++ b/utils/io/httputils/httpclient.go @@ -22,26 +22,37 @@ type HttpClientDetails struct { type PreRetryInterceptor func() (shouldRetry bool) -func (httpClientDetails HttpClientDetails) Clone() *HttpClientDetails { +func (hcd HttpClientDetails) Clone() *HttpClientDetails { headers := make(map[string]string) - utils.MergeMaps(httpClientDetails.Headers, headers) + utils.MergeMaps(hcd.Headers, headers) var transport *http.Transport - if httpClientDetails.Transport != nil { - transport = httpClientDetails.Transport.Clone() + if hcd.Transport != nil { + transport = hcd.Transport.Clone() } return &HttpClientDetails{ - User: httpClientDetails.User, - Password: httpClientDetails.Password, - ApiKey: httpClientDetails.ApiKey, - AccessToken: httpClientDetails.AccessToken, + User: hcd.User, + Password: hcd.Password, + ApiKey: hcd.ApiKey, + AccessToken: hcd.AccessToken, Headers: headers, Transport: transport, - DialTimeout: httpClientDetails.DialTimeout, - OverallRequestTimeout: httpClientDetails.OverallRequestTimeout, - PreRetryInterceptors: httpClientDetails.PreRetryInterceptors, + DialTimeout: hcd.DialTimeout, + OverallRequestTimeout: hcd.OverallRequestTimeout, + PreRetryInterceptors: hcd.PreRetryInterceptors, } } -func (httpClientDetails *HttpClientDetails) AddPreRetryInterceptor(preRetryInterceptors PreRetryInterceptor) { - httpClientDetails.PreRetryInterceptors = append(httpClientDetails.PreRetryInterceptors, preRetryInterceptors) +func (hcd *HttpClientDetails) AddPreRetryInterceptor(preRetryInterceptors PreRetryInterceptor) { + hcd.PreRetryInterceptors = append(hcd.PreRetryInterceptors, preRetryInterceptors) +} + +func (hcd *HttpClientDetails) SetContentTypeApplicationJson() { + hcd.AddHeader("Content-Type", "application/json") +} + +func (hcd *HttpClientDetails) AddHeader(headerName, headerValue string) { + if hcd.Headers == nil { + hcd.Headers = make(map[string]string) + } + hcd.Headers[headerName] = headerValue } diff --git a/xray/services/binMgr.go b/xray/services/binMgr.go index 653a1497b..ea52b9fda 100644 --- a/xray/services/binMgr.go +++ b/xray/services/binMgr.go @@ -6,7 +6,6 @@ import ( "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" - artUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" clientutils "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -54,7 +53,7 @@ func (xbms *BinMgrService) AddBuildsToIndexing(buildNames []string) error { } httpClientsDetails := xbms.XrayDetails.CreateHttpClientDetails() - artUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = xbms.getBinMgrURL() + "/builds" log.Info("Configuring Xray to index the build...") resp, body, err := xbms.client.SendPost(url, content, &httpClientsDetails) diff --git a/xray/services/buildscan.go b/xray/services/buildscan.go index 734738ed3..a422ece96 100644 --- a/xray/services/buildscan.go +++ b/xray/services/buildscan.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "github.com/jfrog/gofrog/version" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -59,7 +58,7 @@ func (bs *BuildScanService) ScanBuild(params XrayBuildParams, includeVulnerabili func (bs *BuildScanService) triggerScan(paramsBytes []byte) error { httpClientsDetails := bs.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() url := bs.XrayDetails.GetUrl() + BuildScanAPI resp, body, err := bs.client.SendPost(url, paramsBytes, &httpClientsDetails) @@ -95,7 +94,7 @@ func (bs *BuildScanService) prepareGetResultsRequest(params XrayBuildParams, par queryParams = append(queryParams, includeVulnerabilitiesQueryParam+"true") } httpClientsDetails := bs.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() if version.NewVersion(xrayVer).AtLeast(buildScanResultsPostApiMinXrayVersion) { getResultsReqFunc = bs.getResultsPostRequestFunc(params, paramsBytes, &httpClientsDetails, queryParams) return diff --git a/xray/services/enrich.go b/xray/services/enrich.go index 9c999cacb..7c0924c84 100644 --- a/xray/services/enrich.go +++ b/xray/services/enrich.go @@ -37,7 +37,7 @@ func (es *EnrichService) ImportGraph(importParams XrayGraphImportParams) (string utils.SetContentType("application/xml", &httpClientsDetails.Headers) url = es.XrayDetails.GetUrl() + importGraphXML } else { - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() url = es.XrayDetails.GetUrl() + importGraph } @@ -62,7 +62,7 @@ func (es *EnrichService) ImportGraph(importParams XrayGraphImportParams) (string func (es *EnrichService) GetImportGraphResults(scanId string) (*ScanResponse, error) { httpClientsDetails := es.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() // Getting the import graph results is from the same api but with some parameters always initialized. endPoint := es.XrayDetails.GetUrl() + scanGraphAPI + "/" + scanId + includeVulnerabilitiesParam diff --git a/xray/services/ignorerule.go b/xray/services/ignorerule.go index 440ca6ffe..952332555 100644 --- a/xray/services/ignorerule.go +++ b/xray/services/ignorerule.go @@ -6,7 +6,6 @@ import ( "net/http" "regexp" - artUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" clientutils "github.com/jfrog/jfrog-client-go/utils" @@ -49,7 +48,7 @@ func (xirs *IgnoreRuleService) getIgnoreRuleURL() string { // Delete will delete an ignore rule by id func (xirs *IgnoreRuleService) Delete(ignoreRuleId string) error { httpClientsDetails := xirs.XrayDetails.CreateHttpClientDetails() - artUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() log.Info("Deleting ignore rule...") resp, body, err := xirs.client.SendDelete(xirs.getIgnoreRuleURL()+"/"+ignoreRuleId, nil, &httpClientsDetails) @@ -74,7 +73,7 @@ func (xirs *IgnoreRuleService) Create(params utils.IgnoreRuleParams) (ignoreRule } httpClientsDetails := xirs.XrayDetails.CreateHttpClientDetails() - artUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = xirs.getIgnoreRuleURL() log.Info("Create new ignore rule...") diff --git a/xray/services/policy.go b/xray/services/policy.go index ceb1b48a6..fef075d53 100644 --- a/xray/services/policy.go +++ b/xray/services/policy.go @@ -8,7 +8,6 @@ import ( "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" - artUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" clientutils "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -59,7 +58,7 @@ func (xps *PolicyService) getPolicyURL() string { // It will error if no policy can be found by that name. func (xps *PolicyService) Delete(policyName string) error { httpClientsDetails := xps.XrayDetails.CreateHttpClientDetails() - artUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() log.Info("Deleting policy...") resp, body, err := xps.client.SendDelete(xps.getPolicyURL()+"/"+policyName, nil, &httpClientsDetails) @@ -83,7 +82,7 @@ func (xps *PolicyService) Create(params utils.PolicyParams) error { } httpClientsDetails := xps.XrayDetails.CreateHttpClientDetails() - artUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = xps.getPolicyURL() log.Info(fmt.Sprintf("Creating a new Policy named %s on JFrog Xray....", params.Name)) @@ -113,7 +112,7 @@ func (xps *PolicyService) Update(params utils.PolicyParams) error { } httpClientsDetails := xps.XrayDetails.CreateHttpClientDetails() - artUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = xps.getPolicyURL() + "/" + params.Name log.Info("Updating policy...") diff --git a/xray/services/report.go b/xray/services/report.go index ee387f8ed..f910d8029 100644 --- a/xray/services/report.go +++ b/xray/services/report.go @@ -3,7 +3,6 @@ package services import ( "encoding/json" "fmt" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -207,7 +206,7 @@ func (rs *ReportService) Violations(req ViolationsReportRequestParams) (*ReportR func (rs *ReportService) requestReport(req any, reportType string) (*ReportResponse, error) { retVal := ReportResponse{} httpClientsDetails := rs.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() url := fmt.Sprintf("%s/%s", rs.XrayDetails.GetUrl(), ReportsAPI+"/"+reportType) content, err := json.Marshal(req) @@ -235,7 +234,7 @@ func (rs *ReportService) requestReport(req any, reportType string) (*ReportRespo func (rs *ReportService) Details(reportId string) (*ReportDetails, error) { retVal := ReportDetails{} httpClientsDetails := rs.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() url := fmt.Sprintf("%s/%s/%s", rs.XrayDetails.GetUrl(), ReportsAPI, reportId) resp, body, _, err := rs.client.SendGet(url, true, &httpClientsDetails) @@ -258,7 +257,7 @@ func (rs *ReportService) Details(reportId string) (*ReportDetails, error) { func (rs *ReportService) Content(request ReportContentRequestParams) (*ReportContent, error) { retVal := ReportContent{} httpClientsDetails := rs.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() url := fmt.Sprintf("%s/%s/%s/%s?direction=%s&page_num=%d&num_of_rows=%d&order_by=%s", rs.XrayDetails.GetUrl(), ReportsAPI, request.ReportType, request.ReportId, request.Direction, request.PageNum, request.NumRows, request.OrderBy) @@ -277,7 +276,7 @@ func (rs *ReportService) Content(request ReportContentRequestParams) (*ReportCon // Delete deletes the report that has an id matching reportId func (rs *ReportService) Delete(reportId string) error { httpClientsDetails := rs.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() url := fmt.Sprintf("%s/%s/%s", rs.XrayDetails.GetUrl(), ReportsAPI, reportId) resp, body, err := rs.client.SendDelete(url, nil, &httpClientsDetails) diff --git a/xray/services/scan.go b/xray/services/scan.go index 177cb9b38..53fcb0644 100644 --- a/xray/services/scan.go +++ b/xray/services/scan.go @@ -9,7 +9,6 @@ import ( "github.com/jfrog/jfrog-client-go/utils/log" xrayUtils "github.com/jfrog/jfrog-client-go/xray/services/utils" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -106,7 +105,7 @@ func createScanGraphQueryParams(scanParams XrayGraphScanParams) string { func (ss *ScanService) ScanGraph(scanParams XrayGraphScanParams) (string, error) { httpClientsDetails := ss.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var err error var requestBody []byte if scanParams.DependenciesGraph != nil { @@ -145,7 +144,7 @@ func (ss *ScanService) ScanGraph(scanParams XrayGraphScanParams) (string, error) func (ss *ScanService) GetScanGraphResults(scanId string, includeVulnerabilities, includeLicenses, xscEnabled bool) (*ScanResponse, error) { httpClientsDetails := ss.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() // The scan request may take some time to complete. We expect to receive a 202 response, until the completion. endPoint := ss.XrayDetails.GetUrl() + scanGraphAPI @@ -193,7 +192,7 @@ func (ss *ScanService) xrayToXscUrl() string { func (ss *ScanService) SendScanGitInfoContext(details *XscGitInfoContext) (multiScanId string, err error) { httpClientsDetails := ss.XrayDetails.CreateHttpClientDetails() - utils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() requestBody, err := json.Marshal(details) if err != nil { return "", errorutils.CheckError(err) diff --git a/xray/services/summary.go b/xray/services/summary.go index 5659d289e..3da92e3b8 100644 --- a/xray/services/summary.go +++ b/xray/services/summary.go @@ -5,7 +5,6 @@ import ( "fmt" "net/http" - servicesutils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -56,8 +55,7 @@ func (ss *SummaryService) GetBuildSummary(params XrayBuildParams) (*SummaryRespo func (ss *SummaryService) GetArtifactSummary(params ArtifactSummaryParams) (*ArtifactSummaryResponse, error) { httpDetails := ss.XrayDetails.CreateHttpClientDetails() - servicesutils.SetContentType("application/json", &httpDetails.Headers) - + httpDetails.SetContentTypeApplicationJson() requestBody, err := json.Marshal(params) if err != nil { return nil, errorutils.CheckError(err) diff --git a/xray/services/watch.go b/xray/services/watch.go index ae356e0b7..ac71623ea 100644 --- a/xray/services/watch.go +++ b/xray/services/watch.go @@ -8,7 +8,6 @@ import ( "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" - artUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/auth" clientutils "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" @@ -86,7 +85,7 @@ func (xws *WatchService) Create(params utils.WatchParams) error { } httpClientsDetails := xws.XrayDetails.CreateHttpClientDetails() - artUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = xws.getWatchURL() log.Info(fmt.Sprintf("Creating a new Watch named %s on JFrog Xray....", params.Name)) @@ -128,7 +127,7 @@ func (xws *WatchService) Update(params utils.WatchParams) error { } httpClientsDetails := xws.XrayDetails.CreateHttpClientDetails() - artUtils.SetContentType("application/json", &httpClientsDetails.Headers) + httpClientsDetails.SetContentTypeApplicationJson() var url = xws.getWatchURL() + "/" + params.Name log.Info("Updating watch...") diff --git a/xray/usage/reportusage.go b/xray/usage/reportusage.go index 3ca7b3801..cb1555782 100644 --- a/xray/usage/reportusage.go +++ b/xray/usage/reportusage.go @@ -5,7 +5,6 @@ import ( "errors" "net/http" - "github.com/jfrog/jfrog-client-go/artifactory/services/utils" clientutils "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/jfrog/jfrog-client-go/xray" @@ -62,7 +61,7 @@ func SendXrayUsageEvents(serviceManager xray.XrayServicesManager, events ...Repo if errorutils.CheckError(err) != nil { return err } - utils.AddHeader("Content-Type", "application/json", &clientDetails.Headers) + clientDetails.SetContentTypeApplicationJson() resp, body, err := serviceManager.Client().SendPost(url, bodyContent, &clientDetails) if err != nil { return errors.New("Couldn't send usage info. Error: " + err.Error()) From ab971556737621b64ac758ebe21bee509a26a7bd Mon Sep 17 00:00:00 2001 From: Osaid Wattad Date: Sun, 11 Aug 2024 17:29:30 +0300 Subject: [PATCH 2/4] Adding Metadata Service Manager (#997) --- README.md | 52 +++++++++++++++++++++++++++++ metadata/auth/metadatadetails.go | 17 ++++++++++ metadata/manager.go | 45 +++++++++++++++++++++++++ metadata/services/graphql.go | 45 +++++++++++++++++++++++++ metadata/services/graphql_test.go | 55 +++++++++++++++++++++++++++++++ tests/timeout_test.go | 20 +++++++++++ 6 files changed, 234 insertions(+) create mode 100644 metadata/auth/metadatadetails.go create mode 100644 metadata/manager.go create mode 100644 metadata/services/graphql.go create mode 100644 metadata/services/graphql_test.go diff --git a/README.md b/README.md index 6167f726b..8ef95903b 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,13 @@ - [Creating New Evidence Service Manager](#creating-new-evidence-service-manager) - [Using Evidence Services](#using-evidence-services) - [Upload Evidence](#upload-evidence) + - [Metadata APIs](#metadata-apis) + - [Creating Metadata Service Manager](#creating-metadata-service-manager) + - [Creating Metadata Details](#creating-metadata-details) + - [Creating Metadata Service Config](#creating-metadata-service-config) + - [Creating New Metadata Service Manager](#creating-new-metadata-service-manager) + - [Using Metadata Services](#using-metadata-services) + - [Graphql query](#graphql-query) ## General @@ -2964,3 +2971,48 @@ evidenceDetails := evidenceService.EvidenceDetails{ } body, err = evideceManager.UploadEvidence(evidenceDetails) ``` +## Metadata APIs + +### Creating Metadata Service Manager + +#### Creating Metadata Details + +```go +mdDetails := auth.NewMetadataDetails() +mdDetails.SetUrl("http://localhost:8081/metadata") +mdDetails.SetAccessToken("access-token") +// if client certificates are required +mdDetails.SetClientCertPath("path/to/.cer") +mdDetails.SetClientCertKeyPath("path/to/.key") +``` + +#### Creating Metadata Service Config + +```go +serviceConfig, err := config.NewConfigBuilder(). + SetServiceDetails(mdDetails). + SetCertificatesPath(mdDetails.GetClientCertPath()). + // Optionally overwrite the default HTTP retries, which is set to 3. + SetHttpRetries(3). + Build() +``` + +#### Creating New Metadata Service Manager + +```go +metadataManager, err := metadata.NewManager(serviceConfig) +``` + +### Using Metadata Services + +#### Graphql query + +```go +queryBytes := []byte(`{"query":"someGraphqlQuery"}`) + +queryDetails := metadataService.QueryDetails{ + Body: queryBytes, +} + +body, err = metadataManager.GraphqlQuery(queryDetails) +``` \ No newline at end of file diff --git a/metadata/auth/metadatadetails.go b/metadata/auth/metadatadetails.go new file mode 100644 index 000000000..fe8504d19 --- /dev/null +++ b/metadata/auth/metadatadetails.go @@ -0,0 +1,17 @@ +package auth + +import ( + "github.com/jfrog/jfrog-client-go/auth" +) + +type metadataDetails struct { + auth.CommonConfigFields +} + +func NewMetadataDetails() auth.ServiceDetails { + return &metadataDetails{} +} + +func (rt *metadataDetails) GetVersion() (string, error) { + panic("Failed: Method is not implemented") +} diff --git a/metadata/manager.go b/metadata/manager.go new file mode 100644 index 000000000..9b6e3b071 --- /dev/null +++ b/metadata/manager.go @@ -0,0 +1,45 @@ +package metadata + +import ( + "github.com/jfrog/jfrog-client-go/config" + "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" + "github.com/jfrog/jfrog-client-go/metadata/services" +) + +type Manager interface { + GraphqlQuery(query []byte) ([]byte, error) +} + +type metadataManager struct { + client *jfroghttpclient.JfrogHttpClient + config config.Config +} + +func NewManager(config config.Config) (Manager, error) { + details := config.GetServiceDetails() + var err error + manager := &metadataManager{config: config} + manager.client, err = jfroghttpclient.JfrogClientBuilder(). + SetCertificatesPath(config.GetCertificatesPath()). + SetInsecureTls(config.IsInsecureTls()). + SetClientCertPath(details.GetClientCertPath()). + SetClientCertKeyPath(details.GetClientCertKeyPath()). + AppendPreRequestInterceptor(details.RunPreRequestFunctions). + SetContext(config.GetContext()). + SetDialTimeout(config.GetDialTimeout()). + SetOverallRequestTimeout(config.GetOverallRequestTimeout()). + SetRetries(config.GetHttpRetries()). + SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()). + Build() + + return manager, err +} + +func (mm *metadataManager) Client() *jfroghttpclient.JfrogHttpClient { + return mm.client +} + +func (mm *metadataManager) GraphqlQuery(query []byte) ([]byte, error) { + metadataService := services.NewMetadataService(mm.config.GetServiceDetails(), mm.client) + return metadataService.Query(query) +} diff --git a/metadata/services/graphql.go b/metadata/services/graphql.go new file mode 100644 index 000000000..1ccde656f --- /dev/null +++ b/metadata/services/graphql.go @@ -0,0 +1,45 @@ +package services + +import ( + "fmt" + rtUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" + "github.com/jfrog/jfrog-client-go/auth" + "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" + "github.com/jfrog/jfrog-client-go/utils/errorutils" + "net/http" + "net/url" +) + +const queryUrl = "api/v1/query" + +type Service interface { + Query(query []byte) ([]byte, error) +} + +type metadataService struct { + client *jfroghttpclient.JfrogHttpClient + serviceDetails *auth.ServiceDetails +} + +func NewMetadataService(serviceDetails auth.ServiceDetails, client *jfroghttpclient.JfrogHttpClient) Service { + return &metadataService{serviceDetails: &serviceDetails, client: client} +} + +func (m *metadataService) GetMetadataDetails() auth.ServiceDetails { + return *m.serviceDetails +} + +func (m *metadataService) Query(query []byte) ([]byte, error) { + graphqlUrl, err := url.Parse(m.GetMetadataDetails().GetUrl() + queryUrl) + if err != nil { + return nil, fmt.Errorf("failed to parse URL: %w", err) + } + httpClientDetails := m.GetMetadataDetails().CreateHttpClientDetails() + rtUtils.SetContentType("application/json", &httpClientDetails.Headers) + + resp, body, err := m.client.SendPost(graphqlUrl.String(), query, &httpClientDetails) + if err != nil { + return []byte{}, err + } + return body, errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK) +} diff --git a/metadata/services/graphql_test.go b/metadata/services/graphql_test.go new file mode 100644 index 000000000..b15bc5a65 --- /dev/null +++ b/metadata/services/graphql_test.go @@ -0,0 +1,55 @@ +package services + +import ( + "encoding/json" + "github.com/jfrog/jfrog-client-go/artifactory/auth" + "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" + "github.com/stretchr/testify/assert" + "net/http" + "net/http/httptest" + "testing" +) + +const queryData = `{"query":"someGraphqlQuery"}` + +func TestMetadataService_Query(t *testing.T) { + handlerFunc, requestNum := createMetadataHandlerFunc(t) + + mockServer, metadataService := createMockMetadataServer(t, handlerFunc) + defer mockServer.Close() + + _, err := metadataService.Query([]byte(queryData)) + assert.NoError(t, err) + assert.Equal(t, 1, *requestNum) +} + +func createMockMetadataServer(t *testing.T, testHandler http.HandlerFunc) (*httptest.Server, *metadataService) { + testServer := httptest.NewServer(testHandler) + + serviceDetails := auth.NewArtifactoryDetails() + serviceDetails.SetUrl(testServer.URL + "/") + + client, err := jfroghttpclient.JfrogClientBuilder().Build() + assert.NoError(t, err) + return testServer, &metadataService{serviceDetails: &serviceDetails, client: client} +} + +func createMetadataHandlerFunc(t *testing.T) (http.HandlerFunc, *int) { + requestNum := 0 + return func(w http.ResponseWriter, r *http.Request) { + if r.RequestURI == "/api/v1/query" { + assert.Equal(t, "application/json", r.Header.Get("Content-Type")) + + w.WriteHeader(http.StatusOK) + requestNum++ + writeMockMetadataResponse(t, w, []byte(queryData)) + } + }, &requestNum +} + +func writeMockMetadataResponse(t *testing.T, w http.ResponseWriter, payload []byte) { + content, err := json.Marshal(payload) + assert.NoError(t, err) + _, err = w.Write(content) + assert.NoError(t, err) +} diff --git a/tests/timeout_test.go b/tests/timeout_test.go index ea7304654..6dc284bae 100644 --- a/tests/timeout_test.go +++ b/tests/timeout_test.go @@ -3,6 +3,7 @@ package tests import ( "github.com/jfrog/jfrog-client-go/evidence" "github.com/jfrog/jfrog-client-go/evidence/services" + "github.com/jfrog/jfrog-client-go/metadata" "net/http" "net/http/httptest" "testing" @@ -23,6 +24,7 @@ import ( evidenceAuth "github.com/jfrog/jfrog-client-go/evidence/auth" lifecycleAuth "github.com/jfrog/jfrog-client-go/lifecycle/auth" lifecycleServices "github.com/jfrog/jfrog-client-go/lifecycle/services" + metadataAuth "github.com/jfrog/jfrog-client-go/metadata/auth" pipelinesAuth "github.com/jfrog/jfrog-client-go/pipelines/auth" "github.com/jfrog/jfrog-client-go/utils/log" "github.com/jfrog/jfrog-client-go/utils/tests" @@ -48,6 +50,7 @@ func TestTimeout(t *testing.T) { t.Run("testPipelinesTimeout", testPipelinesTimeout) t.Run("testXrayTimeout", testXrayTimeout) t.Run("testEvidenceTimeout", testEvidenceTimeout) + t.Run("testMetadataTimeout", testMetadataTimeout) } func testAccessTimeout(t *testing.T) { @@ -136,6 +139,23 @@ func testEvidenceTimeout(t *testing.T) { assert.ErrorContains(t, err, "context deadline exceeded") } +func testMetadataTimeout(t *testing.T) { + // Create mock server + url, cleanup := createSleepyRequestServer() + defer cleanup() + + // Create services manager configuring to work with the mock server + details := metadataAuth.NewMetadataDetails() + details.SetUrl(url) + servicesManager, err := metadata.NewManager(createServiceConfigWithTimeout(t, details)) + assert.NoError(t, err) + + query := []byte("query body") + // Expect timeout + _, err = servicesManager.GraphqlQuery(query) + assert.ErrorContains(t, err, "context deadline exceeded") +} + func testPipelinesTimeout(t *testing.T) { // Create mock server url, cleanup := createSleepyRequestServer() From 1f32e208a317247c36daca7aabbb60162b1a5843 Mon Sep 17 00:00:00 2001 From: Bar Vered <161704690+barv-jfrog@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:51:19 +0300 Subject: [PATCH 3/4] Secret Token Validation (#991) --- README.md | 5 ++ .../services/utils/tests/xray/consts.go | 2 + .../services/utils/tests/xray/server.go | 12 +++++ tests/xrayjasconfig_test.go | 36 +++++++++++++ xray/manager.go | 6 +++ xray/services/jasconfig.go | 51 +++++++++++++++++++ 6 files changed, 112 insertions(+) create mode 100644 tests/xrayjasconfig_test.go create mode 100644 xray/services/jasconfig.go diff --git a/README.md b/README.md index 8ef95903b..e2a10ea55 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ - [Retrieve the Graph Scan Results](#retrieve-the-graph-scan-results) - [Request Graph Enrich](#request-graph-enrich) - [Retrieve the Graph Enrich Results](#retrieve-the-graph-enrich-results) + - [Get Token Validation Status](#get-token-validation-status) - [Generate Vulnerabilities Report](#generate-vulnerabilities-report) - [Get Vulnerabilities Report Details](#get-vulnerabilities-report-details) - [Get Vulnerabilities Report Content](#get-vulnerabilities-report-content) @@ -2160,6 +2161,10 @@ scanId, err := xrayManager.ImportGraph(graphImportParams) enrichResults, err := xrayManager.GetImportGraphResults(scanId) ``` +#### Get Token Validation Status +```go +isEnabled, err := xrayManager.IsTokenValidationEnabled() +``` #### Generate Vulnerabilities Report diff --git a/artifactory/services/utils/tests/xray/consts.go b/artifactory/services/utils/tests/xray/consts.go index e30db20a9..4fb0c478e 100644 --- a/artifactory/services/utils/tests/xray/consts.go +++ b/artifactory/services/utils/tests/xray/consts.go @@ -1429,6 +1429,8 @@ const xscVersionResponse = `{"xsc_version": "1.0.0"}` const scanIdResponse = `{"scan_id": "3472b4e2-bddc-11ee-a9c9-acde48001122"}` +const JasConfigResponse = `{"enable_token_validation_scanning": true}` + const XscGitInfoResponse = `{"multi_scan_id": "3472b4e2-bddc-11ee-a9c9-acde48001122"}` const XscGitInfoBadResponse = `"failed create git info request: git_repo_url field must contain value"` diff --git a/artifactory/services/utils/tests/xray/server.go b/artifactory/services/utils/tests/xray/server.go index 6a38ff8c8..34b476ae4 100644 --- a/artifactory/services/utils/tests/xray/server.go +++ b/artifactory/services/utils/tests/xray/server.go @@ -208,6 +208,17 @@ func enrichGetScanId(t *testing.T) func(w http.ResponseWriter, r *http.Request) } } +func getJasConfig(t *testing.T) func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodGet { + _, err := fmt.Fprint(w, JasConfigResponse) + assert.NoError(t, err) + return + } + http.Error(w, "Invalid enrich get scan id request", http.StatusBadRequest) + } +} + func enrichGetResults(t *testing.T) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodGet { @@ -250,6 +261,7 @@ func StartXrayMockServer(t *testing.T) int { handlers["/xsc/api/v1/system/version"] = xscGetVersionHandlerFunc(t) handlers["/xsc/api/v1/gitinfo"] = xscGitInfoHandlerFunc(t) handlers["/xray/api/v1/scan/import_xml"] = enrichGetScanId(t) + handlers["/xray/api/v1/configuration/jas"] = getJasConfig(t) getEnrichResults := fmt.Sprintf("/xray/api/v1/scan/graph/%s", TestMultiScanId) handlers[getEnrichResults] = enrichGetResults(t) handlers[fmt.Sprintf("/%s/", services.ReportsAPI)] = reportHandler diff --git a/tests/xrayjasconfig_test.go b/tests/xrayjasconfig_test.go new file mode 100644 index 000000000..5e93ecb47 --- /dev/null +++ b/tests/xrayjasconfig_test.go @@ -0,0 +1,36 @@ +package tests + +import ( + "github.com/jfrog/jfrog-client-go/artifactory/services/utils/tests/xray" + "github.com/jfrog/jfrog-client-go/auth" + "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" + xrayServices "github.com/jfrog/jfrog-client-go/xray/services" + "github.com/stretchr/testify/assert" + "strconv" + "testing" +) + +func initXrayJasConfigTest(t *testing.T) (xrayServerPort int, xrayDetails auth.ServiceDetails, client *jfroghttpclient.JfrogHttpClient) { + var err error + initXrayTest(t) + xrayServerPort = xray.StartXrayMockServer(t) + xrayDetails = GetXrayDetails() + client, err = jfroghttpclient.JfrogClientBuilder(). + SetClientCertPath(xrayDetails.GetClientCertPath()). + SetClientCertKeyPath(xrayDetails.GetClientCertKeyPath()). + AppendPreRequestInterceptor(xrayDetails.RunPreRequestFunctions). + Build() + assert.NoError(t, err) + return +} + +func TestIsTokenValidationEnabled(t *testing.T) { + xrayServerPort, xrayDetails, client := initXrayJasConfigTest(t) + testsJasConfigService := xrayServices.NewJasConfigService(client) + testsJasConfigService.XrayDetails = xrayDetails + testsJasConfigService.XrayDetails.SetUrl("http://localhost:" + strconv.Itoa(xrayServerPort) + "/xray/") + + result, err := testsJasConfigService.GetJasConfigTokenValidation() + assert.NoError(t, err) + assert.Equal(t, result, true) +} diff --git a/xray/manager.go b/xray/manager.go index 25256d90f..9667e681a 100644 --- a/xray/manager.go +++ b/xray/manager.go @@ -142,6 +142,12 @@ func (sm *XrayServicesManager) AddBuildsToIndexing(buildNames []string) error { return binMgrService.AddBuildsToIndexing(buildNames) } +func (sm *XrayServicesManager) IsTokenValidationEnabled() (isEnabled bool, err error) { + jasConfigService := services.NewJasConfigService(sm.client) + jasConfigService.XrayDetails = sm.config.GetServiceDetails() + return jasConfigService.GetJasConfigTokenValidation() +} + // ScanGraph will send Xray the given graph for scan // Returns a string represents the scan ID. func (sm *XrayServicesManager) ScanGraph(params services.XrayGraphScanParams) (scanId string, err error) { diff --git a/xray/services/jasconfig.go b/xray/services/jasconfig.go new file mode 100644 index 000000000..cb6af794c --- /dev/null +++ b/xray/services/jasconfig.go @@ -0,0 +1,51 @@ +package services + +import ( + "encoding/json" + "errors" + "github.com/jfrog/jfrog-client-go/auth" + "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" + "github.com/jfrog/jfrog-client-go/utils/errorutils" + "net/http" +) + +const ( + jasConfigApiURL = "api/v1/configuration/jas" +) + +// JasConfigService returns the https client and Xray details +type JasConfigService struct { + client *jfroghttpclient.JfrogHttpClient + XrayDetails auth.ServiceDetails +} + +// NewJasConfigService creates a new service to retrieve the version of Xray +func NewJasConfigService(client *jfroghttpclient.JfrogHttpClient) *JasConfigService { + return &JasConfigService{client: client} +} + +// GetXrayDetails returns the Xray details +func (jcs *JasConfigService) GetXrayDetails() auth.ServiceDetails { + return jcs.XrayDetails +} + +// GetJasConfigTokenValidation returns token validation status in xray +func (jcs *JasConfigService) GetJasConfigTokenValidation() (bool, error) { + httpDetails := jcs.XrayDetails.CreateHttpClientDetails() + resp, body, _, err := jcs.client.SendGet(jcs.XrayDetails.GetUrl()+jasConfigApiURL, true, &httpDetails) + if err != nil { + return false, errors.New("failed while attempting to get JFrog Xray Jas Configuration: " + err.Error()) + } + if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil { + return false, errors.New("got unexpected server response while attempting to get JFrog Xray Jas Configuration:\n" + err.Error()) + } + var jasConfig JasConfig + if err = json.Unmarshal(body, &jasConfig); err != nil { + return false, errorutils.CheckErrorf("couldn't parse JFrog Xray server Jas Configuration response: " + err.Error()) + } + return *jasConfig.TokenValidationToggle, nil +} + +type JasConfig struct { + TokenValidationToggle *bool `json:"enable_token_validation_scanning,omitempty"` +} From d0578f37b362bae40a94b13013fa3353719bbdd2 Mon Sep 17 00:00:00 2001 From: Michael Sverdlov Date: Wed, 14 Aug 2024 17:11:13 +0300 Subject: [PATCH 4/4] Promote to v1.44.0 (#1001) Signed-off-by: Michael Sverdlov --- go.mod | 18 +++++++-------- go.sum | 40 +++++++++++++++++----------------- utils/errorutils/errorutils.go | 2 +- utils/utils.go | 2 +- xray/services/summary.go | 4 ++-- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 3dbf3dd6d..5d7889cec 100644 --- a/go.mod +++ b/go.mod @@ -10,14 +10,14 @@ require ( github.com/golang-jwt/jwt/v4 v4.5.0 github.com/gookit/color v1.5.4 github.com/jfrog/archiver/v3 v3.6.1 - github.com/jfrog/build-info-go v1.9.32 + github.com/jfrog/build-info-go v1.9.33 github.com/jfrog/gofrog v1.7.5 github.com/minio/sha256-simd v1.0.1 github.com/stretchr/testify v1.9.0 github.com/xanzy/ssh-agent v0.3.3 - golang.org/x/crypto v0.25.0 - golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 - golang.org/x/term v0.22.0 + golang.org/x/crypto v0.26.0 + golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa + golang.org/x/term v0.23.0 ) require ( @@ -49,11 +49,11 @@ require ( github.com/ulikunitz/xz v0.5.12 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect - golang.org/x/mod v0.19.0 // indirect - golang.org/x/net v0.27.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/tools v0.23.0 // indirect + golang.org/x/mod v0.20.0 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/tools v0.24.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index ac1ac44a8..258341449 100644 --- a/go.sum +++ b/go.sum @@ -59,8 +59,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOl github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jfrog/archiver/v3 v3.6.1 h1:LOxnkw9pOn45DzCbZNFV6K0+6dCsQ0L8mR3ZcujO5eI= github.com/jfrog/archiver/v3 v3.6.1/go.mod h1:VgR+3WZS4N+i9FaDwLZbq+jeU4B4zctXL+gL4EMzfLw= -github.com/jfrog/build-info-go v1.9.32 h1:PKXAMe84sMdob6eBtwwGz47Fz2cmjMwMPoHW8xuk08Q= -github.com/jfrog/build-info-go v1.9.32/go.mod h1:JTGnENexG1jRhKWCkQtZuDb0PerlzlSzF5OmMLG9kfc= +github.com/jfrog/build-info-go v1.9.33 h1:TEeTHDc3tEwZe/7kKhm1hQDd5vA/HnVhp1ZczUOWExk= +github.com/jfrog/build-info-go v1.9.33/go.mod h1:JTGnENexG1jRhKWCkQtZuDb0PerlzlSzF5OmMLG9kfc= github.com/jfrog/gofrog v1.7.5 h1:dFgtEDefJdlq9cqTRoe09RLxS5Bxbe1Ev5+E6SmZHcg= github.com/jfrog/gofrog v1.7.5/go.mod h1:jyGiCgiqSSR7k86hcUSu67XVvmvkkgWTmPsH25wI298= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= @@ -131,14 +131,14 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI= +golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= -golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -146,13 +146,13 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -167,15 +167,15 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= -golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= +golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= +golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -183,14 +183,14 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= -golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/utils/errorutils/errorutils.go b/utils/errorutils/errorutils.go index 3aaf2f53c..c434b2a56 100644 --- a/utils/errorutils/errorutils.go +++ b/utils/errorutils/errorutils.go @@ -52,7 +52,7 @@ func GenerateResponseError(status, body string) error { if body != "" { responseErrString = responseErrString + "\n" + body } - return fmt.Errorf(responseErrString) + return errors.New(responseErrString) } func GenerateErrorString(bodyArray []byte) string { diff --git a/utils/utils.go b/utils/utils.go index 2befe8d4a..3f0e55638 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -28,7 +28,7 @@ import ( const ( Development = "development" Agent = "jfrog-client-go" - Version = "1.43.2" + Version = "1.44.0" ) type MinVersionProduct string diff --git a/xray/services/summary.go b/xray/services/summary.go index 3da92e3b8..325c78d1b 100644 --- a/xray/services/summary.go +++ b/xray/services/summary.go @@ -47,7 +47,7 @@ func (ss *SummaryService) GetBuildSummary(params XrayBuildParams) (*SummaryRespo if err != nil { return nil, errorutils.CheckError(err) } - if summaryResponse.Errors != nil && len(summaryResponse.Errors) > 0 { + if len(summaryResponse.Errors) > 0 { return nil, errorutils.CheckErrorf("getting build-summary for build: %s failed with error: %s", summaryResponse.Errors[0].Identifier, summaryResponse.Errors[0].Error) } return &summaryResponse, nil @@ -74,7 +74,7 @@ func (ss *SummaryService) GetArtifactSummary(params ArtifactSummaryParams) (*Art if err != nil { return nil, errorutils.CheckError(err) } - if response.Errors != nil && len(response.Errors) > 0 { + if len(response.Errors) > 0 { return nil, errorutils.CheckErrorf("getting artifact-summary for artifact: %s failed with error: %s", response.Errors[0].Identifier, response.Errors[0].Error) } return &response, nil