Skip to content

Commit

Permalink
Merge pull request #16 from eyalbe4/dev
Browse files Browse the repository at this point in the history
Isolate the CreateArtifactoryHttpClient API.
  • Loading branch information
eyalbe4 authored Dec 2, 2018
2 parents 094f769 + 1e4f2e4 commit a326960
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
19 changes: 19 additions & 0 deletions artifactory/httpclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package artifactory

import (
"github.com/jfrog/jfrog-client-go/artifactory/auth/cert"
"github.com/jfrog/jfrog-client-go/httpclient"
"net/http"
)

func CreateArtifactoryHttpClient(config Config) (*httpclient.HttpClient, error) {
if config.GetCertifactesPath() == "" {
return httpclient.NewDefaultHttpClient(), nil
}

transport, err := cert.GetTransportWithLoadedCert(config.GetCertifactesPath())
if err != nil {
return nil, err
}
return httpclient.NewHttpClient(&http.Client{Transport: transport}), nil
}
15 changes: 4 additions & 11 deletions artifactory/manager.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package artifactory

import (
"github.com/jfrog/jfrog-client-go/artifactory/auth/cert"
"github.com/jfrog/jfrog-client-go/artifactory/buildinfo"
"github.com/jfrog/jfrog-client-go/artifactory/services"
"github.com/jfrog/jfrog-client-go/artifactory/services/go"
"github.com/jfrog/jfrog-client-go/artifactory/services/utils"
"github.com/jfrog/jfrog-client-go/httpclient"
"github.com/jfrog/jfrog-client-go/utils/log"
"io"
"net/http"
)

type ArtifactoryServicesManager struct {
Expand All @@ -20,14 +18,9 @@ type ArtifactoryServicesManager struct {
func New(config Config) (*ArtifactoryServicesManager, error) {
var err error
manager := &ArtifactoryServicesManager{config: config}
if config.GetCertifactesPath() == "" {
manager.client = httpclient.NewDefaultHttpClient()
} else {
transport, err := cert.GetTransportWithLoadedCert(config.GetCertifactesPath())
if err != nil {
return nil, err
}
manager.client = httpclient.NewHttpClient(&http.Client{Transport: transport})
manager.client, err = CreateArtifactoryHttpClient(config)
if err != nil {
return nil, err
}
if config.GetLogger() != nil {
log.SetLogger(config.GetLogger())
Expand Down Expand Up @@ -174,4 +167,4 @@ func (sm *ArtifactoryServicesManager) Ping() ([]byte, error) {

func (sm *ArtifactoryServicesManager) GetConfig() Config {
return sm.config
}
}

0 comments on commit a326960

Please sign in to comment.