Skip to content

Commit

Permalink
INT - override resolver for gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekschauhan committed Nov 11, 2024
1 parent 92bbe14 commit 19098ff
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/watchmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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
Expand Down Expand Up @@ -87,6 +88,7 @@ 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}),
}

m.logger.
Expand All @@ -97,6 +99,36 @@ 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
Expand Down

0 comments on commit 19098ff

Please sign in to comment.