Skip to content

Resolve #244 Trigger handler to pass request data to flow #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions trigger/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,22 @@ func HandlerFromContext(ctx context.Context) (*HandlerInfo, bool) {
u, ok := ctx.Value(handlerKey).(*HandlerInfo)
return u, ok
}

// This allows trigger developer to pass request parameters to handler w/o going through output mapper, e.g.,
// ctx := trigger.NewContextWithValues(context.Background(), values)
// results, err := handler.Handle(ctx, triggerData.ToMap())

type valueKey string

const contextValueKey valueKey = "values"

// NewContextWithValues returns a new Context that carries specified request parameter values
func NewContextWithValues(ctx context.Context, values map[string]interface{}) context.Context {
return context.WithValue(ctx, contextValueKey, values)
}

// ValuesFromContext extracts request parameters from a context
func ValuesFromContext(ctx context.Context) (map[string]interface{}, bool) {
values, ok := ctx.Value(contextValueKey).(map[string]interface{})
return values, ok
}
7 changes: 7 additions & 0 deletions trigger/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ func (h *handlerImpl) Handle(ctx context.Context, triggerData interface{}) (resu
inputMap = triggerValues
}

// extract request parameters from trigger context, and make them available in actions
if reqParams, ok := ValuesFromContext(ctx); ok {
for k, v := range reqParams {
inputMap[k] = v
}
}

if ioMd := act.act.IOMetadata(); ioMd != nil {
for name, tv := range ioMd.Input {
if val, ok := inputMap[name]; ok {
Expand Down