Skip to content

Commit

Permalink
soft failure for failed in information fetching (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
morwn authored Nov 24, 2022
1 parent ea7d32d commit d687016
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
3 changes: 1 addition & 2 deletions internal/commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ func NewScanCommand() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
start := time.Now()
logger.Infof("%v Fetch Starting", emoji.TriangularFlag)

assetsData, supportedChecks, err := clients.FetchClientData(accessToken, repositoryUrl, scmPlatform, branch)
if err != nil {
if assetsData.AuthorizedUser == nil || err != nil {
logger.Error(err, "Failed to fetch client data")
return err
} else {
Expand Down
37 changes: 21 additions & 16 deletions internal/scm-clients/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/aquasecurity/chain-bench/internal/scm-clients/github"
"github.com/aquasecurity/chain-bench/internal/scm-clients/gitlab"
"github.com/aquasecurity/chain-bench/internal/utils"
pipelineModels "github.com/argonsecurity/pipeline-parser/pkg/models"
"github.com/enescakir/emoji"
)

Expand Down Expand Up @@ -47,27 +48,31 @@ func FetchClientData(accessToken string, repoUrl string, scmPlatform string, bra
repo, _ := adapter.GetRepository(orgName, repoName, branch)
logger.FetchingFinished("Repository Settings", emoji.OilDrum)

branchName := utils.GetBranchName(utils.GetValue(repo.DefaultBranch), branch)
var protection *models.Protection
var pipelines []*pipelineModels.Pipeline
var org *models.Organization
var registry *models.PackageRegistry

logger.FetchingFinished("Branch Protection Settings", emoji.Seedling)
protection, _ := adapter.GetBranchProtection(orgName, repo, branchName)
if repo != nil {
branchName := utils.GetBranchName(utils.GetValue(repo.DefaultBranch), branch)

pipelines, _ := adapter.GetPipelines(orgName, repoName, branchName)
logger.FetchingFinished("Pipelines", emoji.Wrench)
logger.FetchingFinished("Branch Protection Settings", emoji.Seedling)
protection, _ = adapter.GetBranchProtection(orgName, repo, branchName)

var org *models.Organization
var registry *models.PackageRegistry
pipelines, _ = adapter.GetPipelines(orgName, repoName, branchName)
logger.FetchingFinished("Pipelines", emoji.Wrench)

if *repo.Owner.Type == "Organization" {
org, _ = adapter.GetOrganization(orgName)
logger.FetchingFinished("Organization Settings", emoji.OfficeBuilding)
if *repo.Owner.Type == "Organization" {
org, _ = adapter.GetOrganization(orgName)
logger.FetchingFinished("Organization Settings", emoji.OfficeBuilding)

registry, _ = adapter.GetRegistry(org)
registry, _ = adapter.GetRegistry(org)

orgMembers, err := adapter.ListOrganizationMembers(orgName)
if err == nil {
org.Members = orgMembers
logger.FetchingFinished("Members", emoji.Emoji(emoji.WomanAndManHoldingHands.Tone()))
orgMembers, err := adapter.ListOrganizationMembers(orgName)
if err == nil {
org.Members = orgMembers
logger.FetchingFinished("Members", emoji.Emoji(emoji.WomanAndManHoldingHands.Tone()))
}
}
}

Expand All @@ -80,7 +85,7 @@ func FetchClientData(accessToken string, repoUrl string, scmPlatform string, bra
BranchProtections: protection,
Pipelines: pipelines,
Registry: registry,
}, checksIds, nil
}, checksIds, err
}

func getRepoInfo(repoFullUrl string) (string, string, string, error) {
Expand Down

0 comments on commit d687016

Please sign in to comment.