From 28de1049214c353b859917c02ee85df36a7c7eb9 Mon Sep 17 00:00:00 2001 From: Adlane Achab Date: Mon, 23 Oct 2017 22:16:07 +0200 Subject: [PATCH] Add a new API to pass a tls.Config pointer. --- operations_tmpl.go | 11 +++++++++++ soap_tmpl.go | 23 ++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/operations_tmpl.go b/operations_tmpl.go index b8503ad..3849d5f 100644 --- a/operations_tmpl.go +++ b/operations_tmpl.go @@ -22,6 +22,17 @@ var opsTmpl = ` } } + func New{{$portType}}WithTLSConfig(url string, tlsCfg *tls.Config, auth *BasicAuth) *{{$portType}} { + if url == "" { + url = {{findServiceAddress .Name | printf "%q"}} + } + client := NewSOAPClientWithTLSConfig(url, tlsCfg, auth) + + return &{{$portType}}{ + client: client, + } + } + func (service *{{$portType}}) AddHeader(header interface{}) { service.client.AddHeader(header) } diff --git a/soap_tmpl.go b/soap_tmpl.go index f28d4fd..e5e3cf8 100644 --- a/soap_tmpl.go +++ b/soap_tmpl.go @@ -19,7 +19,7 @@ type SOAPEnvelope struct { type SOAPHeader struct { XMLName xml.Name ` + "`" + `xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"` + "`" + ` - + Items []interface{} ` + "`" + `xml:",omitempty"` + "`" + ` } @@ -49,7 +49,7 @@ const ( type WSSSecurityHeader struct { XMLName xml.Name ` + "`" + `xml:"http://schemas.xmlsoap.org/soap/envelope/ wsse:Security"` + "`" + ` XmlNSWsse string ` + "`" + `xml:"xmlns:wsse,attr"` + "`" + ` - + MustUnderstand string ` + "`" + `xml:"mustUnderstand,attr,omitempty"` + "`" + ` Token *WSSUsernameToken ` + "`" + `xml:",omitempty"` + "`" + ` @@ -88,7 +88,7 @@ type BasicAuth struct { type SOAPClient struct { url string - tls bool + tlsCfg *tls.Config auth *BasicAuth headers []interface{} } @@ -186,10 +186,17 @@ func (f *SOAPFault) Error() string { return f.String } -func NewSOAPClient(url string, tls bool, auth *BasicAuth) *SOAPClient { +func NewSOAPClient(url string, insecureSkipVerify bool, auth *BasicAuth) *SOAPClient { + tlsCfg := &tls.Config{ + InsecureSkipVerify: insecureSkipVerify, + } + return NewSOAPClientWithTLSConfig(url, tlsCfg, auth) +} + +func NewSOAPClientWithTLSConfig(url string, tlsCfg *tls.Config, auth *BasicAuth) *SOAPClient { return &SOAPClient{ url: url, - tls: tls, + tlsCfg: tlsCfg, auth: auth, } } @@ -233,14 +240,12 @@ func (s *SOAPClient) Call(soapAction string, request, response interface{}) erro req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"") req.Header.Add("SOAPAction", soapAction) - + req.Header.Set("User-Agent", "gowsdl/0.1") req.Close = true tr := &http.Transport{ - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: s.tls, - }, + TLSClientConfig: s.tlsCfg, Dial: dialTimeout, }