@@ -18,6 +18,7 @@ package session
18
18
19
19
import (
20
20
"context"
21
+ "crypto/tls"
21
22
"errors"
22
23
"fmt"
23
24
"io"
@@ -159,7 +160,7 @@ func newClientWithTimeout(ctx context.Context, u *url.URL, insecure bool, timeou
159
160
*/
160
161
161
162
customTransport := & CustomTransport {
162
- RoundTripper : http . DefaultTransport ,
163
+ RoundTripper : createTransport ( insecure ) ,
163
164
}
164
165
165
166
soapClient := soap .NewClient (u , insecure )
@@ -182,7 +183,6 @@ func newClientWithTimeout(ctx context.Context, u *url.URL, insecure bool, timeou
182
183
if err != nil {
183
184
log .Fatalf ("Failed to login to vSphere: %v" , err )
184
185
}
185
- defer client .Logout (clientCreateCtx )
186
186
187
187
// Create SOAP client with custom transport
188
188
//client.Transport = customTransport
@@ -363,3 +363,18 @@ func (s *Session) WithCachingTagsManager(ctx context.Context, f func(m *CachingT
363
363
364
364
return f (m )
365
365
}
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