Skip to content

feat: use gaf to get sast settings #319

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

Closed
wants to merge 3 commits into from

Conversation

acke
Copy link
Contributor

@acke acke commented Mar 26, 2025

Changes in Go Application Framework:

  • added a defaultFuncGetSastSettings callback function that executes when the snyk-ls asks for sast settings from the Go Application Framework Configuration.
  • moved sast_settings.go from "/internal/api/contract" to /pkg/common to be used in snyk-ls.
  • introduced a new constant for the new settings in Configuration: SAST_SETTINGS
  • removed the cachedResponse

@acke acke force-pushed the feat/IDE-724_sast_settings_from-gaf branch from 734554d to f9dea3d Compare March 26, 2025 08:57
@acke acke marked this pull request as ready for review March 26, 2025 09:40
@acke acke requested review from a team as code owners March 26, 2025 09:40
Comment on lines +52 to +59
client := engine.GetNetworkAccess().GetHttpClient()
url := config.GetString(configuration.API_URL)
apiClient := apiClientFactory(url, client)
orgId := config.GetString(configuration.ORGANIZATION)
if len(orgId) == 0 {
return existingValue, nil
}
response, err := apiClient.GetSastSettings(orgId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we have caching here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this and it might not make sense to have caching for this in GAF and leave it up to the consumer to cache if necessary.

Comment on lines +48 to 49
func getSastSettings(engine workflow.Engine) (*common.SastResponse, error) {
config := engine.GetConfiguration()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this func is still needed.
Shouldn't the code_workflow get the sastSettings from the config?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -98,7 +99,7 @@ func Test_Code_entrypoint(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, rs)
assert.Equal(t, expectedData, rs[0].GetPayload().(string))
assert.Equal(t, 1, sastSettingsCalled)
assert.Equal(t, 2, sastSettingsCalled)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

@acke acke Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because now its also called when then default func is setup here: initConfiguration to initiate configuration.SAST_SETTINGS

config.AddDefaultValue(configuration.SAST_SETTINGS, defaultFuncGetSastSettings(engine, config, logger, apiClientFactory))

And it is also called in InitCodeWorkflow to set config for code_workflow.ConfigurationSastEnabled.

engine.GetConfiguration().AddDefaultValue(code_workflow.ConfigurationSastEnabled, getSastEnabled(engine))

Before adding the default func, we only did the second config call in the test case.

Comment on lines +201 to +202
var response common.SastResponse
var defaultResult common.SastResponse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PeterSchafer fyi we need SastResponse struct to be outside internal pkg to use it in ls.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understand! Can we find a more descriptive name than common?

@@ -44,6 +44,28 @@ func defaultFuncOrganizationSlug(engine workflow.Engine, config configuration.Co
return callback
}

func defaultFuncGetSastSettings(engine workflow.Engine, config configuration.Configuration, logger *zerolog.Logger, apiClientFactory func(url string, client *http.Client) api.ApiClient) configuration.DefaultValueFunction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Please don't add domain logic into app, which is more or less domain independent. There is already a function registered in the code_workflow, please let's use this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we want:

  1. Rewrite the engine.GetConfiguration() to have the sast settings instead of just a ConfigurationSastEnabled configuration.
  2. Setup the callback in code_workflow that will query the API for sast settings whenever asked for.
  3. NOT setup a callback for sast settings in app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, what I wanted to say is, to keep product and domain specific logic close to each other. This means in this case that the default function for SAST specific configuration values should be registered here and implemented somewhere there as well.

One benefit is, that these values only get available if an application registers the code workflow and are not wide spread through the code base.

@acke acke closed this Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants