Skip to content

Commit 7e5c3d0

Browse files
authored
Merge branch 'main' into modgraph
2 parents e07925a + b468c90 commit 7e5c3d0

File tree

3 files changed

+21
-32
lines changed

3 files changed

+21
-32
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+
}

pkg/capabilities/v2/protoc/pkg/template_generator.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (t *TemplateGenerator) Generate(
9191
func (t *TemplateGenerator) runTemplate(name, tmplText string, args any, partials map[string]string, importToPkg map[protogen.GoImportPath]protogen.GoPackageName) (string, error) {
9292
buf := &bytes.Buffer{}
9393
imports := map[string]bool{}
94+
var orderedImports []string
9495
if t.ExtraFns == nil {
9596
t.ExtraFns = template.FuncMap{}
9697
}
@@ -146,14 +147,16 @@ func (t *TemplateGenerator) runTemplate(name, tmplText string, args any, partial
146147
importName = fmt.Sprintf("%s %s", importToPkg[importPath], importName)
147148
}
148149

149-
imports[importName] = true
150+
if !imports[importName] {
151+
orderedImports = append(orderedImports, importName)
152+
imports[importName] = true
153+
}
154+
150155
return ""
151156
},
152157
"allimports": func() []string {
153-
var allImports []string
154-
for i := range imports {
155-
allImports = append(allImports, i)
156-
}
158+
allImports := make([]string, len(imports))
159+
copy(allImports, orderedImports)
157160
return allImports
158161
},
159162
"name": func(ident protogen.GoIdent, ignore string) string {

0 commit comments

Comments
 (0)