Skip to content

Commit 5c27d53

Browse files
committed
fix: update constants
1 parent 18fc6ad commit 5c27d53

File tree

2 files changed

+82
-40
lines changed

2 files changed

+82
-40
lines changed

domain/ide/command/ignores_request.go

+81-40
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import (
2020
"context"
2121
"fmt"
2222

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"
2426
"github.com/snyk/snyk-ls/application/config"
2527
"github.com/snyk/snyk-ls/domain/snyk"
2628
"github.com/snyk/snyk-ls/internal/types"
@@ -32,10 +34,6 @@ type submitIgnoreRequest struct {
3234
c *config.Config
3335
}
3436

35-
type IgnoresResponse struct {
36-
SuppressionStatus string
37-
}
38-
3937
func (cmd *submitIgnoreRequest) Command() types.CommandData {
4038
return cmd.command
4139
}
@@ -47,76 +45,119 @@ func (cmd *submitIgnoreRequest) Execute(ctx context.Context) (any, error) {
4745
return nil, fmt.Errorf("workflow type should be a string")
4846
}
4947

48+
issue := cmd.issueProvider.Issue(cmd.command.Arguments[1].(string))
49+
findingsId := issue.GetFindingsId()
50+
contentRoot := issue.GetContentRoot()
51+
5052
switch workflowType {
5153
case "create":
52-
if len(cmd.command.Arguments) < 7 {
54+
if len(cmd.command.Arguments) < 5 {
5355
return nil, fmt.Errorf("insufficient arguments for ignore-create workflow")
5456
}
5557

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+
}
5970

6071
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)
6981
if err != nil && len(result) == 0 {
7082
return nil, fmt.Errorf("failed to invoke ignore-create workflow: %w", err)
7183
}
7284

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))
7590

7691
case "update":
77-
if len(cmd.command.Arguments) < 8 {
92+
if len(cmd.command.Arguments) < 5 {
7893
return nil, fmt.Errorf("insufficient arguments for ignore-edit workflow")
7994
}
8095

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+
}
83112

84113
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)
93124
if err != nil && len(result) == 0 {
94125
return nil, fmt.Errorf("failed to invoke ignore-create workflow: %w", err)
95126
}
96127

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))
99133

100134
case "delete":
101135
if len(cmd.command.Arguments) < 3 {
102136
return nil, fmt.Errorf("insufficient arguments for ignore-delete workflow")
103137
}
104138

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+
}
107143

108144
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)
112150

113-
result, err := engine.InvokeWithConfig(localworkflows.WORKFLOWID_IGNORE_DELETE, gafConfig)
151+
result, err := engine.InvokeWithConfig(ignore_workflow.WORKFLOWID_IGNORE_DELETE, gafConfig)
114152
if err != nil && len(result) == 0 {
115153
return nil, fmt.Errorf("failed to invoke ignore-create workflow: %w", err)
116154
}
117155

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))
120161

121162
default:
122163
return nil, fmt.Errorf(`unkown worflow`)

internal/types/issues.go

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type Issue interface {
8888
GetMessage() string
8989
GetFormattedMessage() string
9090
GetAffectedFilePath() FilePath
91+
GetContentRoot() FilePath
9192
GetIsNew() bool
9293
GetIsIgnored() bool
9394
GetSeverity() Severity

0 commit comments

Comments
 (0)