Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions pkg/capabilities/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ type RequestMetadata struct {
}

func (m *RequestMetadata) ContextWithCRE(ctx context.Context) context.Context {
return contexts.WithCRE(ctx, contexts.CRE{
Owner: m.WorkflowOwner,
Workflow: m.WorkflowID,
})
val := contexts.CREValue(ctx)
// preserve org, if set
val.Owner = m.WorkflowOwner
val.Workflow = m.WorkflowID
return contexts.WithCRE(ctx, val)
}

type RegistrationMetadata struct {
Expand All @@ -131,10 +132,11 @@ type RegistrationMetadata struct {
}

func (m *RegistrationMetadata) ContextWithCRE(ctx context.Context) context.Context {
return contexts.WithCRE(ctx, contexts.CRE{
Owner: m.WorkflowOwner,
Workflow: m.WorkflowID,
})
val := contexts.CREValue(ctx)
// preserve org, if set
val.Owner = m.WorkflowOwner
val.Workflow = m.WorkflowID
return contexts.WithCRE(ctx, val)
}

// CapabilityRequest is a struct for the Execute request of a capability.
Expand Down
29 changes: 29 additions & 0 deletions pkg/capabilities/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/contexts"
"github.com/smartcontractkit/chainlink-protos/cre/go/values"
)

Expand Down Expand Up @@ -331,3 +332,31 @@ func TestChainSelectorLabel(t *testing.T) {
}

func ptr[T any](v T) *T { return &v }

func TestRequestMetadata_ContextWithCRE(t *testing.T) {
ctx := t.Context()
require.Equal(t, "", contexts.CREValue(ctx).Org)

// set it
ctx = contexts.WithCRE(ctx, contexts.CRE{Org: "org-id"})
require.Equal(t, "org-id", contexts.CREValue(ctx).Org)

// preserve it
md := RequestMetadata{WorkflowOwner: "owner-id", WorkflowID: "workflow-id"}
ctx = md.ContextWithCRE(ctx)
require.Equal(t, "org-id", contexts.CREValue(ctx).Org)
}

func TestRegistrationMetadata_ContextWithCRE(t *testing.T) {
ctx := t.Context()
require.Equal(t, "", contexts.CREValue(ctx).Org)

// set it
ctx = contexts.WithCRE(ctx, contexts.CRE{Org: "org-id"})
require.Equal(t, "org-id", contexts.CREValue(ctx).Org)

// preserve it
md := RegistrationMetadata{WorkflowOwner: "owner-id", WorkflowID: "workflow-id"}
ctx = md.ContextWithCRE(ctx)
require.Equal(t, "org-id", contexts.CREValue(ctx).Org)
}
Loading