Skip to content

Commit

Permalink
feat: support ipv6 from address
Browse files Browse the repository at this point in the history
  • Loading branch information
lzgabel committed Feb 26, 2024
1 parent e1f73af commit 582084b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clients/go/cmd/zbctl/internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ var initClient = func(cmd *cobra.Command, args []string) error {
var credsProvider zbc.CredentialsProvider

host, port, err := parseAddress()
ip := net.ParseIP(host)
if ip == nil {

Check failure on line 102 in clients/go/cmd/zbctl/internal/commands/root.go

View workflow job for this annotation

GitHub Actions / Go linting

File is not `gofmt`-ed with `-s` (gofmt)
err = fmt.Errorf("Invalid IP address: %s\n", host)

Check warning on line 103 in clients/go/cmd/zbctl/internal/commands/root.go

View workflow job for this annotation

GitHub Actions / Go linting

error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
} else if ip.To16() != nil {
host = fmt.Sprintf("[%s]", host)
}

if err != nil {
return err
}
Expand Down
29 changes: 29 additions & 0 deletions clients/go/pkg/zbc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,35 @@ func (s *clientTestSuite) TestOverrideHostAndPortEnvVar() {
s.EqualValues(fmt.Sprintf("%s:%s", address, port), config.GatewayAddress)
}

func (s *clientTestSuite) TestHostWithIPV6() {
// given
host := "[::1]"
port := "9090"

Check failure on line 550 in clients/go/pkg/zbc/client_test.go

View workflow job for this annotation

GitHub Actions / Go linting

File is not `gofmt`-ed with `-s` (gofmt)
lis, grpcServer := createServer(host, port)

go grpcServer.Serve(lis)
defer func() {
grpcServer.Stop()
_ = lis.Close()
}()

client, err := NewClient(&ClientConfig{
GatewayAddress: fmt.Sprintf("%s:%s", host, port),
UsePlaintextConnection: true,
})

s.NoError(err)

// when
_, err = client.NewTopologyCommand().Send(context.Background())

// then
s.Error(err)
if grpcStatus, ok := status.FromError(err); ok {
s.EqualValues(codes.Unimplemented, grpcStatus.Code())
}
}

func createSecureServer(withSan bool) (net.Listener, *grpc.Server) {
certFile := "testdata/chain.cert.pem"
keyFile := "testdata/private.key.pem"
Expand Down

0 comments on commit 582084b

Please sign in to comment.