Skip to content

Commit

Permalink
added full gitlab support for command line execution
Browse files Browse the repository at this point in the history
Signed-off-by: N8BWert <[email protected]>
Signed-off-by: nathaniel.wert <[email protected]>
  • Loading branch information
nathaniel.wert committed Nov 28, 2022
1 parent a37d63c commit 249b65f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
65 changes: 50 additions & 15 deletions checker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ package checker
import (
"context"
"fmt"
"os"
"strings"

"github.com/ossf/scorecard/v4/clients"
ghrepo "github.com/ossf/scorecard/v4/clients/githubrepo"
glrepo "github.com/ossf/scorecard/v4/clients/gitlabrepo"
"github.com/ossf/scorecard/v4/clients/localdir"
"github.com/ossf/scorecard/v4/log"
)
Expand All @@ -34,7 +37,9 @@ func GetClients(ctx context.Context, repoURI, localURI string, logger *log.Logge
clients.VulnerabilitiesClient, // vulnClient
error,
) {
var githubRepo clients.Repo
var repo clients.Repo
var makeRepoError error

if localURI != "" {
localRepo, errLocal := localdir.MakeLocalDirRepo(localURI)
var retErr error
Expand All @@ -49,14 +54,26 @@ func GetClients(ctx context.Context, repoURI, localURI string, logger *log.Logge
retErr
}

githubRepo, errGitHub := ghrepo.MakeGithubRepo(repoURI)
if errGitHub != nil {
return githubRepo,
nil,
nil,
nil,
nil,
fmt.Errorf("getting local directory client: %w", errGitHub)
if strings.Contains(repoURI, "gitlab.") {
repo, makeRepoError = glrepo.MakeGitlabRepo(repoURI)
if makeRepoError != nil {
return repo,
nil,
nil,
nil,
nil,
fmt.Errorf("getting local directory client: %w", makeRepoError)
}
} else {
repo, makeRepoError = ghrepo.MakeGithubRepo(repoURI)
if makeRepoError != nil {
return repo,
nil,
nil,
nil,
nil,
fmt.Errorf("getting local directory client: %w", makeRepoError)
}
}

ossFuzzRepoClient, errOssFuzz := ghrepo.CreateOssFuzzRepoClient(ctx, logger)
Expand All @@ -65,10 +82,28 @@ func GetClients(ctx context.Context, repoURI, localURI string, logger *log.Logge
retErr = fmt.Errorf("getting OSS-Fuzz repo client: %w", errOssFuzz)
}
// TODO(repo): Should we be handling the OSS-Fuzz client error like this?
return githubRepo, /*repo*/
ghrepo.CreateGithubRepoClient(ctx, logger), /*repoClient*/
ossFuzzRepoClient, /*ossFuzzClient*/
clients.DefaultCIIBestPracticesClient(), /*ciiClient*/
clients.DefaultVulnerabilitiesClient(), /*vulnClient*/
retErr
if strings.Contains(repoURI, "gitlab.") {
glClient, err := glrepo.CreateGitlabClientWithToken(ctx, os.Getenv("GITLAB_AUTH_TOKEN"), repo)
if err != nil {
return repo,
nil,
nil,
nil,
nil,
fmt.Errorf("error creating gitlab client: %w", err)
}
return repo, /*repo*/
glClient, /*repoClient*/
ossFuzzRepoClient, /*ossFuzzClient*/
clients.DefaultCIIBestPracticesClient(), /*ciiClient*/
clients.DefaultVulnerabilitiesClient(), /*vulnClient*/
retErr
} else {
return repo, /*repo*/
ghrepo.CreateGithubRepoClient(ctx, logger), /*repoClient*/
ossFuzzRepoClient, /*ossFuzzClient*/
clients.DefaultCIIBestPracticesClient(), /*ciiClient*/
clients.DefaultVulnerabilitiesClient(), /*vulnClient*/
retErr
}
}
22 changes: 17 additions & 5 deletions checks/raw/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ package raw
import (
"errors"
"fmt"
"os"
"path"
"strings"

"github.com/ossf/scorecard/v4/checker"
"github.com/ossf/scorecard/v4/checks/fileparser"
"github.com/ossf/scorecard/v4/clients"
"github.com/ossf/scorecard/v4/clients/githubrepo"
"github.com/ossf/scorecard/v4/clients/gitlabrepo"
sce "github.com/ossf/scorecard/v4/errors"
"github.com/ossf/scorecard/v4/log"
)
Expand Down Expand Up @@ -52,13 +54,23 @@ func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error)
// https#://docs.github.com/en/github/building-a-strong-community/creating-a-default-community-health-file.
// TODO(1491): Make this non-GitHub specific.
logger := log.NewLogger(log.InfoLevel)
dotGitHubClient := githubrepo.CreateGithubRepoClient(c.Ctx, logger)
err = dotGitHubClient.InitRepo(c.Repo.Org(), clients.HeadSHA)
var client clients.RepoClient

if strings.Contains(c.Repo.Org().String(), "gitlab.") {
client, err = gitlabrepo.CreateGitlabClientWithToken(c.Ctx, os.Getenv("GITLAB_AUTH_TOKEN"), c.Repo)
if err != nil {
return checker.SecurityPolicyData{}, err
}
err = client.InitRepo(c.Repo, clients.HeadSHA)
} else {
client = githubrepo.CreateGithubRepoClient(c.Ctx, logger)
err = client.InitRepo(c.Repo.Org(), clients.HeadSHA)
}
switch {
case err == nil:
defer dotGitHubClient.Close()
data.uri = dotGitHubClient.URI()
err = fileparser.OnAllFilesDo(dotGitHubClient, isSecurityPolicyFile, &data)
defer client.Close()
data.uri = client.URI()
err = fileparser.OnAllFilesDo(client, isSecurityPolicyFile, &data)
if err != nil {
return checker.SecurityPolicyData{}, err
}
Expand Down

0 comments on commit 249b65f

Please sign in to comment.