Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass http.Client to all managers #1027

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions access/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func New(config config.Config) (*AccessServicesManager, error) {
SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
SetRetries(config.GetHttpRetries()).
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
SetHttpClient(config.GetHttpClient()).
Build()

return manager, err
Expand Down
9 changes: 4 additions & 5 deletions artifactory/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,17 +604,16 @@ func (sm *ArtifactoryServicesManagerImp) ImportReleaseBundle(filePath string) er
return releaseService.ImportReleaseBundle(filePath)
}

func buildJFrogHttpClient(config config.Config, authDetails auth.ServiceDetails) (*jfroghttpclient.JfrogHttpClient, error) {
func buildJFrogHttpClient(config config.Config, details auth.ServiceDetails) (*jfroghttpclient.JfrogHttpClient, error) {
return 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()).
SetClientCertPath(authDetails.GetClientCertPath()).
SetClientCertKeyPath(authDetails.GetClientCertKeyPath()).
AppendPreRequestInterceptor(authDetails.RunPreRequestFunctions).
SetContext(config.GetContext()).
SetRetries(config.GetHttpRetries()).
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
SetHttpClient(config.GetHttpClient()).
Expand Down
1 change: 1 addition & 0 deletions distribution/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func New(config config.Config) (*DistributionServicesManager, error) {
SetContext(config.GetContext()).
SetRetries(config.GetHttpRetries()).
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
SetHttpClient(config.GetHttpClient()).
Build()
return manager, err
}
Expand Down
1 change: 1 addition & 0 deletions evidence/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func New(config config.Config) (*EvidenceServicesManager, error) {
SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
SetRetries(config.GetHttpRetries()).
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
SetHttpClient(config.GetHttpClient()).
Build()

return manager, err
Expand Down
1 change: 1 addition & 0 deletions lifecycle/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func New(config config.Config) (*LifecycleServicesManager, error) {
SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
SetRetries(config.GetHttpRetries()).
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
SetHttpClient(config.GetHttpClient()).
Build()

return manager, err
Expand Down
2 changes: 2 additions & 0 deletions metadata/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type Manager interface {
GraphqlQuery(query []byte) ([]byte, error)
Client() *jfroghttpclient.JfrogHttpClient
}

type metadataManager struct {
Expand All @@ -30,6 +31,7 @@ func NewManager(config config.Config) (Manager, error) {
SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
SetRetries(config.GetHttpRetries()).
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
SetHttpClient(config.GetHttpClient()).
Build()

return manager, err
Expand Down
1 change: 1 addition & 0 deletions pipelines/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func New(config config.Config) (*PipelinesServicesManager, error) {
SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
SetRetries(config.GetHttpRetries()).
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
SetHttpClient(config.GetHttpClient()).
Build()
return manager, err
}
Expand Down
51 changes: 51 additions & 0 deletions tests/manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package tests

import (
"net/http"
"testing"

"github.com/jfrog/jfrog-client-go/access"
"github.com/jfrog/jfrog-client-go/config"
"github.com/jfrog/jfrog-client-go/distribution"
"github.com/jfrog/jfrog-client-go/evidence"
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
"github.com/jfrog/jfrog-client-go/lifecycle"
"github.com/jfrog/jfrog-client-go/metadata"
"github.com/jfrog/jfrog-client-go/pipelines"
"github.com/jfrog/jfrog-client-go/xray"
"github.com/jfrog/jfrog-client-go/xsc"
"github.com/stretchr/testify/assert"
)

func TestUsesCustomHttpClient(t *testing.T) {
t.Run("artifactory", func(t *testing.T) { usesCustomHttpClient(t, access.New) })
t.Run("access", func(t *testing.T) { usesCustomHttpClient(t, access.New) })
t.Run("distribution", func(t *testing.T) { usesCustomHttpClient(t, distribution.New) })
t.Run("evidence", func(t *testing.T) { usesCustomHttpClient(t, evidence.New) })
t.Run("lifecycle", func(t *testing.T) { usesCustomHttpClient(t, lifecycle.New) })
t.Run("metadata", func(t *testing.T) { usesCustomHttpClient(t, metadata.NewManager) })
t.Run("pipelines", func(t *testing.T) { usesCustomHttpClient(t, pipelines.New) })
t.Run("xray", func(t *testing.T) { usesCustomHttpClient(t, xray.New) })
t.Run("xsc", func(t *testing.T) { usesCustomHttpClient(t, xsc.New) })
}

type Manager interface {
Client() *jfroghttpclient.JfrogHttpClient
}

func usesCustomHttpClient[K Manager](t *testing.T, createManager func(config config.Config) (K, error)) {
client := http.DefaultClient
config, err := config.NewConfigBuilder().
SetServiceDetails(GetRtDetails()).
SetHttpClient(client).
Build()
if err != nil {
t.Error(err)
}
m, err := createManager(config)
if err != nil {
t.Error(err)
}
actualClient := m.Client().GetHttpClient().GetClient()
assert.Equal(t, client, actualClient, "Expected the client to be the same")
}
7 changes: 4 additions & 3 deletions xray/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ func New(config config.Config) (*XrayServicesManager, error) {
manager.client, err = jfroghttpclient.JfrogClientBuilder().
SetCertificatesPath(config.GetCertificatesPath()).
SetInsecureTls(config.IsInsecureTls()).
SetContext(config.GetContext()).
SetDialTimeout(config.GetDialTimeout()).
SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
SetClientCertPath(details.GetClientCertPath()).
SetClientCertKeyPath(details.GetClientCertKeyPath()).
AppendPreRequestInterceptor(details.RunPreRequestFunctions).
SetContext(config.GetContext()).
SetDialTimeout(config.GetDialTimeout()).
SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
SetRetries(config.GetHttpRetries()).
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
SetHttpClient(config.GetHttpClient()).
Build()
return manager, err
}
Expand Down
7 changes: 4 additions & 3 deletions xsc/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ func New(config config.Config) (*XscServicesManager, error) {
manager.client, err = jfroghttpclient.JfrogClientBuilder().
SetCertificatesPath(config.GetCertificatesPath()).
SetInsecureTls(config.IsInsecureTls()).
SetContext(config.GetContext()).
SetDialTimeout(config.GetDialTimeout()).
SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
SetClientCertPath(details.GetClientCertPath()).
SetClientCertKeyPath(details.GetClientCertKeyPath()).
AppendPreRequestInterceptor(details.RunPreRequestFunctions).
SetContext(config.GetContext()).
SetDialTimeout(config.GetDialTimeout()).
SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
SetRetries(config.GetHttpRetries()).
SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
SetHttpClient(config.GetHttpClient()).
Build()
return manager, err
}
Expand Down
Loading