Skip to content

Commit c8cd5fe

Browse files
committed
Merge branch 'main' into cre-1601-shard-orchestrator-plugin
2 parents 287bf71 + 2df013c commit c8cd5fe

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

pkg/capabilities/capabilities.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ type RequestMetadata struct {
117117
}
118118

119119
func (m *RequestMetadata) ContextWithCRE(ctx context.Context) context.Context {
120-
return contexts.WithCRE(ctx, contexts.CRE{
121-
Owner: m.WorkflowOwner,
122-
Workflow: m.WorkflowID,
123-
})
120+
val := contexts.CREValue(ctx)
121+
// preserve org, if set
122+
val.Owner = m.WorkflowOwner
123+
val.Workflow = m.WorkflowID
124+
return contexts.WithCRE(ctx, val)
124125
}
125126

126127
type RegistrationMetadata struct {
@@ -131,10 +132,11 @@ type RegistrationMetadata struct {
131132
}
132133

133134
func (m *RegistrationMetadata) ContextWithCRE(ctx context.Context) context.Context {
134-
return contexts.WithCRE(ctx, contexts.CRE{
135-
Owner: m.WorkflowOwner,
136-
Workflow: m.WorkflowID,
137-
})
135+
val := contexts.CREValue(ctx)
136+
// preserve org, if set
137+
val.Owner = m.WorkflowOwner
138+
val.Workflow = m.WorkflowID
139+
return contexts.WithCRE(ctx, val)
138140
}
139141

140142
// CapabilityRequest is a struct for the Execute request of a capability.

pkg/capabilities/capabilities_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
1313

14+
"github.com/smartcontractkit/chainlink-common/pkg/contexts"
1415
"github.com/smartcontractkit/chainlink-protos/cre/go/values"
1516
)
1617

@@ -331,3 +332,31 @@ func TestChainSelectorLabel(t *testing.T) {
331332
}
332333

333334
func ptr[T any](v T) *T { return &v }
335+
336+
func TestRequestMetadata_ContextWithCRE(t *testing.T) {
337+
ctx := t.Context()
338+
require.Equal(t, "", contexts.CREValue(ctx).Org)
339+
340+
// set it
341+
ctx = contexts.WithCRE(ctx, contexts.CRE{Org: "org-id"})
342+
require.Equal(t, "org-id", contexts.CREValue(ctx).Org)
343+
344+
// preserve it
345+
md := RequestMetadata{WorkflowOwner: "owner-id", WorkflowID: "workflow-id"}
346+
ctx = md.ContextWithCRE(ctx)
347+
require.Equal(t, "org-id", contexts.CREValue(ctx).Org)
348+
}
349+
350+
func TestRegistrationMetadata_ContextWithCRE(t *testing.T) {
351+
ctx := t.Context()
352+
require.Equal(t, "", contexts.CREValue(ctx).Org)
353+
354+
// set it
355+
ctx = contexts.WithCRE(ctx, contexts.CRE{Org: "org-id"})
356+
require.Equal(t, "org-id", contexts.CREValue(ctx).Org)
357+
358+
// preserve it
359+
md := RegistrationMetadata{WorkflowOwner: "owner-id", WorkflowID: "workflow-id"}
360+
ctx = md.ContextWithCRE(ctx)
361+
require.Equal(t, "org-id", contexts.CREValue(ctx).Org)
362+
}

0 commit comments

Comments
 (0)