Skip to content

Commit

Permalink
APIGOV-29235 - override resolver for gRPC (#858)
Browse files Browse the repository at this point in the history
* INT - override resolver for gRPC

* INT - moved resolver builder to utils for reusability
  • Loading branch information
vivekschauhan authored Nov 14, 2024
1 parent 727f972 commit ee300db
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
40 changes: 40 additions & 0 deletions pkg/util/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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() {}
5 changes: 5 additions & 0 deletions pkg/watchmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func (m *watchManager) createConnection() (*grpc.ClientConn, error) {
logrusStreamClientInterceptor(m.options.loggerEntry),
),
grpc.WithUserAgent(m.cfg.UserAgent),
grpc.WithResolvers(
util.CreateCustomGRPCResolverBuilder(
fmt.Sprintf("%s:%d", m.cfg.Host, m.cfg.Port),
m.cfg.Host,
"https")),
}

m.logger.
Expand Down

0 comments on commit ee300db

Please sign in to comment.