@@ -20,7 +20,9 @@ import (
20
20
"context"
21
21
"fmt"
22
22
23
- localworkflows "github.com/snyk/go-application-framework/pkg/local_workflows"
23
+ "github.com/snyk/code-client-go/sarif"
24
+ "github.com/snyk/go-application-framework/pkg/configuration"
25
+ "github.com/snyk/go-application-framework/pkg/local_workflows/ignore_workflow"
24
26
"github.com/snyk/snyk-ls/application/config"
25
27
"github.com/snyk/snyk-ls/domain/snyk"
26
28
"github.com/snyk/snyk-ls/internal/types"
@@ -32,10 +34,6 @@ type submitIgnoreRequest struct {
32
34
c * config.Config
33
35
}
34
36
35
- type IgnoresResponse struct {
36
- SuppressionStatus string
37
- }
38
-
39
37
func (cmd * submitIgnoreRequest ) Command () types.CommandData {
40
38
return cmd .command
41
39
}
@@ -47,76 +45,119 @@ func (cmd *submitIgnoreRequest) Execute(ctx context.Context) (any, error) {
47
45
return nil , fmt .Errorf ("workflow type should be a string" )
48
46
}
49
47
48
+ issue := cmd .issueProvider .Issue (cmd .command .Arguments [1 ].(string ))
49
+ findingsId := issue .GetFindingsId ()
50
+ contentRoot := issue .GetContentRoot ()
51
+
50
52
switch workflowType {
51
53
case "create" :
52
- if len (cmd .command .Arguments ) < 7 {
54
+ if len (cmd .command .Arguments ) < 5 {
53
55
return nil , fmt .Errorf ("insufficient arguments for ignore-create workflow" )
54
56
}
55
57
56
- issue := cmd .issueProvider .Issue (cmd .command .Arguments [1 ].(string ))
57
-
58
- findingsId := issue .GetFindingsId ()
58
+ ignoreType , ok := cmd .command .Arguments [2 ].(string )
59
+ if ! ok {
60
+ return nil , fmt .Errorf ("ignoreType should be a string" )
61
+ }
62
+ reason , ok := cmd .command .Arguments [3 ].(string )
63
+ if ! ok {
64
+ return nil , fmt .Errorf ("reason should be a string" )
65
+ }
66
+ expiration , ok := cmd .command .Arguments [4 ].(string )
67
+ if ! ok {
68
+ return nil , fmt .Errorf ("expiration should be a string" )
69
+ }
59
70
60
71
gafConfig := engine .GetConfiguration ().Clone ()
61
- gafConfig .Set ("id" , findingsId )
62
- gafConfig .Set ("ignoreType" , cmd .command .Arguments [2 ].(string ))
63
- gafConfig .Set ("reason" , cmd .command .Arguments [3 ].(string ))
64
- gafConfig .Set ("expiration" , cmd .command .Arguments [4 ].(string ))
65
- gafConfig .Set ("enrichResponse" , true )
66
- gafConfig .Set ("interactive" , false )
67
-
68
- result , err := engine .InvokeWithConfig (localworkflows .WORKFLOWID_IGNORE_CREATE , gafConfig )
72
+ gafConfig .Set (ignore_workflow .FindingsIdKey , findingsId )
73
+ gafConfig .Set (ignore_workflow .IgnoreTypeKey , ignoreType )
74
+ gafConfig .Set (ignore_workflow .ReasonKey , reason )
75
+ gafConfig .Set (ignore_workflow .ExpirationKey , expiration )
76
+ gafConfig .Set (ignore_workflow .EnrichResponseKey , true )
77
+ gafConfig .Set (ignore_workflow .InteractiveKey , false )
78
+ gafConfig .Set (configuration .INPUT_DIRECTORY , contentRoot )
79
+
80
+ result , err := engine .InvokeWithConfig (ignore_workflow .WORKFLOWID_IGNORE_CREATE , gafConfig )
69
81
if err != nil && len (result ) == 0 {
70
82
return nil , fmt .Errorf ("failed to invoke ignore-create workflow: %w" , err )
71
83
}
72
84
73
- response := result [0 ].GetPayload ().(IgnoresResponse )
74
- issue .SetSuppressionStatus (response .SuppressionStatus )
85
+ suppressionResponse , ok := result [0 ].GetPayload ().(* sarif.Suppression )
86
+ if ! ok {
87
+ return nil , fmt .Errorf ("unexpected payload type: expected *sarif.Suppression" )
88
+ }
89
+ issue .SetSuppressionStatus (string (suppressionResponse .Status ))
75
90
76
91
case "update" :
77
- if len (cmd .command .Arguments ) < 8 {
92
+ if len (cmd .command .Arguments ) < 5 {
78
93
return nil , fmt .Errorf ("insufficient arguments for ignore-edit workflow" )
79
94
}
80
95
81
- issue := cmd .issueProvider .Issue (cmd .command .Arguments [1 ].(string ))
82
- findingsId := issue .GetFindingsId ()
96
+ ignoreType , ok := cmd .command .Arguments [2 ].(string )
97
+ if ! ok {
98
+ return nil , fmt .Errorf ("ignoreType should be a string" )
99
+ }
100
+ reason , ok := cmd .command .Arguments [3 ].(string )
101
+ if ! ok {
102
+ return nil , fmt .Errorf ("reason should be a string" )
103
+ }
104
+ expiration , ok := cmd .command .Arguments [4 ].(string )
105
+ if ! ok {
106
+ return nil , fmt .Errorf ("expiration should be a string" )
107
+ }
108
+ ignoreId , ok := cmd .command .Arguments [5 ].(string )
109
+ if ! ok {
110
+ return nil , fmt .Errorf ("ignoreId should be a string" )
111
+ }
83
112
84
113
gafConfig := engine .GetConfiguration ().Clone ()
85
- gafConfig .Set ("id" , findingsId )
86
- gafConfig .Set ("ignoreType" , cmd .command .Arguments [2 ].(string ))
87
- gafConfig .Set ("reason" , cmd .command .Arguments [3 ].(string ))
88
- gafConfig .Set ("expiration" , cmd .command .Arguments [4 ].(string ))
89
- gafConfig .Set ("enrichResponse" , true )
90
- gafConfig .Set ("interactive" , false )
91
-
92
- result , err := engine .InvokeWithConfig (localworkflows .WORKFLOWID_IGNORE_EDIT , gafConfig )
114
+ gafConfig .Set (ignore_workflow .FindingsIdKey , findingsId )
115
+ gafConfig .Set (ignore_workflow .IgnoreTypeKey , ignoreType )
116
+ gafConfig .Set (ignore_workflow .ReasonKey , reason )
117
+ gafConfig .Set (ignore_workflow .ExpirationKey , expiration )
118
+ gafConfig .Set (ignore_workflow .EnrichResponseKey , true )
119
+ gafConfig .Set (ignore_workflow .InteractiveKey , false )
120
+ gafConfig .Set (ignore_workflow .IgnoreIdKey , ignoreId )
121
+ gafConfig .Set (configuration .INPUT_DIRECTORY , contentRoot )
122
+
123
+ result , err := engine .InvokeWithConfig (ignore_workflow .WORKFLOWID_IGNORE_EDIT , gafConfig )
93
124
if err != nil && len (result ) == 0 {
94
125
return nil , fmt .Errorf ("failed to invoke ignore-create workflow: %w" , err )
95
126
}
96
127
97
- response := result [0 ].GetPayload ().(IgnoresResponse )
98
- issue .SetSuppressionStatus (response .SuppressionStatus )
128
+ suppressionResponse , ok := result [0 ].GetPayload ().(* sarif.Suppression )
129
+ if ! ok {
130
+ return nil , fmt .Errorf ("unexpected payload type: expected *sarif.Suppression" )
131
+ }
132
+ issue .SetSuppressionStatus (string (suppressionResponse .Status ))
99
133
100
134
case "delete" :
101
135
if len (cmd .command .Arguments ) < 3 {
102
136
return nil , fmt .Errorf ("insufficient arguments for ignore-delete workflow" )
103
137
}
104
138
105
- issue := cmd .issueProvider .Issue (cmd .command .Arguments [1 ].(string ))
106
- findingsId := issue .GetFindingsId ()
139
+ ignoreId , ok := cmd .command .Arguments [5 ].(string )
140
+ if ! ok {
141
+ return nil , fmt .Errorf ("ignoreId should be a string" )
142
+ }
107
143
108
144
gafConfig := engine .GetConfiguration ().Clone ()
109
- gafConfig .Set ("id" , findingsId )
110
- gafConfig .Set ("enrichResponse" , true )
111
- gafConfig .Set ("interactive" , false )
145
+ gafConfig .Set (ignore_workflow .FindingsIdKey , findingsId ) //TODO remove this one?
146
+ gafConfig .Set (ignore_workflow .IgnoreIdKey , ignoreId )
147
+ gafConfig .Set (ignore_workflow .EnrichResponseKey , true )
148
+ gafConfig .Set (ignore_workflow .InteractiveKey , false )
149
+ gafConfig .Set (configuration .INPUT_DIRECTORY , contentRoot )
112
150
113
- result , err := engine .InvokeWithConfig (localworkflows .WORKFLOWID_IGNORE_DELETE , gafConfig )
151
+ result , err := engine .InvokeWithConfig (ignore_workflow .WORKFLOWID_IGNORE_DELETE , gafConfig )
114
152
if err != nil && len (result ) == 0 {
115
153
return nil , fmt .Errorf ("failed to invoke ignore-create workflow: %w" , err )
116
154
}
117
155
118
- response := result [0 ].GetPayload ().(IgnoresResponse )
119
- issue .SetSuppressionStatus (response .SuppressionStatus )
156
+ suppressionResponse , ok := result [0 ].GetPayload ().(* sarif.Suppression )
157
+ if ! ok {
158
+ return nil , fmt .Errorf ("unexpected payload type: expected *sarif.Suppression" )
159
+ }
160
+ issue .SetSuppressionStatus (string (suppressionResponse .Status ))
120
161
121
162
default :
122
163
return nil , fmt .Errorf (`unkown worflow` )
0 commit comments