Skip to content

Commit

Permalink
Support bare IPv6 vCenter server addresses
Browse files Browse the repository at this point in the history
Co-authored-by: Tyler Schultz <[email protected]>
  • Loading branch information
christianang and tylerschultz committed Jul 12, 2023
1 parent 527d522 commit 5caea58
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package session

import (
"context"
"fmt"
"net/netip"
"net/url"
"sync"
"time"
Expand Down Expand Up @@ -137,7 +139,17 @@ func GetOrCreate(ctx context.Context, params *Params) (*Session, error) {
}

clearCache(logger, sessionKey)
soapURL, err := soap.ParseURL(params.server)

// soap.ParseURL expects a valid URL. In the case of a bare, unbracketed
// IPv6 address (e.g fd00::1) ParseURL will fail. Surround unbracketed IPv6
// addresses with brackets.
urlSafeServer := params.server
ip, err := netip.ParseAddr(urlSafeServer)
if err == nil && ip.Is6() {
urlSafeServer = fmt.Sprintf("[%s]", urlSafeServer)
}

soapURL, err := soap.ParseURL(urlSafeServer)
if err != nil {
return nil, errors.Wrapf(err, "error parsing vSphere URL %q", params.server)
}
Expand Down

0 comments on commit 5caea58

Please sign in to comment.