@@ -18,6 +18,7 @@ package session
1818
1919import (
2020 "context"
21+ "crypto/tls"
2122 "errors"
2223 "fmt"
2324 "io"
@@ -159,7 +160,7 @@ func newClientWithTimeout(ctx context.Context, u *url.URL, insecure bool, timeou
159160 */
160161
161162 customTransport := & CustomTransport {
162- RoundTripper : http . DefaultTransport ,
163+ RoundTripper : createTransport ( insecure ) ,
163164 }
164165
165166 soapClient := soap .NewClient (u , insecure )
@@ -182,7 +183,6 @@ func newClientWithTimeout(ctx context.Context, u *url.URL, insecure bool, timeou
182183 if err != nil {
183184 log .Fatalf ("Failed to login to vSphere: %v" , err )
184185 }
185- defer client .Logout (clientCreateCtx )
186186
187187 // Create SOAP client with custom transport
188188 //client.Transport = customTransport
@@ -363,3 +363,18 @@ func (s *Session) WithCachingTagsManager(ctx context.Context, f func(m *CachingT
363363
364364 return f (m )
365365}
366+
367+ // createTransport creates a transport that respects the insecure flag
368+ func createTransport (insecure bool ) http.RoundTripper {
369+ if insecure {
370+ // Create a transport that skips TLS verification
371+ transport := & http.Transport {
372+ TLSClientConfig : & tls.Config {
373+ InsecureSkipVerify : true ,
374+ },
375+ }
376+ return transport
377+ }
378+ // Use default transport for secure connections
379+ return http .DefaultTransport
380+ }
0 commit comments