Skip to content

Commit

Permalink
🧹 allow url option for custom gitlab urls (#2123)
Browse files Browse the repository at this point in the history
* 🧹 allow url option for custom gitlab urls

* fix capitalization of gitlab

Co-authored-by: Tim Smith <[email protected]>

* minor fixes

Signed-off-by: Ivan Milchev <[email protected]>

---------

Signed-off-by: Ivan Milchev <[email protected]>
Co-authored-by: Tim Smith <[email protected]>
Co-authored-by: Ivan Milchev <[email protected]>
  • Loading branch information
3 people authored Oct 9, 2023
1 parent d85c10c commit 186149b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions providers/gitlab/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ var Config = plugin.Provider{
Default: "",
Desc: "a GitLab project to scan",
},
{
Long: "url",
Type: plugin.FlagType_String,
Default: "",
Desc: "custom GitLab base url",
},
},
},
},
Expand Down
8 changes: 7 additions & 1 deletion providers/gitlab/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ func NewGitLabConnection(id uint32, asset *inventory.Asset, conf *inventory.Conf
return nil, errors.New("you need to provide GitLab token e.g. via GITLAB_TOKEN env")
}

client, err := gitlab.NewClient(token)
var opts gitlab.ClientOptionFunc
url := conf.Options["url"]
if url != "" {
opts = gitlab.WithBaseURL(url)
}

client, err := gitlab.NewClient(token, opts)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions providers/gitlab/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error)
}
// it's ok if no group or project is defined.
// we will discover all the groups
if x, ok := flags["url"]; ok {
conf.Options["url"] = string(x.Value)
}

conf.Discover = parseDiscover(flags)
asset := inventory.Asset{
Expand Down

0 comments on commit 186149b

Please sign in to comment.