Skip to content

Commit

Permalink
RE-3424: Add GAPv2 required repo header (#15988)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriosNaikopoulos authored Jan 21, 2025
1 parent 87e0fdf commit c430b5b
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions deployment/environment/devenv/jd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ import (
"github.com/smartcontractkit/chainlink/deployment"
)

type GAPConfig struct {
Token string
Repository string
}

type JDConfig struct {
GRPC string
WSRPC string
Creds credentials.TransportCredentials
Auth oauth2.TokenSource
GAP string
GAP *GAPConfig
NodeInfo []NodeInfo
}

Expand Down Expand Up @@ -62,6 +67,22 @@ func gapTokenInterceptor(token string) grpc.UnaryClientInterceptor {
}
}

func gapRepositoryInterceptor(repository string) grpc.UnaryClientInterceptor {
return func(
ctx context.Context,
method string,
req, reply any,
cc *grpc.ClientConn,
invoker grpc.UnaryInvoker,
opts ...grpc.CallOption,
) error {
return invoker(
metadata.AppendToOutgoingContext(ctx, "x-repository", repository),
method, req, reply, cc, opts...,
)
}
}

func NewJDConnection(cfg JDConfig) (*grpc.ClientConn, error) {
opts := []grpc.DialOption{}
interceptors := []grpc.UnaryClientInterceptor{}
Expand All @@ -72,8 +93,8 @@ func NewJDConnection(cfg JDConfig) (*grpc.ClientConn, error) {
if cfg.Auth != nil {
interceptors = append(interceptors, authTokenInterceptor(cfg.Auth))
}
if cfg.GAP != "" {
interceptors = append(interceptors, gapTokenInterceptor(cfg.GAP))
if cfg.GAP != nil && cfg.GAP.Token != "" && cfg.GAP.Repository != "" {
interceptors = append(interceptors, gapTokenInterceptor(cfg.GAP.Token), gapRepositoryInterceptor(cfg.GAP.Repository))
}

if len(interceptors) > 0 {
Expand Down

0 comments on commit c430b5b

Please sign in to comment.