Skip to content

Commit 156c3cf

Browse files
authored
fix(sdk): ignore invalid notif type (#6153)
* fix(sdk): ignore invalid notif type Signed-off-by: Yvonnick Esnault <[email protected]>
1 parent 607c015 commit 156c3cf

File tree

7 files changed

+14
-12
lines changed

7 files changed

+14
-12
lines changed

engine/api/workflow/workflow_parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Parse(ctx context.Context, proj sdk.Project, oldW *sdk.Workflow, ew exporte
3232
log.Debug(ctx, "Parse>> Workflow: %+v", ew)
3333

3434
//Parse workflow
35-
w, errW := exportentities.ParseWorkflow(ew)
35+
w, errW := exportentities.ParseWorkflow(ctx, ew)
3636
if errW != nil {
3737
return nil, sdk.NewError(sdk.ErrWrongRequest, errW)
3838
}

sdk/exportentities/v1/workflow_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1_test
22

33
import (
4+
"context"
45
"sort"
56
"strings"
67
"testing"
@@ -812,7 +813,7 @@ func TestWorkflow_GetWorkflow(t *testing.T) {
812813
OneAtATime: tt.fields.OneAtATime,
813814
}
814815

815-
got, err := exportentities.ParseWorkflow(w)
816+
got, err := exportentities.ParseWorkflow(context.TODO(), w)
816817
if (err != nil) != tt.wantErr {
817818
t.Errorf("Workflow.GetWorkflow() error = %v, wantErr %v", err, tt.wantErr)
818819
return

sdk/exportentities/v2/workflow.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func (w Workflow) GetVersion() string {
402402
}
403403

404404
// GetWorkflow returns a fresh sdk.Workflow
405-
func (w Workflow) GetWorkflow() (*sdk.Workflow, error) {
405+
func (w Workflow) GetWorkflow(ctx context.Context) (*sdk.Workflow, error) {
406406
var wf = new(sdk.Workflow)
407407
wf.Name = w.Name
408408
wf.Description = w.Description
@@ -489,7 +489,7 @@ func (w Workflow) GetWorkflow() (*sdk.Workflow, error) {
489489
}
490490

491491
//Compute notifications
492-
if err := w.processNotifications(wf); err != nil {
492+
if err := w.processNotifications(ctx, wf); err != nil {
493493
return nil, err
494494
}
495495

sdk/exportentities/v2/workflow_notif_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ notifications:
250250
t.Error("Unmarshal should return an error but it doesn't")
251251
return
252252
}
253-
w, err := exportentities.ParseWorkflow(yamlWorkflow)
253+
w, err := exportentities.ParseWorkflow(context.TODO(), yamlWorkflow)
254254
if err != nil {
255255
if !tst.wantErr {
256256
t.Error("GetWorkflow raised an error", err)

sdk/exportentities/v2/workflow_notification.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func ProcessNotificationValues(notif NotificationEntry) (sdk.WorkflowNotificatio
186186
return n, nil
187187
}
188188

189-
func (w *Workflow) processNotifications(wrkflw *sdk.Workflow) error {
189+
func (w *Workflow) processNotifications(ctx context.Context, wrkflw *sdk.Workflow) error {
190190
for _, notif := range w.Notifications {
191191
if notif.Type == sdk.EventsNotification {
192192
if notif.Integration == "" {
@@ -199,7 +199,8 @@ func (w *Workflow) processNotifications(wrkflw *sdk.Workflow) error {
199199
}
200200
n, err := ProcessNotificationValues(notif)
201201
if err != nil {
202-
return sdk.WrapError(err, "unable to process notification")
202+
log.Error(ctx, "unable to process notification err:", err)
203+
continue
203204
}
204205
n.SourceNodeRefs = notif.Pipelines
205206
wrkflw.Notifications = append(wrkflw.Notifications, n)

sdk/exportentities/v2/workflow_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ func TestWorkflow_GetWorkflow(t *testing.T) {
642642
HistoryLength: &tt.fields.HistoryLength,
643643
RetentionPolicy: &tt.fields.RetentionPolicy,
644644
}
645-
got, err := exportentities.ParseWorkflow(w)
645+
got, err := exportentities.ParseWorkflow(context.TODO(), w)
646646
if (err != nil) != tt.wantErr {
647647
t.Errorf("Workflow.GetWorkflow() error = %v, wantErr %v", err, tt.wantErr)
648648
return
@@ -1077,7 +1077,7 @@ workflow:
10771077
t.Error("Unmarshal should return an error but it doesn't")
10781078
return
10791079
}
1080-
w, err := exportentities.ParseWorkflow(yamlWorkflow)
1080+
w, err := exportentities.ParseWorkflow(context.TODO(), yamlWorkflow)
10811081
if err != nil {
10821082
if !tst.wantErr {
10831083
t.Error("GetWorkflow raised an error", err)
@@ -1159,7 +1159,7 @@ notifications:
11591159
require.NoError(t, err)
11601160

11611161
t.Logf("yamlWorkflow> %+v", yamlWorkflow)
1162-
_, err = exportentities.ParseWorkflow(yamlWorkflow)
1162+
_, err = exportentities.ParseWorkflow(context.TODO(), yamlWorkflow)
11631163
require.Error(t, err)
11641164
t.Log(err)
11651165

sdk/exportentities/workflow.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ func UnmarshalWorkflow(body []byte, format Format) (Workflow, error) {
7171
return nil, sdk.WrapError(sdk.ErrWrongRequest, "invalid workflow version: %s", workflowVersion.Version)
7272
}
7373

74-
func ParseWorkflow(exportWorkflow Workflow) (*sdk.Workflow, error) {
74+
func ParseWorkflow(ctx context.Context, exportWorkflow Workflow) (*sdk.Workflow, error) {
7575
switch exportWorkflow.GetVersion() {
7676
case WorkflowVersion2:
7777
workflowV2, ok := exportWorkflow.(v2.Workflow)
7878
if ok {
79-
return workflowV2.GetWorkflow()
79+
return workflowV2.GetWorkflow(ctx)
8080
}
8181
case WorkflowVersion1:
8282
workflowV1, ok := exportWorkflow.(v1.Workflow)

0 commit comments

Comments
 (0)