Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/jfrog/jfrog-client-go into xsc
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Aug 28, 2023
2 parents 75aaa3d + 653986a commit 3812c20
Show file tree
Hide file tree
Showing 28 changed files with 459 additions and 120 deletions.
16 changes: 9 additions & 7 deletions access/services/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package services

import (
"encoding/json"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
"net/http"
"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"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
"net/http"
"path"
"time"
)

const (
Expand Down Expand Up @@ -37,7 +39,7 @@ func NewLoginService(client *jfroghttpclient.JfrogHttpClient) *LoginService {

func (ls *LoginService) SendLoginAuthenticationRequest(uuid string) error {
restAPI := path.Join(baseClientLoginApi, requestApi)
fullUrl, err := utils.BuildArtifactoryUrl(ls.ServiceDetails.GetUrl(), restAPI, make(map[string]string))
fullUrl, err := utils.BuildUrl(ls.ServiceDetails.GetUrl(), restAPI, make(map[string]string))
if err != nil {
return err
}
Expand All @@ -49,7 +51,7 @@ func (ls *LoginService) SendLoginAuthenticationRequest(uuid string) error {
return errorutils.CheckError(err)
}
httpClientsDetails := ls.ServiceDetails.CreateHttpClientDetails()
utils.SetContentType("application/json", &httpClientsDetails.Headers)
artifactoryutils.SetContentType("application/json", &httpClientsDetails.Headers)
resp, body, err := ls.client.SendPost(fullUrl, requestContent, &httpClientsDetails)
if err != nil {
return err
Expand Down Expand Up @@ -89,7 +91,7 @@ func (ls *LoginService) GetLoginAuthenticationToken(uuid string) (token auth.Com

func (ls *LoginService) getLoginAuthenticationToken(uuid string) (resp *http.Response, body []byte, err error) {
restAPI := path.Join(baseClientLoginApi, tokenApi, uuid)
fullUrl, err := utils.BuildArtifactoryUrl(ls.ServiceDetails.GetUrl(), restAPI, make(map[string]string))
fullUrl, err := utils.BuildUrl(ls.ServiceDetails.GetUrl(), restAPI, make(map[string]string))
if err != nil {
return
}
Expand Down
3 changes: 2 additions & 1 deletion artifactory/services/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/jfrog/jfrog-client-go/auth"
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
clientutils "github.com/jfrog/jfrog-client-go/utils"
urlutil "github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/content"
"github.com/jfrog/jfrog-client-go/utils/log"
Expand Down Expand Up @@ -98,7 +99,7 @@ func (ds *DeleteService) createFileHandlerFunc(result *utils.Result) fileDeleteH
return func(threadId int) error {
result.TotalCount[threadId]++
logMsgPrefix := clientutils.GetLogMsgPrefix(threadId, ds.DryRun)
deletePath, e := utils.BuildArtifactoryUrl(ds.GetArtifactoryDetails().GetUrl(), resultItem.GetItemRelativePath(), make(map[string]string))
deletePath, e := urlutil.BuildUrl(ds.GetArtifactoryDetails().GetUrl(), resultItem.GetItemRelativePath(), make(map[string]string))
if e != nil {
return e
}
Expand Down
10 changes: 6 additions & 4 deletions artifactory/services/discardBuilds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package services

import (
"encoding/json"
buildinfo "github.com/jfrog/build-info-go/entities"
"net/http"
"path"
"strconv"
"strings"
"time"

"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
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"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
)
Expand All @@ -30,7 +32,7 @@ func (ds *DiscardBuildsService) DiscardBuilds(params DiscardBuildsParams) error

discardUrl := ds.ArtDetails.GetUrl()
restApi := path.Join("api/build/retention/", params.GetBuildName())
requestFullUrl, err := utils.BuildArtifactoryUrl(discardUrl, restApi, make(map[string]string))
requestFullUrl, err := utils.BuildUrl(discardUrl, restApi, make(map[string]string))
if err != nil {
return err
}
Expand Down Expand Up @@ -63,7 +65,7 @@ func (ds *DiscardBuildsService) DiscardBuilds(params DiscardBuildsParams) error
}

httpClientsDetails := ds.getArtifactoryDetails().CreateHttpClientDetails()
utils.SetContentType("application/json", &httpClientsDetails.Headers)
artifactoryutils.SetContentType("application/json", &httpClientsDetails.Headers)

resp, body, err := ds.client.SendPost(requestFullUrl, requestContent, &httpClientsDetails)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions artifactory/services/distribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"path"
"strings"

"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
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"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
)
Expand Down Expand Up @@ -41,7 +42,7 @@ func (ds *DistributeService) BuildDistribute(params BuildDistributionParams) err

distributeUrl := ds.ArtDetails.GetUrl()
restApi := path.Join("api/build/distribute/", params.GetBuildName(), params.GetBuildNumber())
requestFullUrl, err := utils.BuildArtifactoryUrl(distributeUrl, restApi, make(map[string]string))
requestFullUrl, err := utils.BuildUrl(distributeUrl, restApi, make(map[string]string))
if err != nil {
return err
}
Expand Down Expand Up @@ -70,7 +71,7 @@ func (ds *DistributeService) BuildDistribute(params BuildDistributionParams) err
}

httpClientsDetails := ds.getArtifactoryDetails().CreateHttpClientDetails()
utils.SetContentType("application/json", &httpClientsDetails.Headers)
artifactoryutils.SetContentType("application/json", &httpClientsDetails.Headers)

resp, body, err := ds.client.SendPost(requestFullUrl, requestContent, &httpClientsDetails)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions artifactory/services/dockerpromote.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"net/http"
"path"

"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
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"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ func (ps *DockerPromoteService) IsDryRun() bool {
func (ps *DockerPromoteService) PromoteDocker(params DockerPromoteParams) error {
// Create URL
restApi := path.Join("api/docker", params.SourceRepo, "v2", "promote")
url, err := utils.BuildArtifactoryUrl(ps.GetArtifactoryDetails().GetUrl(), restApi, nil)
url, err := utils.BuildUrl(ps.GetArtifactoryDetails().GetUrl(), restApi, nil)
if err != nil {
return err
}
Expand All @@ -57,7 +58,7 @@ func (ps *DockerPromoteService) PromoteDocker(params DockerPromoteParams) error

// Send POST request
httpClientsDetails := ps.GetArtifactoryDetails().CreateHttpClientDetails()
utils.SetContentType("application/json", &httpClientsDetails.Headers)
artifactoryutils.SetContentType("application/json", &httpClientsDetails.Headers)
resp, body, err := ps.client.SendPost(url, requestContent, &httpClientsDetails)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion artifactory/services/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func (ds *DownloadService) createFileHandlerFunc(downloadParams DownloadParams,
return func(downloadData DownloadData) parallel.TaskFunc {
return func(threadId int) error {
logMsgPrefix := clientutils.GetLogMsgPrefix(threadId, ds.DryRun)
downloadPath, e := utils.BuildArtifactoryUrl(ds.GetArtifactoryDetails().GetUrl(), downloadData.Dependency.GetItemRelativePath(), make(map[string]string))
downloadPath, e := clientutils.BuildUrl(ds.GetArtifactoryDetails().GetUrl(), downloadData.Dependency.GetItemRelativePath(), make(map[string]string))
if e != nil {
return e
}
Expand Down
11 changes: 6 additions & 5 deletions artifactory/services/go/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"github.com/jfrog/gofrog/version"
"github.com/jfrog/jfrog-client-go/utils/log"

"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
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"
clientutils "github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/content"
Expand All @@ -37,8 +38,8 @@ func (gpc *GoPublishCommand) verifyCompatibleVersion(artifactoryVersion string)
return nil
}

func (gpc *GoPublishCommand) PublishPackage(params GoParams, client *jfroghttpclient.JfrogHttpClient, artDetails auth.ServiceDetails) (*utils.OperationSummary, error) {
goApiUrl, err := utils.BuildArtifactoryUrl(artDetails.GetUrl(), "api/go/", make(map[string]string))
func (gpc *GoPublishCommand) PublishPackage(params GoParams, client *jfroghttpclient.JfrogHttpClient, artDetails auth.ServiceDetails) (*artifactoryutils.OperationSummary, error) {
goApiUrl, err := utils.BuildUrl(artDetails.GetUrl(), "api/go/", make(map[string]string))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -72,7 +73,7 @@ func (gpc *GoPublishCommand) PublishPackage(params GoParams, client *jfroghttpcl
return nil, err
}

return &utils.OperationSummary{TotalSucceeded: totalSucceed, TotalFailed: totalFailed, TransferDetailsReader: content.NewContentReader(fileTransferDetailsTempFile, "files")}, nil
return &artifactoryutils.OperationSummary{TotalSucceeded: totalSucceed, TotalFailed: totalFailed, TransferDetailsReader: content.NewContentReader(fileTransferDetailsTempFile, "files")}, nil
}

func (gpc *GoPublishCommand) uploadFile(params GoParams, filePath string, moduleId, ext, goApiUrl string, filesDetails *[]clientutils.FileTransferDetails, pwa *GoPublishCommand) (success, failed int, err error) {
Expand Down Expand Up @@ -108,7 +109,7 @@ func (gpc *GoPublishCommand) upload(localPath, pathInArtifactory, version, props
if err != nil {
return nil, err
}
utils.AddChecksumHeaders(gpc.clientDetails.Headers, details)
artifactoryutils.AddChecksumHeaders(gpc.clientDetails.Headers, details)
resp, body, err := gpc.client.UploadFile(localPath, goApiUrl, "", &gpc.clientDetails, nil)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/movecopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (mc *MoveCopyService) moveOrCopyFile(sourcePath, destPath, logMsgPrefix str
} else {
log.Info(logMsgPrefix + message)
}
requestFullUrl, err := utils.BuildArtifactoryUrl(moveUrl, restApi, params)
requestFullUrl, err := clientutils.BuildUrl(moveUrl, restApi, params)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (mc *MoveCopyService) createPathForMoveAction(destPath, logMsgPrefix string

func (mc *MoveCopyService) createPathInArtifactory(destPath, logMsgPrefix string) (bool, error) {
rtUrl := mc.GetArtifactoryDetails().GetUrl()
requestFullUrl, err := utils.BuildArtifactoryUrl(rtUrl, destPath, map[string]string{})
requestFullUrl, err := clientutils.BuildUrl(rtUrl, destPath, map[string]string{})
if err != nil {
return false, err
}
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package services
import (
"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"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
)
Expand All @@ -32,7 +32,7 @@ func (ps *PingService) IsDryRun() bool {
}

func (ps *PingService) Ping() ([]byte, error) {
url, err := utils.BuildArtifactoryUrl(ps.GetArtifactoryDetails().GetUrl(), "api/system/ping", nil)
url, err := utils.BuildUrl(ps.GetArtifactoryDetails().GetUrl(), "api/system/ping", nil)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion artifactory/services/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"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"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
)
Expand Down Expand Up @@ -41,7 +42,7 @@ func (ps *PromoteService) BuildPromote(promotionParams PromotionParams) error {
queryParams["project"] = promotionParams.ProjectKey
}

requestFullUrl, err := utils.BuildArtifactoryUrl(promoteUrl, restApi, queryParams)
requestFullUrl, err := clientutils.BuildUrl(promoteUrl, restApi, queryParams)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (ps *PropsService) performRequest(propsParams PropsParams, isDelete bool) (
logMsgPrefix := clientutils.GetLogMsgPrefix(threadId, ps.IsDryRun())

restAPI := path.Join("api", "storage", relativePath)
setPropertiesURL, err := utils.BuildArtifactoryUrl(ps.GetArtifactoryDetails().GetUrl(), restAPI, make(map[string]string))
setPropertiesURL, err := clientutils.BuildUrl(ps.GetArtifactoryDetails().GetUrl(), restAPI, make(map[string]string))
if err != nil {
return err
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func NewPropsParams() PropsParams {

func (ps *PropsService) GetItemProperties(relativePath string) (*utils.ItemProperties, error) {
restAPI := path.Join("api", "storage", path.Clean(relativePath))
propertiesURL, err := utils.BuildArtifactoryUrl(ps.GetArtifactoryDetails().GetUrl(), restAPI, make(map[string]string))
propertiesURL, err := clientutils.BuildUrl(ps.GetArtifactoryDetails().GetUrl(), restAPI, make(map[string]string))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/readfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"io"
"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"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
)

Expand Down Expand Up @@ -39,7 +39,7 @@ func (ds *ReadFileService) SetDryRun(isDryRun bool) {
}

func (ds *ReadFileService) ReadRemoteFile(downloadPath string) (io.ReadCloser, error) {
readPath, err := utils.BuildArtifactoryUrl(ds.GetArtifactoryDetails().GetUrl(), downloadPath, make(map[string]string))
readPath, err := utils.BuildUrl(ds.GetArtifactoryDetails().GetUrl(), downloadPath, make(map[string]string))
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions artifactory/services/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strconv"
"strings"

"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"
Expand All @@ -34,7 +33,7 @@ func (ss *SecurityService) getArtifactoryDetails() auth.ServiceDetails {
// Create an API key for the current user. Returns an error if API key already exists - use regenerate API key instead.
func (ss *SecurityService) CreateAPIKey() (string, error) {
httpClientDetails := ss.ArtDetails.CreateHttpClientDetails()
reqURL, err := utils.BuildArtifactoryUrl(ss.ArtDetails.GetUrl(), APIKeyPath, nil)
reqURL, err := clientutils.BuildUrl(ss.ArtDetails.GetUrl(), APIKeyPath, nil)
if err != nil {
return "", err
}
Expand All @@ -55,7 +54,7 @@ func (ss *SecurityService) CreateAPIKey() (string, error) {
func (ss *SecurityService) RegenerateAPIKey() (string, error) {
httpClientDetails := ss.ArtDetails.CreateHttpClientDetails()

reqURL, err := utils.BuildArtifactoryUrl(ss.ArtDetails.GetUrl(), APIKeyPath, nil)
reqURL, err := clientutils.BuildUrl(ss.ArtDetails.GetUrl(), APIKeyPath, nil)
if err != nil {
return "", err
}
Expand All @@ -75,7 +74,7 @@ func (ss *SecurityService) RegenerateAPIKey() (string, error) {
// Returns empty string if API Key wasn't generated.
func (ss *SecurityService) GetAPIKey() (string, error) {
httpClientDetails := ss.ArtDetails.CreateHttpClientDetails()
reqURL, err := utils.BuildArtifactoryUrl(ss.ArtDetails.GetUrl(), APIKeyPath, nil)
reqURL, err := clientutils.BuildUrl(ss.ArtDetails.GetUrl(), APIKeyPath, nil)
if err != nil {
return "", err
}
Expand Down
12 changes: 7 additions & 5 deletions artifactory/services/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package services

import (
"encoding/json"
"net/http"
"path"
"strconv"

"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"
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"net/http"
"path"
"strconv"
)

type StorageService struct {
Expand All @@ -34,7 +36,7 @@ func (s *StorageService) GetJfrogHttpClient() *jfroghttpclient.JfrogHttpClient {
func (s *StorageService) FolderInfo(relativePath string) (*utils.FolderInfo, error) {
client := s.GetJfrogHttpClient()
restAPI := path.Join(StorageRestApi, path.Clean(relativePath))
folderUrl, err := utils.BuildArtifactoryUrl(s.GetArtifactoryDetails().GetUrl(), restAPI, make(map[string]string))
folderUrl, err := clientutils.BuildUrl(s.GetArtifactoryDetails().GetUrl(), restAPI, make(map[string]string))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -69,7 +71,7 @@ func (s *StorageService) FileList(relativePath string, optionalParams utils.File
params["depth"] = strconv.Itoa(optionalParams.Depth)
}

folderUrl, err := utils.BuildArtifactoryUrl(s.GetArtifactoryDetails().GetUrl(), restAPI, params)
folderUrl, err := clientutils.BuildUrl(s.GetArtifactoryDetails().GetUrl(), restAPI, params)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 3812c20

Please sign in to comment.