scorecard/checks/packaging.go

70 lines
2.1 KiB
Go
Raw Normal View History

// Copyright 2020 OpenSSF Scorecard Authors
2021-01-15 19:29:07 +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 (
2022-01-12 22:49:01 +03:00
"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/checks/evaluation"
:sparkles: Enable gitlab Packaging Reporting (#2941) * feat: Added yaml file that contains the full, flattened gitlab ci/cd contents Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Updated to meet linting failures Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Updated filename for flattened gitlab Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Updated to include the generated, flattened ci yaml in the file listing Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Updated the apiFunction to be part of the handler Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Moved packaging collection to be a repoClient specific sub-package Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * feat: Added path for gitlab projects, including a basic search for lines containing nuget, poetry, twine publishes Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * test: Added tests for gitlab packaging finders Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * test: Added more tests for parsing through the client and grouping packaging data Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Utilizing existing mock objects to prevent race condition exception Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Addressed linting errors Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * test: Updated expectation for log message Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Reverted back to the original error Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> --------- Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> Co-authored-by: raghavkaul <8695110+raghavkaul@users.noreply.github.com>
2023-05-08 20:20:12 +03:00
"github.com/ossf/scorecard/v4/checks/raw/github"
"github.com/ossf/scorecard/v4/checks/raw/gitlab"
"github.com/ossf/scorecard/v4/clients/githubrepo"
"github.com/ossf/scorecard/v4/clients/gitlabrepo"
2022-01-12 22:49:01 +03:00
sce "github.com/ossf/scorecard/v4/errors"
"github.com/ossf/scorecard/v4/probes"
"github.com/ossf/scorecard/v4/probes/zrunner"
2021-01-15 19:29:07 +03:00
)
// CheckPackaging is the registered name for Packaging.
const CheckPackaging = "Packaging"
//nolint:gochecknoinits
2021-01-15 19:29:07 +03:00
func init() {
if err := registerCheck(CheckPackaging, Packaging, nil); err != nil {
// this should never happen
panic(err)
}
2021-01-15 19:29:07 +03:00
}
// Packaging runs Packaging check.
func Packaging(c *checker.CheckRequest) checker.CheckResult {
:sparkles: Enable gitlab Packaging Reporting (#2941) * feat: Added yaml file that contains the full, flattened gitlab ci/cd contents Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Updated to meet linting failures Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Updated filename for flattened gitlab Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Updated to include the generated, flattened ci yaml in the file listing Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Updated the apiFunction to be part of the handler Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Moved packaging collection to be a repoClient specific sub-package Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * feat: Added path for gitlab projects, including a basic search for lines containing nuget, poetry, twine publishes Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * test: Added tests for gitlab packaging finders Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * test: Added more tests for parsing through the client and grouping packaging data Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Utilizing existing mock objects to prevent race condition exception Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Addressed linting errors Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * test: Updated expectation for log message Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> * refactor: Reverted back to the original error Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> --------- Signed-off-by: Robison, Jim B <jim.b.robison@lmco.com> Co-authored-by: raghavkaul <8695110+raghavkaul@users.noreply.github.com>
2023-05-08 20:20:12 +03:00
var rawData checker.PackagingData
var err error
switch v := c.RepoClient.(type) {
case *githubrepo.Client:
rawData, err = github.Packaging(c)
case *gitlabrepo.Client:
rawData, err = gitlab.Packaging(c)
default:
_ = v
}
2021-01-15 19:29:07 +03:00
if err != nil {
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
return checker.CreateRuntimeErrorResult(CheckPackaging, e)
2021-01-15 19:29:07 +03:00
}
pRawResults := getRawResults(c)
pRawResults.PackagingResults = rawData
findings, err := zrunner.Run(pRawResults, probes.Packaging)
if err != nil {
e := sce.WithMessage(sce.ErrScorecardInternal, err.Error())
return checker.CreateRuntimeErrorResult(CheckPackaging, e)
2021-01-15 19:29:07 +03:00
}
return evaluation.Packaging(CheckPackaging, findings, c.Dlogger)
2021-01-15 19:29:07 +03:00
}