|
| 1 | +// Copyright 2025 OpenSSF Scorecard Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package checks |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/ossf/scorecard/v5/checker" |
| 19 | + "github.com/ossf/scorecard/v5/checks/evaluation" |
| 20 | + "github.com/ossf/scorecard/v5/checks/raw" |
| 21 | + sce "github.com/ossf/scorecard/v5/errors" |
| 22 | + "github.com/ossf/scorecard/v5/probes" |
| 23 | + zrunner "github.com/ossf/scorecard/v5/probes/zrunner" |
| 24 | +) |
| 25 | + |
| 26 | +const CheckMTTUDependencies = "MTTUDependencies" |
| 27 | + |
| 28 | +//nolint:gochecknoinits |
| 29 | +func init() { |
| 30 | + supportedRequestTypes := []checker.RequestType{ |
| 31 | + checker.FileBased, |
| 32 | + } |
| 33 | + if err := registerCheck(CheckMTTUDependencies, MTTUDependencies, supportedRequestTypes); err != nil { |
| 34 | + // this should never happen |
| 35 | + panic(err) |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// indirections to ease testing. |
| 40 | +var runProbes = zrunner.Run |
| 41 | + |
| 42 | +func MTTUDependencies(c *checker.CheckRequest) checker.CheckResult { |
| 43 | + // 1) get raw data |
| 44 | + rawData, err := raw.MTTUDependencies(c) |
| 45 | + if err != nil { |
| 46 | + e := sce.WithMessage(sce.ErrScorecardInternal, err.Error()) |
| 47 | + return checker.CreateRuntimeErrorResult(CheckMTTUDependencies, e) |
| 48 | + } |
| 49 | + |
| 50 | + // 2) set raw results |
| 51 | + pRawResults := getRawResults(c) |
| 52 | + pRawResults.MTTUDependenciesResults = rawData |
| 53 | + |
| 54 | + // 3) run probes |
| 55 | + findings, err := runProbes(pRawResults, probes.MTTUDependencies) |
| 56 | + if err != nil { |
| 57 | + e := sce.WithMessage(sce.ErrScorecardInternal, err.Error()) |
| 58 | + return checker.CreateRuntimeErrorResult(CheckMTTUDependencies, e) |
| 59 | + } |
| 60 | + |
| 61 | + // 4) evaluate |
| 62 | + ret := evaluation.MTTUDependencies(CheckMTTUDependencies, findings, c.Dlogger) |
| 63 | + return ret |
| 64 | +} |
0 commit comments