Skip to content

Commit

Permalink
🐛 use gitlab mql group projects for project init (#1921)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey authored Sep 25, 2023
1 parent d54cda5 commit 06be5cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 0 additions & 2 deletions motor/discovery/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
28 changes: 19 additions & 9 deletions resources/packs/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 06be5cb

Please sign in to comment.