Skip to content

Commit

Permalink
fix(sdk): ignore invalid notif type (#6153)
Browse files Browse the repository at this point in the history
* fix(sdk): ignore invalid notif type

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Apr 25, 2022
1 parent 607c015 commit 156c3cf
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion engine/api/workflow/workflow_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Parse(ctx context.Context, proj sdk.Project, oldW *sdk.Workflow, ew exporte
log.Debug(ctx, "Parse>> Workflow: %+v", ew)

//Parse workflow
w, errW := exportentities.ParseWorkflow(ew)
w, errW := exportentities.ParseWorkflow(ctx, ew)
if errW != nil {
return nil, sdk.NewError(sdk.ErrWrongRequest, errW)
}
Expand Down
3 changes: 2 additions & 1 deletion sdk/exportentities/v1/workflow_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1_test

import (
"context"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -812,7 +813,7 @@ func TestWorkflow_GetWorkflow(t *testing.T) {
OneAtATime: tt.fields.OneAtATime,
}

got, err := exportentities.ParseWorkflow(w)
got, err := exportentities.ParseWorkflow(context.TODO(), w)
if (err != nil) != tt.wantErr {
t.Errorf("Workflow.GetWorkflow() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
4 changes: 2 additions & 2 deletions sdk/exportentities/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (w Workflow) GetVersion() string {
}

// GetWorkflow returns a fresh sdk.Workflow
func (w Workflow) GetWorkflow() (*sdk.Workflow, error) {
func (w Workflow) GetWorkflow(ctx context.Context) (*sdk.Workflow, error) {
var wf = new(sdk.Workflow)
wf.Name = w.Name
wf.Description = w.Description
Expand Down Expand Up @@ -489,7 +489,7 @@ func (w Workflow) GetWorkflow() (*sdk.Workflow, error) {
}

//Compute notifications
if err := w.processNotifications(wf); err != nil {
if err := w.processNotifications(ctx, wf); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/exportentities/v2/workflow_notif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ notifications:
t.Error("Unmarshal should return an error but it doesn't")
return
}
w, err := exportentities.ParseWorkflow(yamlWorkflow)
w, err := exportentities.ParseWorkflow(context.TODO(), yamlWorkflow)
if err != nil {
if !tst.wantErr {
t.Error("GetWorkflow raised an error", err)
Expand Down
5 changes: 3 additions & 2 deletions sdk/exportentities/v2/workflow_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func ProcessNotificationValues(notif NotificationEntry) (sdk.WorkflowNotificatio
return n, nil
}

func (w *Workflow) processNotifications(wrkflw *sdk.Workflow) error {
func (w *Workflow) processNotifications(ctx context.Context, wrkflw *sdk.Workflow) error {
for _, notif := range w.Notifications {
if notif.Type == sdk.EventsNotification {
if notif.Integration == "" {
Expand All @@ -199,7 +199,8 @@ func (w *Workflow) processNotifications(wrkflw *sdk.Workflow) error {
}
n, err := ProcessNotificationValues(notif)
if err != nil {
return sdk.WrapError(err, "unable to process notification")
log.Error(ctx, "unable to process notification err:", err)
continue
}
n.SourceNodeRefs = notif.Pipelines
wrkflw.Notifications = append(wrkflw.Notifications, n)
Expand Down
6 changes: 3 additions & 3 deletions sdk/exportentities/v2/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func TestWorkflow_GetWorkflow(t *testing.T) {
HistoryLength: &tt.fields.HistoryLength,
RetentionPolicy: &tt.fields.RetentionPolicy,
}
got, err := exportentities.ParseWorkflow(w)
got, err := exportentities.ParseWorkflow(context.TODO(), w)
if (err != nil) != tt.wantErr {
t.Errorf("Workflow.GetWorkflow() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down Expand Up @@ -1077,7 +1077,7 @@ workflow:
t.Error("Unmarshal should return an error but it doesn't")
return
}
w, err := exportentities.ParseWorkflow(yamlWorkflow)
w, err := exportentities.ParseWorkflow(context.TODO(), yamlWorkflow)
if err != nil {
if !tst.wantErr {
t.Error("GetWorkflow raised an error", err)
Expand Down Expand Up @@ -1159,7 +1159,7 @@ notifications:
require.NoError(t, err)

t.Logf("yamlWorkflow> %+v", yamlWorkflow)
_, err = exportentities.ParseWorkflow(yamlWorkflow)
_, err = exportentities.ParseWorkflow(context.TODO(), yamlWorkflow)
require.Error(t, err)
t.Log(err)

Expand Down
4 changes: 2 additions & 2 deletions sdk/exportentities/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func UnmarshalWorkflow(body []byte, format Format) (Workflow, error) {
return nil, sdk.WrapError(sdk.ErrWrongRequest, "invalid workflow version: %s", workflowVersion.Version)
}

func ParseWorkflow(exportWorkflow Workflow) (*sdk.Workflow, error) {
func ParseWorkflow(ctx context.Context, exportWorkflow Workflow) (*sdk.Workflow, error) {
switch exportWorkflow.GetVersion() {
case WorkflowVersion2:
workflowV2, ok := exportWorkflow.(v2.Workflow)
if ok {
return workflowV2.GetWorkflow()
return workflowV2.GetWorkflow(ctx)
}
case WorkflowVersion1:
workflowV1, ok := exportWorkflow.(v1.Workflow)
Expand Down

0 comments on commit 156c3cf

Please sign in to comment.