Skip to content

Commit

Permalink
Merge pull request #92 from adlane/feature/tlsConfig
Browse files Browse the repository at this point in the history
Add a new API to pass a tls.Config pointer.
  • Loading branch information
c4milo authored Oct 31, 2017
2 parents b3b00e6 + 28de104 commit 256caae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
11 changes: 11 additions & 0 deletions operations_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
23 changes: 14 additions & 9 deletions soap_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"` + "`" + `
}
Expand Down Expand Up @@ -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"` + "`" + `
Expand Down Expand Up @@ -88,7 +88,7 @@ type BasicAuth struct {
type SOAPClient struct {
url string
tls bool
tlsCfg *tls.Config
auth *BasicAuth
headers []interface{}
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 256caae

Please sign in to comment.