Skip to content

feat: use gaf sast settings [IDE-724] #813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8b4a5b6
feat: use gaf to get sast settings
acke Mar 25, 2025
91b6673
sast settings
acke Mar 26, 2025
0063dc9
fix: move shared types to common
acke Mar 27, 2025
7649ace
fix: store user agent in gaf configuration
acke Mar 28, 2025
06d7a28
fix: refactor shared types and constants to sast_contract
acke Mar 28, 2025
5ea9418
fix: update gaf dependency
acke Mar 28, 2025
92dce26
fix: remove tests for functions removed in the api client
acke Mar 31, 2025
7b72832
fix: fix references to sast_contract.SastPresponse and fixed lint and…
acke Mar 31, 2025
a302a16
fix: revert test changes in cache_test
acke Apr 2, 2025
f5c5994
fix: remove and add correct headers
acke Apr 2, 2025
fd0b5dd
fix: updated cache_test
acke Apr 3, 2025
ba14998
fix: updated gaf dependency
acke Apr 3, 2025
b323c49
fix: remove tests that uses the apiclient to get sastsettings
acke Apr 3, 2025
9123271
fix: use sastresponse pointer
acke Apr 3, 2025
e588336
fix: test setup for sast settings
acke Apr 3, 2025
62eecf8
fix: updated failed to get sast settings error description
acke Apr 4, 2025
58c9cf6
fix: setup sast configs in smoke test
acke Apr 4, 2025
6256c59
fix: cleanup test cases
acke Apr 6, 2025
a529d27
fix: unit test
acke Apr 15, 2025
baba7de
fix: update gaf dependency
acke Apr 15, 2025
0271844
fix: updated go.sum
acke Apr 15, 2025
a4b85a6
fix: upgrade google.golang.org/genproto
acke Apr 15, 2025
5d0415a
fix: update go.sum
acke Apr 15, 2025
f09ed6f
fix: use GetWithError instead of only Get when accessing sast setting…
acke Apr 15, 2025
d0786eb
fix: updated gaf dependency
acke Apr 15, 2025
cb84a0c
fix: refactor code WIP
acke Apr 17, 2025
4babd1a
fix: initialize the code workflow for the snyk-ls
acke Apr 23, 2025
1120a32
fix: code review improvements
acke Apr 23, 2025
8b611d9
Merge branch 'main' into feat/IDE-724_use_gaf_sast_settings
acke Apr 23, 2025
7c777b4
docs: updated licenses
acke Apr 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Right now the language server supports the following actions:
- `SettingsSastEnabled` triggers the api call to check if Snyk Code is enabled
- command: `snyk.getSettingsSastEnabled`
- args: empty
- returns `true` if enabled, `false` if not, or an error and false if an error occurred
- returns a `*sast_contract.SastResponse` or, or an error and false if an error occurred
- `GetActiveUser` triggers the api call to get the active logged in user or an error if not logged in
- command: `snyk.getActiveUser`
- args: empty
Expand Down
5 changes: 4 additions & 1 deletion application/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ func workspaceDidChangeWorkspaceFoldersHandler(c *config.Config, srv *jrpc2.Serv

func initNetworkAccessHeaders() {
engine := config.CurrentConfig().Engine()
ua := util.GetUserAgent(engine.GetConfiguration(), config.Version)
gafConfig := engine.GetConfiguration()
ua := util.GetUserAgent(gafConfig, config.Version)
engine.GetNetworkAccess().RemoveHeaderField("x-snyk-cli-version")
engine.GetNetworkAccess().AddHeaderField("x-snyk-ide", ua.AppVersion)
engine.GetNetworkAccess().AddHeaderField("User-Agent", ua.String())
}

Expand Down
17 changes: 17 additions & 0 deletions application/server/server_smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/creachadair/jrpc2/server"
"github.com/go-git/go-git/v5"
"github.com/rs/zerolog"
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow"
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow/sast_contract"
sglsp "github.com/sourcegraph/go-lsp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -210,6 +212,7 @@ func Test_SmokeIssueCaching(t *testing.T) {
c.SetSnykOssEnabled(true)
c.SetSnykIacEnabled(false)
di.Init()
setSastEnabled(c, true)

var cloneTargetDirGoof = setupRepoAndInitialize(t, testsupport.NodejsGoof, "0336589", loc, c)
cloneTargetDirGoofString := (string)(cloneTargetDirGoof)
Expand Down Expand Up @@ -286,6 +289,7 @@ func Test_SmokeIssueCaching(t *testing.T) {
c.SetSnykOssEnabled(true)
c.SetSnykIacEnabled(false)
di.Init()
setSastEnabled(c, true)

var cloneTargetDirGoof = setupRepoAndInitialize(t, testsupport.NodejsGoof, "0336589", loc, c)
folderGoof := c.Workspace().GetFolderContaining(cloneTargetDirGoof)
Expand Down Expand Up @@ -495,6 +499,7 @@ func runSmokeTest(t *testing.T, c *config.Config, repo string, commit string, fi
c.SetSnykOssEnabled(true)
cleanupChannels()
di.Init()
setSastEnabled(c, true)

cloneTargetDir := setupRepoAndInitialize(t, repo, commit, loc, c)
cloneTargetDirString := (string)(cloneTargetDir)
Expand Down Expand Up @@ -849,6 +854,7 @@ func Test_SmokeSnykCodeFileScan(t *testing.T) {
c.SetSnykCodeEnabled(true)
cleanupChannels()
di.Init()
setSastEnabled(c, true)

var cloneTargetDir, err = storedconfig.SetupCustomTestRepo(t, types.FilePath(t.TempDir()), testsupport.NodejsGoof, "0336589", c.Logger())
cloneTargetDirString := string(cloneTargetDir)
Expand Down Expand Up @@ -897,6 +903,7 @@ func Test_SmokeUncFilePath(t *testing.T) {
c.SetSnykIacEnabled(false)
cleanupChannels()
di.Init()
setSastEnabled(c, true)

var cloneTargetDir, err = storedconfig.SetupCustomTestRepo(t, types.FilePath(t.TempDir()), testsupport.NodejsGoof, "0336589", c.Logger())
if err != nil {
Expand Down Expand Up @@ -925,6 +932,7 @@ func Test_SmokeSnykCodeDelta_NewVulns(t *testing.T) {
c.SetDeltaFindingsEnabled(true)
cleanupChannels()
di.Init()
setSastEnabled(c, true)
scanAggregator := di.ScanStateAggregator()
fileWithNewVulns := "vulns.js"
var cloneTargetDir, err = storedconfig.SetupCustomTestRepo(t, types.FilePath(t.TempDir()), testsupport.NodejsGoof, "0336589", c.Logger())
Expand Down Expand Up @@ -972,6 +980,7 @@ func Test_SmokeSnykCodeDelta_NoNewIssuesFound(t *testing.T) {
cleanupChannels()
di.Init()
scanAggregator := di.ScanStateAggregator()
setSastEnabled(c, true)

fileWithNewVulns := "vulns.js"
var cloneTargetDir, err = storedconfig.SetupCustomTestRepo(t, types.FilePath(t.TempDir()), "https://github.com/snyk-labs/nodejs-goof", "0336589", c.Logger())
Expand Down Expand Up @@ -1002,6 +1011,7 @@ func Test_SmokeSnykCodeDelta_NoNewIssuesFound_JavaGoof(t *testing.T) {
cleanupChannels()
di.Init()
scanAggregator := di.ScanStateAggregator()
setSastEnabled(c, true)

var cloneTargetDir, err = storedconfig.SetupCustomTestRepo(t, types.FilePath(t.TempDir()), "https://github.com/snyk-labs/java-goof", "f5719ae", c.Logger())
assert.NoError(t, err)
Expand All @@ -1021,6 +1031,13 @@ func Test_SmokeSnykCodeDelta_NoNewIssuesFound_JavaGoof(t *testing.T) {
assert.Equal(t, 0, len(issueList), "no issues expected, as delta and no new change")
}

func setSastEnabled(c *config.Config, b bool) {
c.Engine().GetConfiguration().Set(code_workflow.ConfigurationSastSettings, &sast_contract.SastResponse{SastEnabled: b, LocalCodeEngine: sast_contract.LocalCodeEngine{
Enabled: false,
},
})
}

func ensureInitialized(t *testing.T, c *config.Config, loc server.Local, initParams types.InitializeParams) {
t.Helper()
t.Setenv("SNYK_LOG_LEVEL", "info")
Expand Down
4 changes: 3 additions & 1 deletion domain/ide/codelens/codelens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"testing"

"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow"
"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow/sast_contract"
"github.com/stretchr/testify/assert"

"github.com/snyk/snyk-ls/application/di"
Expand All @@ -46,7 +48,7 @@ func Test_GetCodeLensForPath(t *testing.T) {
c := testutil.IntegTest(t)
di.TestInit(t) // IntegTest doesn't automatically inits DI
testutil.OnlyEnableCode()

c.Engine().GetConfiguration().Set(code_workflow.ConfigurationSastSettings, &sast_contract.SastResponse{SastEnabled: true})
// this is using the real progress channel, so we need to listen to it
dummyProgressListeners(t)

Expand Down
3 changes: 1 addition & 2 deletions domain/ide/command/command_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ func CreateFromCommandData(c *config.Config, commandData types.CommandData, srv
case types.OpenLearnLesson:
return &openLearnLesson{command: commandData, srv: srv, learnService: learnService}, nil
case types.GetSettingsSastEnabled:
apiClient := snyk_api.NewSnykApiClient(c, httpClient)
return &sastEnabled{command: commandData, apiClient: apiClient, logger: c.Logger(), authenticationService: authService}, nil
return &sastEnabled{command: commandData, logger: c.Logger(), authenticationService: authService, c: c}, nil
case types.GetFeatureFlagStatus:
apiClient := snyk_api.NewSnykApiClient(c, httpClient)
return &featureFlagStatus{command: commandData, apiClient: apiClient, authenticationService: authService}, nil
Expand Down
15 changes: 11 additions & 4 deletions domain/ide/command/sast_enabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ import (

"github.com/rs/zerolog"

"github.com/snyk/snyk-ls/application/config"
"github.com/snyk/snyk-ls/infrastructure/authentication"
"github.com/snyk/snyk-ls/infrastructure/snyk_api"
"github.com/snyk/snyk-ls/internal/types"

"github.com/snyk/go-application-framework/pkg/local_workflows/code_workflow"
)

type sastEnabled struct {
command types.CommandData
apiClient snyk_api.SnykApiClient
logger *zerolog.Logger
authenticationService authentication.AuthenticationService
c *config.Config
}

func (cmd *sastEnabled) Command() types.CommandData {
Expand All @@ -45,6 +47,11 @@ func (cmd *sastEnabled) Execute(_ context.Context) (any, error) {
return nil, nil
}

sastResponse, err := cmd.apiClient.SastSettings()
return sastResponse, err
gafConfig := cmd.c.Engine().GetConfiguration()
sastResponse, err := gafConfig.GetWithError(code_workflow.ConfigurationSastSettings)
if err != nil {
return nil, err
}

return sastResponse, nil
}
98 changes: 0 additions & 98 deletions domain/ide/command/sast_enabled_test.go

This file was deleted.

35 changes: 18 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ require (
github.com/pkg/errors v0.9.1
github.com/puzpuzpuz/xsync v1.5.2
github.com/puzpuzpuz/xsync/v3 v3.5.1
github.com/rs/zerolog v1.33.0
github.com/rs/zerolog v1.34.0
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/snyk/code-client-go v1.20.1
github.com/snyk/go-application-framework v0.0.0-20250325133828-3ffd1aa4f76f
github.com/snyk/go-application-framework v0.0.0-20250415184029-4e8fc50fc812
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd
github.com/spf13/pflag v1.0.6
github.com/stretchr/testify v1.10.0
github.com/subosito/gotenv v1.6.0
github.com/writeas/go-strip-markdown v2.0.1+incompatible
go.lsp.dev/uri v0.3.0
golang.org/x/exp v0.0.0-20250215185904-eff6e970281f
golang.org/x/mod v0.23.0
golang.org/x/net v0.35.0
golang.org/x/mod v0.24.0
golang.org/x/net v0.38.0
golang.org/x/oauth2 v0.27.0
golang.org/x/sync v0.11.0
golang.org/x/sync v0.13.0
gopkg.in/ini.v1 v1.67.0
)

require (
dario.cat/mergo v1.0.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProtonMail/go-crypto v1.1.5 // indirect
github.com/ProtonMail/go-crypto v1.1.6 // indirect
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand All @@ -58,12 +58,12 @@ require (
github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/getkin/kin-openapi v0.129.0 // indirect
github.com/getkin/kin-openapi v0.131.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/jsonpointer v0.21.1 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
Expand Down Expand Up @@ -92,10 +92,10 @@ require (
github.com/muesli/termenv v0.15.2 // indirect
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/oasdiff/yaml v0.0.0-20241214135536-5f7845c759c8 // indirect
github.com/oasdiff/yaml3 v0.0.0-20241214160948-977117996672 // indirect
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
github.com/otiai10/mint v1.6.3 // indirect
github.com/pact-foundation/pact-go/v2 v2.2.0 // indirect
github.com/pact-foundation/pact-go/v2 v2.4.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
Expand All @@ -108,7 +108,7 @@ require (
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530 // indirect
github.com/speakeasy-api/jsonpath v0.6.1 // indirect
github.com/speakeasy-api/openapi-overlay v0.10.1 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/afero v1.14.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.9.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand All @@ -123,10 +123,11 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/crypto v0.35.0 // indirect
golang.org/x/sys v0.30.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/tools v0.30.0 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
golang.org/x/tools v0.31.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250409194420-de1ac958c67a // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading