diff --git a/pkg/controller/vsphere/session/session.go b/pkg/controller/vsphere/session/session.go index 85c9b2276e..be4229e341 100644 --- a/pkg/controller/vsphere/session/session.go +++ b/pkg/controller/vsphere/session/session.go @@ -18,16 +18,24 @@ package session import ( "context" + "crypto/tls" "errors" "fmt" + "io" + "log" + "net/http" "net/url" + "strings" "sync" "time" + "github.com/vmware/govmomi/session" "github.com/vmware/govmomi/vapi/rest" "github.com/vmware/govmomi/vapi/tags" + "github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/types" + "github.com/vmware/govmomi/vim25/xml" "github.com/google/uuid" "github.com/vmware/govmomi" @@ -57,14 +65,149 @@ type Session struct { sessionKey string } +// #### Start: This section was added by cursor + +// SOAPResponse represents the structure of SOAP responses +type SOAPResponse struct { + XMLName xml.Name `xml:"Envelope"` + Body struct { + XMLName xml.Name `xml:"Body"` + Fault *struct { + XMLName xml.Name `xml:"Fault"` + Code struct { + XMLName xml.Name `xml:"faultcode"` + Value string `xml:",chardata"` + } `xml:"faultcode"` + Reason struct { + XMLName xml.Name `xml:"faultstring"` + Value string `xml:",chardata"` + } `xml:"faultstring"` + Detail struct { + XMLName xml.Name `xml:"detail"` + Content string `xml:",chardata"` + } `xml:"detail"` + } `xml:"Fault,omitempty"` + } `xml:"Body"` +} + +// CustomTransport wraps the default transport to intercept SOAP responses +type CustomTransport struct { + http.RoundTripper +} + +func (t *CustomTransport) RoundTrip(req *http.Request) (*http.Response, error) { + // Call the original transport + resp, err := t.RoundTripper.RoundTrip(req) + if err != nil { + return resp, err + } + + // Read the response body + body, err := io.ReadAll(resp.Body) + if err != nil { + return resp, err + } + resp.Body.Close() + + // Check if it's a SOAP response + if strings.Contains(string(body), "