diff --git a/pkg/util/dialer.go b/pkg/util/dialer.go index 14331e65f..d0a0345e4 100644 --- a/pkg/util/dialer.go +++ b/pkg/util/dialer.go @@ -12,6 +12,7 @@ import ( "github.com/Axway/agent-sdk/pkg/util/log" "golang.org/x/net/proxy" + gr "google.golang.org/grpc/resolver" ) const ( @@ -167,3 +168,42 @@ func (d *dialer) createConnectRequest(ctx context.Context, targetAddress, sniHos } return req.WithContext(ctx) } + +type customGRPCResolverBuilder struct { + addr string + authority string + schema string +} + +func CreateCustomGRPCResolverBuilder(addr, authority, scheme string) gr.Builder { + return &customGRPCResolverBuilder{ + addr: addr, + authority: authority, + schema: scheme, + } +} + +func (b *customGRPCResolverBuilder) Build(target gr.Target, cc gr.ClientConn, _ gr.BuildOptions) (gr.Resolver, error) { + cc.UpdateState(gr.State{Endpoints: []gr.Endpoint{ + { + Addresses: []gr.Address{ + { + Addr: b.addr, + ServerName: b.authority, + }, + }, + }, + }}) + return &nopResolver{}, nil +} + +func (b *customGRPCResolverBuilder) Scheme() string { + return b.schema +} + +type nopResolver struct { +} + +func (*nopResolver) ResolveNow(gr.ResolveNowOptions) {} + +func (*nopResolver) Close() {} diff --git a/pkg/watchmanager/manager.go b/pkg/watchmanager/manager.go index 608bb93f4..99941097a 100644 --- a/pkg/watchmanager/manager.go +++ b/pkg/watchmanager/manager.go @@ -13,7 +13,6 @@ import ( "github.com/Axway/agent-sdk/pkg/watchmanager/proto" "github.com/google/uuid" "google.golang.org/grpc" - gr "google.golang.org/grpc/resolver" ) // NewManagerFunc func signature to create a Manager @@ -88,7 +87,11 @@ func (m *watchManager) createConnection() (*grpc.ClientConn, error) { logrusStreamClientInterceptor(m.options.loggerEntry), ), grpc.WithUserAgent(m.cfg.UserAgent), - grpc.WithResolvers(&builder{m.cfg.Host, m.cfg.Port}), + grpc.WithResolvers( + util.CreateCustomGRPCResolverBuilder( + fmt.Sprintf("%s:%d", m.cfg.Host, m.cfg.Port), + m.cfg.Host, + "https")), } m.logger. @@ -99,36 +102,6 @@ func (m *watchManager) createConnection() (*grpc.ClientConn, error) { return grpc.NewClient(address, grpcDialOptions...) } -type builder struct { - host string - port uint32 -} - -func (b *builder) Build(target gr.Target, cc gr.ClientConn, _ gr.BuildOptions) (gr.Resolver, error) { - cc.UpdateState(gr.State{Endpoints: []gr.Endpoint{ - { - Addresses: []gr.Address{ - { - Addr: fmt.Sprintf("%s:%d", b.host, b.port), - ServerName: b.host, - }, - }, - }, - }}) - return &nopResolver{}, nil -} - -func (b *builder) Scheme() string { - return b.host -} - -type nopResolver struct { -} - -func (*nopResolver) ResolveNow(gr.ResolveNowOptions) {} - -func (*nopResolver) Close() {} - func (m *watchManager) getDialer(targetAddr string) (util.Dialer, error) { if m.options.singleEntryAddr == "" && m.options.proxyURL == "" { return nil, nil