Skip to content

Commit

Permalink
Fix trigger loading on workflow execution
Browse files Browse the repository at this point in the history
Triggers are now loaded directly from store and
without access control
  • Loading branch information
darh committed Sep 23, 2021
1 parent 49f86f9 commit 3515cf2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 14 additions & 2 deletions automation/service/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,24 @@ func (svc *trigger) unregisterTriggers(tt ...*types.Trigger) {
}
}

func loadTrigger(ctx context.Context, s store.Storer, workflowID uint64) (res *types.Trigger, err error) {
func loadTrigger(ctx context.Context, s store.Storer, triggerID uint64) (res *types.Trigger, err error) {
if triggerID == 0 {
return nil, TriggerErrInvalidID()
}

if res, err = store.LookupAutomationTriggerByID(ctx, s, triggerID); errors.IsNotFound(err) {
return nil, TriggerErrNotFound()
}

return
}

func loadWorkflowTriggers(ctx context.Context, s store.Storer, workflowID uint64) (tt types.TriggerSet, err error) {
if workflowID == 0 {
return nil, TriggerErrInvalidID()
}

if res, err = store.LookupAutomationTriggerByID(ctx, s, workflowID); errors.IsNotFound(err) {
if tt, _, err = store.SearchAutomationTriggers(ctx, s, types.TriggerFilter{WorkflowID: []uint64{workflowID}}); errors.IsNotFound(err) {
return nil, TriggerErrNotFound()
}

Expand Down
8 changes: 7 additions & 1 deletion automation/service/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,9 @@ func (svc *workflow) Exec(ctx context.Context, workflowID uint64, p types.Workfl
// Find the trigger.
t, err = func() (*types.Trigger, error) {
var tt types.TriggerSet
tt, _, err = svc.triggers.Search(ctx, types.TriggerFilter{WorkflowID: []uint64{workflowID}})
// Load triggers directly from the store. At this point we do not care
// about trigger search or read permissions
tt, err = loadWorkflowTriggers(ctx, svc.store, workflowID)
if err != nil {
return nil, err
}
Expand All @@ -539,6 +541,10 @@ func (svc *workflow) Exec(ctx context.Context, workflowID uint64, p types.Workfl
return nil, nil
}()

if err != nil {
return
}

// Start with workflow scope
scope := wf.Scope.MustMerge()

Expand Down

0 comments on commit 3515cf2

Please sign in to comment.