-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Raw results for best practices badge (#1795)
* Raw results for best practices badge * updates * updates * tests * comment
- Loading branch information
1 parent
fe6e091
commit ac88460
Showing
6 changed files
with
179 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright Security Scorecard Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package evaluation | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ossf/scorecard/v4/checker" | ||
sce "github.com/ossf/scorecard/v4/errors" | ||
) | ||
|
||
// Note: exported for unit tests. | ||
const ( | ||
silverScore = 7 | ||
// Note: if this value is changed, please update the action's threshold score | ||
// https://github.com/ossf/scorecard-action/blob/main/policies/template.yml#L61. | ||
passingScore = 5 | ||
inProgressScore = 2 | ||
) | ||
|
||
// CIIBestPractices applies the score policy for the CIIBestPractices check. | ||
func CIIBestPractices(name string, dl checker.DetailLogger, r *checker.CIIBestPracticesData) checker.CheckResult { | ||
if r == nil { | ||
e := sce.WithMessage(sce.ErrScorecardInternal, "empty raw data") | ||
return checker.CreateRuntimeErrorResult(name, e) | ||
} | ||
|
||
var results checker.CheckResult | ||
switch r.Badge { | ||
case checker.CIIBadgeNotFound: | ||
results = checker.CreateMinScoreResult(name, "no badge detected") | ||
case checker.CIIBadgeInProgress: | ||
msg := fmt.Sprintf("badge detected: %v", r.Badge) | ||
results = checker.CreateResultWithScore(name, msg, inProgressScore) | ||
case checker.CIIBadgePassing: | ||
msg := fmt.Sprintf("badge detected: %v", r.Badge) | ||
results = checker.CreateResultWithScore(name, msg, passingScore) | ||
case checker.CIIBadgeSilver: | ||
msg := fmt.Sprintf("badge detected: %v", r.Badge) | ||
results = checker.CreateResultWithScore(name, msg, silverScore) | ||
case checker.CIIBadgeGold: | ||
msg := fmt.Sprintf("badge detected: %v", r.Badge) | ||
results = checker.CreateMaxScoreResult(name, msg) | ||
case checker.CIIBadgeUnknown: | ||
e := sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("unsupported badge: %v", r.Badge)) | ||
results = checker.CreateRuntimeErrorResult(name, e) | ||
} | ||
return results | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022 Security Scorecard Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package raw | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ossf/scorecard/v4/checker" | ||
"github.com/ossf/scorecard/v4/clients" | ||
) | ||
|
||
var errEmptyClient = errors.New("CII client is nil") | ||
|
||
// CIIBestPractices retrieves the raw data for the CIIBestPractices check. | ||
func CIIBestPractices(c *checker.CheckRequest) (checker.CIIBestPracticesData, error) { | ||
var results checker.CIIBestPracticesData | ||
if c.CIIClient == nil { | ||
return results, fmt.Errorf("%w", errEmptyClient) | ||
} | ||
|
||
badge, err := c.CIIClient.GetBadgeLevel(c.Ctx, c.Repo.URI()) | ||
if err != nil { | ||
return results, fmt.Errorf("%w", err) | ||
} | ||
|
||
switch badge { | ||
case clients.NotFound: | ||
results.Badge = checker.CIIBadgeNotFound | ||
case clients.InProgress: | ||
results.Badge = checker.CIIBadgeInProgress | ||
case clients.Passing: | ||
results.Badge = checker.CIIBadgePassing | ||
case clients.Silver: | ||
results.Badge = checker.CIIBadgeSilver | ||
case clients.Gold: | ||
results.Badge = checker.CIIBadgeGold | ||
case clients.Unknown: | ||
results.Badge = checker.CIIBadgeUnknown | ||
} | ||
|
||
return results, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters