Skip to content

Commit

Permalink
basic auth added
Browse files Browse the repository at this point in the history
  • Loading branch information
DukeLog committed Aug 29, 2015
1 parent 02ee328 commit 8413716
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions generator/operations_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ var opsTmpl = `
client *gowsdl.SoapClient
}
func New{{$portType}}(url string, tls bool) *{{$portType}} {
func New{{$portType}}(url string, tls bool, auth *gowsdl.BasicAuth) *{{$portType}} {
if url == "" {
url = {{findServiceAddress .Name | printf "%q"}}
}
client := gowsdl.NewSoapClient(url, tls)
client := gowsdl.NewSoapClient(url, tls, auth)
return &{{$portType}}{
client: client,
Expand Down
15 changes: 13 additions & 2 deletions generator/soap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"

"gopkg.in/inconshreveable/log15.v2"
"fmt"
)

var Log = log15.New()
Expand Down Expand Up @@ -41,19 +42,26 @@ type SoapFault struct {
Detail string `xml:"detail,omitempty"`
}

type BasicAuth struct {
Login string
Password string
}

type SoapClient struct {
url string
tls bool
auth *BasicAuth
}

func (f *SoapFault) Error() string {
return f.Faultstring
}

func NewSoapClient(url string, tls bool) *SoapClient {
func NewSoapClient(url string, tls bool, auth *BasicAuth) *SoapClient {
return &SoapClient{
url: url,
tls: tls,
auth: auth,
}
}

Expand Down Expand Up @@ -85,6 +93,9 @@ func (s *SoapClient) Call(soapAction string, request, response interface{}) erro
}

req, err := http.NewRequest("POST", s.url, buffer)
if s.auth != nil {
req.SetBasicAuth(s.auth.Login, s.auth.Password)
}
req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"")
if soapAction != "" {
req.Header.Add("SOAPAction", soapAction)
Expand All @@ -111,7 +122,7 @@ func (s *SoapClient) Call(soapAction string, request, response interface{}) erro
Log.Warn("empty response")
return nil
}

fmt.Println(string(rawbody))
respEnvelope := &SoapEnvelope{}

err = xml.Unmarshal(rawbody, respEnvelope)
Expand Down

0 comments on commit 8413716

Please sign in to comment.