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

🏎️ access score impact safely #1526

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion policy/executor/internal/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ func (nodeData *ReportingJobNodeData) score() (*policy.Score, error) {
if s == nil {
return nil, nil
}
policy.AddSpecdScore(calculator, s, rjRes.score != nil, rjRes.impact)
i := rjRes.impact
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 understand why this makes it safer to access

policy.AddSpecdScore(calculator, s, rjRes.score != nil, i)
}

policy.AddDataScore(calculator, len(nodeData.datapoints), finishedDatapoints)
Expand Down
9 changes: 7 additions & 2 deletions policy/score_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,13 @@ func (c *bandedScoreCalculator) Add(score *Score, impact *explorer.Impact) {

if score.ScoreCompletion != 0 && score.Weight != 0 {
category := uint32(0)
if impact != nil && impact.Value != nil {
category = 100 - uint32(impact.Value.Value)
if impact != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

these 2 look the same to me. Am i missing somethng

Copy link
Contributor

Choose a reason for hiding this comment

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

// Store pointer to avoid panic
if impactV := impact.GetValue(); impactV != nil {
if value := impactV.GetValue(); value <= 100 && value >= 0 {
category = 100 - uint32(value)
}
}
}

if category <= 10 {
Expand Down
2 changes: 1 addition & 1 deletion test/providers/scan_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestScanFlags(t *testing.T) {
assert.NotNil(t, r.Stderr())

assert.Contains(t, string(r.Stderr()),
"app-private-key is required for GitHub App authentication", // expected! it means we loaded the flags
"could not parse private key", // expected! it means we loaded the flags
)
})
t.Run("github scan WITH all required flags for app auth", func(t *testing.T) {
Expand Down
Loading