fix: load snyk.json only from configstore path - #659
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This comment has been minimized.
This comment has been minimized.
ccd3022 to
5d9e0f2
Compare
PR Reviewer Guide 🔍
|
|
I also added a regression test. |
| } | ||
|
|
||
| config.viper.AddConfigPath(configPath) | ||
| config.viper.AddConfigPath(".") |
There was a problem hiding this comment.
what other implications this removal can have?
There was a problem hiding this comment.
I am not noticing any other files besides snyk referenced for the config (
Also, because of
this function always seems to load only the last file from the array. I believe we could also remove the for loop.There was a problem hiding this comment.
does this affect .snyk files? Should the behavior consider the current directory, same behavior as happens for .gitignore?
There was a problem hiding this comment.
also need to think:
- What if there are customers using the current approach? This will be a breaking change for them.
I also think should contain more tests, i.e. not only look for snyk.json, but for others (.snyk, .gitignore, ...)
There was a problem hiding this comment.
I see the ticket is a bit old, so I wonder if the understanding there remains the same
There was a problem hiding this comment.
.snyk and .gitignore shouldn't be affected. 😀
The config is managed by Viper while .snyk and .gitignore seem to be loaded here:
Tests regarding their loading seems to be performed here: https://github.com/snyk/go-application-framework/blob/main/pkg/utils/file_filter_test.go
I am not sure if we should consider this a breaking change or simply a fix. 😔
TS CLI commands (e.g.: test, container, iac) never loaded the local directory snyk.json config file. The behavior of snyk commands regarding it is currently inconsistent.
Description
Noted that if a
snyk.jsonfile is present in the working directory and absent from the user’s~/.config/configstore/, snyk will use the file from the working directory to authenticate requests.This PR ensures we have a single source of truth for the
snyk.json.Relevant ticket: CLI-1124
CLI PR: snyk/cli#7008
Checklist
make test)make generate)make lint)go get github.com/snyk/go-application-framework@YOUR_LATEST_GAF_COMMITin thecliv2directory.go.modto point to your local GAF code.go mod tidyin thecliv2directory.go.modandgo.sumchanges.Note
Medium Risk
Changes where authentication and endpoint settings are sourced from disk; correct for security but may surprise users who relied on a project-local snyk.json.
Overview
Stops the CLI from treating a
snyk.jsonin the current working directory as configuration when loading defaults.readConfigFilesIntoViperno longer adds"."as a Viper config path, so file-based settings (includingapi,org,endpoint) come only from~/.config/configstoreviadetermineBasePath().This closes the case where a repo-local
snyk.jsoncould supply credentials when nothing was in the user configstore. New tests cover cwd-only (values stay empty) and configstore + cwd (home configstore wins).Reviewed by Cursor Bugbot for commit 5d9e0f2. Bugbot is set up for automated code reviews on this repo. Configure here.