2022-12-02 02:08:48 +03:00
|
|
|
// Copyright 2020 OpenSSF Scorecard Authors
|
2021-12-03 20:28:27 +03:00
|
|
|
//
|
|
|
|
// 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 checks
|
|
|
|
|
|
|
|
import (
|
2024-04-13 00:51:50 +03:00
|
|
|
"github.com/ossf/scorecard/v5/checker"
|
|
|
|
"github.com/ossf/scorecard/v5/checks/evaluation"
|
|
|
|
"github.com/ossf/scorecard/v5/checks/raw"
|
|
|
|
sce "github.com/ossf/scorecard/v5/errors"
|
|
|
|
"github.com/ossf/scorecard/v5/probes"
|
|
|
|
"github.com/ossf/scorecard/v5/probes/zrunner"
|
2021-12-03 20:28:27 +03:00
|
|
|
)
|
|
|
|
|
2021-12-04 17:56:50 +03:00
|
|
|
// CheckLicense is the registered name for License.
|
|
|
|
const CheckLicense = "License"
|
2021-12-03 20:28:27 +03:00
|
|
|
|
|
|
|
//nolint:gochecknoinits
|
|
|
|
func init() {
|
2022-02-08 03:49:49 +03:00
|
|
|
supportedRequestTypes := []checker.RequestType{
|
2022-03-04 20:24:06 +03:00
|
|
|
checker.CommitBased,
|
2022-02-08 03:49:49 +03:00
|
|
|
}
|
2022-04-14 04:20:05 +03:00
|
|
|
if err := registerCheck(CheckLicense, License, supportedRequestTypes); err != nil {
|
2022-01-13 01:14:18 +03:00
|
|
|
// this should never happen
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-12-03 20:28:27 +03:00
|
|
|
}
|
|
|
|
|
2022-04-14 04:20:05 +03:00
|
|
|
// License runs License check.
|
|
|
|
func License(c *checker.CheckRequest) checker.CheckResult {
|
|
|
|
rawData, err := raw.License(c)
|
2021-12-03 20:28:27 +03:00
|
|
|
if err != nil {
|
2022-04-14 04:20:05 +03:00
|
|
|
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
|
|
|
|
return checker.CreateRuntimeErrorResult(CheckLicense, e)
|
2021-12-03 20:28:27 +03:00
|
|
|
}
|
|
|
|
|
2022-04-14 04:20:05 +03:00
|
|
|
// Set the raw results.
|
2023-10-24 21:48:41 +03:00
|
|
|
pRawResults := getRawResults(c)
|
|
|
|
pRawResults.LicenseResults = rawData
|
|
|
|
|
|
|
|
// Evaluate the probes.
|
|
|
|
findings, err := zrunner.Run(pRawResults, probes.License)
|
|
|
|
if err != nil {
|
|
|
|
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
|
|
|
|
return checker.CreateRuntimeErrorResult(CheckLicense, e)
|
2022-02-22 21:50:01 +03:00
|
|
|
}
|
2021-12-03 20:28:27 +03:00
|
|
|
|
2024-04-05 00:43:30 +03:00
|
|
|
ret := evaluation.License(CheckLicense, findings, c.Dlogger)
|
|
|
|
ret.Findings = findings
|
|
|
|
return ret
|
2021-12-03 20:28:27 +03:00
|
|
|
}
|