Skip to content
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

findings: values should be exported consts owned by the probe #3641

Closed
spencerschrock opened this issue Nov 2, 2023 · 2 comments · Fixed by #3977
Closed

findings: values should be exported consts owned by the probe #3641

spencerschrock opened this issue Nov 2, 2023 · 2 comments · Fixed by #3977

Comments

@spencerschrock
Copy link
Member

All the places in our code that read values in a finding shouldn't need to redefine what the key is.

@AdamKorcz
Copy link
Contributor

Could you write a short example for this?

@spencerschrock
Copy link
Member Author

Could you write a short example for this?

This came up in the SAST/Maintained checks:
Both the probe

f = f.WithValues(map[string]int{
"commitsWithinThreshold": commitsWithinThreshold,
})

And then consumer (evaluation code) need to remember "commitsWithinThreshold"
for i := range findings {
f := &findings[i]
if f.Outcome == finding.OutcomePositive {
switch f.Probe {
case issueActivityByProjectMember.Probe:
numberOfIssuesUpdatedWithinThreshold = f.Values["numberOfIssuesUpdatedWithinThreshold"]
case commitsInLast90Days.Probe:
commitsWithinThreshold = f.Values["commitsWithinThreshold"]
}
}
}

Not to mention all the tests:

Values: map[string]int{
"commitsWithinThreshold": 2,
},

So if the probe defined the values it can produce (if known) as a const, then it creates a single source of truth for the key value.

const (
    Probe = "commitsInLast90Days"
    // I'm not set on the name
    CommitsValue = "commitsWithinThreshold" 
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
2 participants