From 06be5cbf7a7a5d111a1215ad33fbe28df84c1479 Mon Sep 17 00:00:00 2001 From: vjeffrey Date: Mon, 25 Sep 2023 14:55:42 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20use=20gitlab=20mql=20group=20pro?= =?UTF-8?q?jects=20for=20project=20init=20(#1921)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- motor/discovery/gitlab/gitlab.go | 2 -- resources/packs/gitlab/gitlab.go | 28 +++++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/motor/discovery/gitlab/gitlab.go b/motor/discovery/gitlab/gitlab.go index 2d95ee6ee3..4a9dda03c8 100644 --- a/motor/discovery/gitlab/gitlab.go +++ b/motor/discovery/gitlab/gitlab.go @@ -131,8 +131,6 @@ func (r *Resolver) Resolve(ctx context.Context, root *asset.Asset, pCfg *provide }) if pCfg.IncludesOneOfDiscoveryTarget(common.DiscoveryAuto, common.DiscoveryAll, DiscoveryProject) { - p.Client().Projects.ListProjects(&gitlab.ListProjectsOptions{}) - for _, project := range grp.Projects { clonedConfig := pCfg.Clone() if clonedConfig.Options == nil { diff --git a/resources/packs/gitlab/gitlab.go b/resources/packs/gitlab/gitlab.go index 8ecf319e17..65e52cbcaa 100644 --- a/resources/packs/gitlab/gitlab.go +++ b/resources/packs/gitlab/gitlab.go @@ -2,9 +2,9 @@ package gitlab import ( "errors" - "net/url" "strconv" + "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/motor/providers" provider "go.mondoo.com/cnquery/motor/providers/gitlab" "go.mondoo.com/cnquery/resources" @@ -111,18 +111,28 @@ func (g *mqlGitlabProject) init(args *resources.Args) (*resources.Args, GitlabPr if err != nil { return nil, nil, err } - - project, _, err := gt.Client().Projects.GetProject(url.QueryEscape(gt.GroupPath)+"/"+url.QueryEscape(gt.ProjectPath), nil) + obj, err := g.MotorRuntime.CreateResource("gitlab.group") if err != nil { return nil, nil, err } + gr := obj.(*mqlGitlabGroup) - (*args)["id"] = int64(project.ID) - (*args)["name"] = project.Name - (*args)["path"] = project.Path - (*args)["namespace"] = project.Namespace.Name - (*args)["description"] = project.Description - (*args)["visibility"] = string(project.Visibility) + rawResources, err := gr.Projects() + if err != nil { + return nil, nil, err + } + matcher := gt.ProjectPath + for i := range rawResources { + proj := rawResources[i].(*mqlGitlabProject) + mqlPath, err := proj.Path() + if err != nil { + log.Error().Err(err).Msg("project is not initialized") + return nil, nil, err + } + if mqlPath == matcher { + return args, proj, nil + } + } return args, nil, nil }