Skip to content

Commit b0c67b6

Browse files
Merge branch 'main' into chore/update-cap-don-type-v2
2 parents 440c09a + 6d6d46a commit b0c67b6

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

pkg/billing/workflow_client.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ type workflowConfig struct {
5353
type WorkflowClientOpt func(*workflowConfig)
5454

5555
func defaultWorkflowConfig() workflowConfig {
56-
loggerInst, _ := logger.New()
5756
// By default, no JWT manager is set and we fallback to insecure creds.
5857
return workflowConfig{
5958
transportCredentials: insecure.NewCredentials(),
60-
log: loggerInst,
6159
tlsCert: "",
6260
// Default to "localhost" if not overridden.
6361
serverName: "localhost",
@@ -71,12 +69,6 @@ func WithWorkflowTransportCredentials(creds credentials.TransportCredentials) Wo
7169
}
7270
}
7371

74-
func WithWorkflowLogger(l logger.Logger) WorkflowClientOpt {
75-
return func(cfg *workflowConfig) {
76-
cfg.log = l
77-
}
78-
}
79-
8072
// WithJWTGenerator sets the JWT generator for authentication.
8173
func WithJWTGenerator(jwtGenerator auth.JWTGenerator) WorkflowClientOpt {
8274
return func(cfg *workflowConfig) {
@@ -98,15 +90,15 @@ func WithServerName(name string) WorkflowClientOpt {
9890
}
9991

10092
// NewWorkflowClient creates a new workflow client with JWT signing enabled.
101-
func NewWorkflowClient(address string, opts ...WorkflowClientOpt) (WorkflowClient, error) {
93+
func NewWorkflowClient(lggr logger.Logger, address string, opts ...WorkflowClientOpt) (WorkflowClient, error) {
10294
cfg := defaultWorkflowConfig()
10395
for _, opt := range opts {
10496
opt(&cfg)
10597
}
10698

10799
wc := &workflowClient{
108100
address: address,
109-
logger: cfg.log,
101+
logger: logger.Named(lggr, "WorkflowClient"),
110102
tlsCert: cfg.tlsCert,
111103
creds: cfg.transportCredentials,
112104
serverName: cfg.serverName,

pkg/billing/workflow_client_test.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"google.golang.org/grpc/metadata"
1717
"google.golang.org/protobuf/types/known/emptypb"
1818

19-
"github.com/smartcontractkit/chainlink-common/pkg/nodeauth/jwt/mocks"
2019
"github.com/smartcontractkit/chainlink-common/pkg/logger"
20+
"github.com/smartcontractkit/chainlink-common/pkg/nodeauth/jwt/mocks"
2121
pb "github.com/smartcontractkit/chainlink-protos/billing/go"
2222
)
2323

@@ -30,7 +30,6 @@ func (d MockRequest) String() string {
3030
return d.Field
3131
}
3232

33-
3433
// ---------- Test Server Implementation ----------
3534

3635
// testWorkflowServer implements pb.WorkflowServiceServer for testing.
@@ -101,11 +100,10 @@ func TestIntegration_GRPCWithCerts(t *testing.T) {
101100
mockJWT.EXPECT().CreateJWTForRequest(&pb.GetRateCardRequest{WorkflowOwner: "test-account", WorkflowRegistryAddress: "0x..", ChainSelector: 1}).Return("test.jwt.token", nil).Once()
102101

103102
lggr := logger.Test(t)
104-
wc, err := NewWorkflowClient(addr,
103+
wc, err := NewWorkflowClient(lggr, addr,
105104
WithWorkflowTransportCredentials(clientCreds), // Provided but may be overridden by TLS cert.
106105
WithWorkflowTLSCert(string(certBytes)),
107106
WithJWTGenerator(mockJWT),
108-
WithWorkflowLogger(lggr),
109107
WithServerName("localhost"),
110108
)
111109
require.NoError(t, err)
@@ -153,9 +151,8 @@ func TestIntegration_GRPC_Insecure(t *testing.T) {
153151
addr := lis.Addr().String()
154152
lggr := logger.Test(t)
155153

156-
wc, err := NewWorkflowClient(addr,
154+
wc, err := NewWorkflowClient(lggr, addr,
157155
WithWorkflowTransportCredentials(insecure.NewCredentials()),
158-
WithWorkflowLogger(lggr),
159156
WithServerName("localhost"),
160157
)
161158

@@ -170,9 +167,8 @@ func TestIntegration_GRPC_Insecure(t *testing.T) {
170167
// Test that NewWorkflowClient fails when given an invalid address.
171168
func TestNewWorkflowClient_InvalidAddress(t *testing.T) {
172169
lggr := logger.Test(t)
173-
wc, err := NewWorkflowClient("invalid-address",
170+
wc, err := NewWorkflowClient(lggr, "invalid-address",
174171
WithWorkflowTransportCredentials(insecure.NewCredentials()),
175-
WithWorkflowLogger(lggr),
176172
WithServerName("localhost"),
177173
)
178174

@@ -196,9 +192,8 @@ func TestWorkflowClient_CloseTwice(t *testing.T) {
196192

197193
addr := lis.Addr().String()
198194
lggr := logger.Test(t)
199-
wc, err := NewWorkflowClient(addr,
195+
wc, err := NewWorkflowClient(lggr, addr,
200196
WithWorkflowTransportCredentials(insecure.NewCredentials()),
201-
WithWorkflowLogger(lggr),
202197
WithServerName("localhost"),
203198
)
204199
require.NoError(t, err)
@@ -215,9 +210,8 @@ func TestWorkflowClient_CloseTwice(t *testing.T) {
215210
func TestWorkflowClient_DialUnreachable(t *testing.T) {
216211
lggr := logger.Test(t)
217212
unreachableAddr := "192.0.2.1:12345" // Reserved for documentation.
218-
wc, err := NewWorkflowClient(unreachableAddr,
213+
wc, err := NewWorkflowClient(lggr, unreachableAddr,
219214
WithWorkflowTransportCredentials(insecure.NewCredentials()),
220-
WithWorkflowLogger(lggr),
221215
WithServerName("localhost"),
222216
)
223217

@@ -240,7 +234,7 @@ func TestWorkflowClient_AddJWTAuthToContext(t *testing.T) {
240234
mockJWT.EXPECT().CreateJWTForRequest(req).Return(expectedToken, nil).Once()
241235

242236
wc := &workflowClient{
243-
logger: logger.Test(t),
237+
logger: logger.Test(t),
244238
jwtGenerator: mockJWT,
245239
}
246240

@@ -263,7 +257,7 @@ func TestWorkflowClient_NoSigningKey(t *testing.T) {
263257
ctx := context.Background()
264258
req := MockRequest{Field: "test"}
265259
wc := &workflowClient{
266-
logger: logger.Test(t),
260+
logger: logger.Test(t),
267261
jwtGenerator: nil,
268262
}
269263
newCtx, err := wc.addJWTAuth(ctx, req)
@@ -281,7 +275,7 @@ func TestWorkflowClient_VerifySignature_Invalid(t *testing.T) {
281275
mockJWT.EXPECT().CreateJWTForRequest(req).Return("", fmt.Errorf("mock JWT creation error")).Once()
282276

283277
wc := &workflowClient{
284-
logger: logger.Test(t),
278+
logger: logger.Test(t),
285279
jwtGenerator: mockJWT,
286280
}
287281

@@ -300,7 +294,7 @@ func TestWorkflowClient_RepeatedSign(t *testing.T) {
300294
mockJWT.EXPECT().CreateJWTForRequest(req).Return(expectedToken, nil).Times(2)
301295

302296
wc := &workflowClient{
303-
logger: logger.Test(t),
297+
logger: logger.Test(t),
304298
jwtGenerator: mockJWT,
305299
}
306300

@@ -319,4 +313,4 @@ func TestWorkflowClient_RepeatedSign(t *testing.T) {
319313
require.True(t, ok)
320314

321315
assert.Equal(t, md1["authorization"], md2["authorization"], "Expected same authorization header for same request")
322-
}
316+
}

0 commit comments

Comments
 (0)