From b11e23f1e19829513541db90dc9828aec76a33b2 Mon Sep 17 00:00:00 2001 From: RachelTucker Date: Fri, 6 Dec 2019 11:13:11 -0700 Subject: [PATCH] GOSDK-30: Add a way to skip cert verification (#98) --- ds3/ds3Client.go | 5 +++++ ds3/networking/net.go | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ds3/ds3Client.go b/ds3/ds3Client.go index 0b82ef3..401ab3c 100644 --- a/ds3/ds3Client.go +++ b/ds3/ds3Client.go @@ -65,6 +65,11 @@ func (clientBuilder *ClientBuilder) WithNetworkRetryCount(count int) *ClientBuil return clientBuilder } +func (clientBuilder *ClientBuilder) WithIgnoreServerCertificate(ignoreServerCert bool) *ClientBuilder { + clientBuilder.connectionInfo.IgnoreServerCertificate = ignoreServerCert + return clientBuilder +} + func (clientBuilder *ClientBuilder) WithLogger(logger sdk_log.Logger) *ClientBuilder { clientBuilder.logger = logger return clientBuilder diff --git a/ds3/networking/net.go b/ds3/networking/net.go index 7472bbd..1aede6b 100644 --- a/ds3/networking/net.go +++ b/ds3/networking/net.go @@ -1,15 +1,17 @@ package networking import ( + "crypto/tls" "net/http" "net/url" "github.com/SpectraLogic/ds3_go_sdk/ds3/models" ) type ConnectionInfo struct { - Endpoint *url.URL - Credentials *Credentials - Proxy *url.URL + Endpoint *url.URL + Credentials *Credentials + Proxy *url.URL + IgnoreServerCertificate bool } type Credentials struct { @@ -27,9 +29,15 @@ type SendNetwork struct { } func NewSendNetwork(connectionInfo *ConnectionInfo) Network { - return &SendNetwork{ - transport: &http.Transport{Proxy: http.ProxyURL(connectionInfo.Proxy)}, + sendNetwork := &SendNetwork{ + transport: &http.Transport{ + Proxy: http.ProxyURL(connectionInfo.Proxy), + }, } + if connectionInfo.IgnoreServerCertificate { + sendNetwork.transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + } + return sendNetwork } func (sendNetwork *SendNetwork) Invoke(httpRequest *http.Request) (models.WebResponse, error) {