Skip to content

Commit f363d4f

Browse files
committed
fix: refactor shared types and constants to sast_contract
1 parent d07bc92 commit f363d4f

File tree

8 files changed

+27
-30
lines changed

8 files changed

+27
-30
lines changed

domain/ide/command/sast_enabled.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package command
1818

1919
import (
2020
"context"
21-
"github.com/snyk/go-application-framework/pkg/configuration"
21+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow"
2222
"github.com/snyk/snyk-ls/application/config"
2323

2424
"github.com/rs/zerolog"
@@ -47,7 +47,7 @@ func (cmd *sastEnabled) Execute(_ context.Context) (any, error) {
4747
}
4848

4949
gafConfig := cmd.c.Engine().GetConfiguration()
50-
sastResponse := gafConfig.Get(configuration.SAST_SETTINGS)
50+
sastResponse := gafConfig.Get(code_workflow.ConfigurationSastSettings)
5151

5252
return sastResponse, nil
5353
}

domain/ide/command/sast_enabled_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package command
1818

1919
import (
2020
"context"
21+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow"
2122
"testing"
2223

2324
"github.com/stretchr/testify/assert"
@@ -28,8 +29,6 @@ import (
2829
"github.com/snyk/snyk-ls/internal/notification"
2930
"github.com/snyk/snyk-ls/internal/observability/error_reporting"
3031
"github.com/snyk/snyk-ls/internal/testutil"
31-
32-
"github.com/snyk/go-application-framework/pkg/common"
3332
)
3433

3534
func Test_ApiClient_isCalledAndResultReturned(t *testing.T) {
@@ -42,7 +41,7 @@ func Test_ApiClient_isCalledAndResultReturned(t *testing.T) {
4241

4342
result, _ := sastEnabledCmd.Execute(context.Background())
4443

45-
assert.True(t, result.(common.SastResponse).SastEnabled)
44+
assert.True(t, result.(code_workflow.SastResponse).SastEnabled)
4645
}
4746

4847
func setupSastEnabledCommand(t *testing.T, c *config.Config, fakeApiClient *snyk_api.FakeApiClient) sastEnabled {

infrastructure/code/code.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package code
1919
import (
2020
"bytes"
2121
"context"
22+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow/sast_contract"
2223
"os"
2324
"sync"
2425
"time"
@@ -47,8 +48,7 @@ import (
4748
"github.com/snyk/snyk-ls/internal/progress"
4849
"github.com/snyk/snyk-ls/internal/uri"
4950

50-
"github.com/snyk/go-application-framework/pkg/common"
51-
"github.com/snyk/go-application-framework/pkg/configuration"
51+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow"
5252
)
5353

5454
type ScanStatus struct {
@@ -151,13 +151,13 @@ func (sc *Scanner) Scan(ctx context.Context, path types.FilePath, folderPath typ
151151
return issues, err
152152
}
153153
gafConfig := sc.C.Engine().GetConfiguration()
154-
sastResponse := gafConfig.Get(configuration.SAST_SETTINGS)
154+
sastResponse := gafConfig.Get(code_workflow.ConfigurationSastSettings)
155155

156-
sastSettings, ok := sastResponse.(common.SastResponse)
156+
sastSettingsPtr, ok := sastResponse.(*sast_contract.SastResponse)
157157
if !ok {
158158
return issues, errors.New("Failed to convert SAST settings to the correct type")
159159
}
160-
160+
sastSettings := *sastSettingsPtr
161161
if !sc.isSastEnabled(sastSettings) {
162162
return issues, errors.New("SAST is not enabled")
163163
}
@@ -166,7 +166,7 @@ func (sc *Scanner) Scan(ctx context.Context, path types.FilePath, folderPath typ
166166
sc.updateCodeApiLocalEngine(sastSettings)
167167
}
168168

169-
sc.C.SetDeepCodeAIFixEnabled(sastResponse.AutofixEnabled)
169+
sc.C.SetDeepCodeAIFixEnabled(sastSettings.AutofixEnabled)
170170

171171
sc.changedFilesMutex.Lock()
172172
if sc.changedPaths[folderPath] == nil {

infrastructure/code/sast_enabled.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package code
1818

1919
import (
20-
"github.com/snyk/go-application-framework/pkg/common"
20+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow/sast_contract"
2121
"github.com/snyk/snyk-ls/internal/data_structure"
2222
"github.com/snyk/snyk-ls/internal/types"
2323
)
@@ -29,7 +29,7 @@ const codeDisabledInOrganisationMessageText = "It looks like your organization h
2929
const enableSnykCodeMessageActionItemTitle types.MessageAction = "Enable Snyk Code"
3030
const closeMessageActionItemTitle types.MessageAction = "Close"
3131

32-
func (sc *Scanner) isSastEnabled(sastResponse common.SastResponse) bool {
32+
func (sc *Scanner) isSastEnabled(sastResponse sast_contract.SastResponse) bool {
3333
if !sastResponse.SastEnabled {
3434
// this is processed in the listener registered to translate into the right client protocol
3535
actionCommandMap := data_structure.NewOrderedMap[types.MessageAction, types.CommandData]()

infrastructure/code/sast_enabled_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package code
1818

1919
import (
20+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow/sast_contract"
2021
"strconv"
2122
"testing"
2223

@@ -27,8 +28,6 @@ import (
2728
"github.com/snyk/snyk-ls/internal/data_structure"
2829
"github.com/snyk/snyk-ls/internal/notification"
2930
"github.com/snyk/snyk-ls/internal/types"
30-
31-
"github.com/snyk/go-application-framework/pkg/common"
3231
)
3332

3433
func TestIsSastEnabled(t *testing.T) {
@@ -37,9 +36,9 @@ func TestIsSastEnabled(t *testing.T) {
3736
ApiError: nil,
3837
}
3938

40-
mockedSastResponse := common.SastResponse{
39+
mockedSastResponse := sast_contract.SastResponse{
4140
SastEnabled: true,
42-
LocalCodeEngine: common.LocalCodeEngine{
41+
LocalCodeEngine: sast_contract.LocalCodeEngine{
4342
AllowCloudUpload: false,
4443
Url: "http://local.engine",
4544
Enabled: true,

infrastructure/code/sast_local_engine.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
package code
1818

1919
import (
20-
"github.com/snyk/go-application-framework/pkg/common"
20+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow/sast_contract"
2121
"github.com/snyk/snyk-ls/application/config"
2222
)
2323

24-
func (sc *Scanner) isLocalEngineEnabled(sastResponse common.SastResponse) bool {
24+
func (sc *Scanner) isLocalEngineEnabled(sastResponse sast_contract.SastResponse) bool {
2525
sc.C.Logger().Debug().Any("sastResponse", sastResponse).Msg("sast response")
2626
return sastResponse.SastEnabled && sastResponse.LocalCodeEngine.Enabled
2727
}
2828

29-
func (sc *Scanner) updateCodeApiLocalEngine(sastResponse common.SastResponse) {
29+
func (sc *Scanner) updateCodeApiLocalEngine(sastResponse sast_contract.SastResponse) {
3030
config.CurrentConfig().SetSnykCodeApi(sastResponse.LocalCodeEngine.Url)
3131
api := config.CurrentConfig().SnykCodeApi()
3232
sc.C.Logger().Debug().Str("snykCodeApi", api).Msg("updated Snyk Code API Local Engine")

infrastructure/code/sast_local_engine_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package code
1818

1919
import (
20-
"github.com/snyk/go-application-framework/pkg/configuration"
20+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow/sast_contract"
2121
"slices"
2222
"testing"
2323

@@ -27,7 +27,7 @@ import (
2727
"github.com/snyk/snyk-ls/infrastructure/snyk_api"
2828
"github.com/snyk/snyk-ls/internal/notification"
2929

30-
"github.com/snyk/go-application-framework/pkg/common"
30+
"github.com/snyk/go-application-framework/pkg/configuration"
3131
)
3232

3333
func TestIsLocalEngine(t *testing.T) {
@@ -37,9 +37,9 @@ func TestIsLocalEngine(t *testing.T) {
3737
ApiError: nil,
3838
}
3939

40-
mockedSastResponse := common.SastResponse{
40+
mockedSastResponse := sast_contract.SastResponse{
4141
SastEnabled: true,
42-
LocalCodeEngine: common.LocalCodeEngine{
42+
LocalCodeEngine: sast_contract.LocalCodeEngine{
4343
AllowCloudUpload: false,
4444
Url: "http://local.engine",
4545
Enabled: true,

infrastructure/snyk_api/snyk_api_pact_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ package snyk_api
1818

1919
import (
2020
"fmt"
21-
"github.com/snyk/go-application-framework/pkg/common"
22-
"github.com/snyk/go-application-framework/pkg/configuration"
21+
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow"
2322
"net/http"
2423
"testing"
2524

@@ -56,9 +55,9 @@ func TestSnykApiPact(t *testing.T) {
5655
}()
5756

5857
t.Run("Get SAST enablement", func(t *testing.T) {
59-
expectedResponse := common.SastResponse{
58+
expectedResponse := code_workflow.SastResponse{
6059
SastEnabled: true,
61-
LocalCodeEngine: common.LocalCodeEngine{Enabled: false},
60+
LocalCodeEngine: code_workflow.LocalCodeEngine{Enabled: false},
6261
ReportFalsePositivesEnabled: false,
6362
AutofixEnabled: false,
6463
}
@@ -114,9 +113,9 @@ func TestSnykApiPact(t *testing.T) {
114113
organization := orgUUID
115114
c.SetOrganization(organization)
116115

117-
expectedResponse := common.SastResponse{
116+
expectedResponse := code_workflow.SastResponse{
118117
SastEnabled: true,
119-
LocalCodeEngine: common.LocalCodeEngine{Enabled: false},
118+
LocalCodeEngine: code_workflow.LocalCodeEngine{Enabled: false},
120119
ReportFalsePositivesEnabled: false,
121120
AutofixEnabled: false,
122121
}

0 commit comments

Comments
 (0)