-
Notifications
You must be signed in to change notification settings - Fork 9
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
Conversation
734554d
to
f9dea3d
Compare
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
func getSastSettings(engine workflow.Engine) (*common.SastResponse, error) { | ||
config := engine.GetConfiguration() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
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.
var response common.SastResponse | ||
var defaultResult common.SastResponse |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we want:
- Rewrite the engine.GetConfiguration() to have the sast settings instead of just a ConfigurationSastEnabled configuration.
- Setup the callback in code_workflow that will query the API for sast settings whenever asked for.
- NOT setup a callback for sast settings in app.
There was a problem hiding this comment.
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.
Changes in Go Application Framework:
defaultFuncGetSastSettings
callback function that executes when the snyk-ls asks for sast settings from the Go Application Framework Configuration./pkg/common
to be used in snyk-ls.SAST_SETTINGS