From dfe5f2c25a08846d8712ae55d270d681342e9d3e Mon Sep 17 00:00:00 2001 From: Mor Weinberger Date: Wed, 23 Nov 2022 16:49:27 +0200 Subject: [PATCH] soft failure for failed in information fetching --- internal/commands/scan.go | 2 +- internal/scm-clients/clients/clients.go | 37 ++++++++++++++----------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/internal/commands/scan.go b/internal/commands/scan.go index 28f2f06..31941b1 100644 --- a/internal/commands/scan.go +++ b/internal/commands/scan.go @@ -20,7 +20,7 @@ func NewScanCommand() *cobra.Command { start := time.Now() logger.Infof("%v Fetch Starting", emoji.TriangularFlag) assetsData, supportedChecks, err := clients.FetchClientData(accessToken, repositoryUrl, branch) - if err != nil { + if assetsData.AuthorizedUser == nil || err != nil { logger.Error(err, "Failed to fetch client data") return err } else { diff --git a/internal/scm-clients/clients/clients.go b/internal/scm-clients/clients/clients.go index fb33d9b..784da93 100644 --- a/internal/scm-clients/clients/clients.go +++ b/internal/scm-clients/clients/clients.go @@ -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" ) @@ -37,27 +38,31 @@ func FetchClientData(accessToken string, repoUrl string, branch string) (*checkm 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())) + } } } @@ -70,7 +75,7 @@ func FetchClientData(accessToken string, repoUrl string, branch string) (*checkm BranchProtections: protection, Pipelines: pipelines, Registry: registry, - }, checksIds, nil + }, checksIds, err } func getRepoInfo(repoFullUrl string) (string, string, string, error) {