Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

feat: Support for Self-Hosted Gitlab. #115

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

var ConfigAvailableKeys = []string{"token"}
var ConfigAvailableKeys = []string{"token", "gitlabClientURL"}

type ConfigCommandDependencies struct {
ConfigurationManager *configurationManager.ConfigurationManager
Expand Down
30 changes: 29 additions & 1 deletion pkg/clients/gitlabClient.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
package clients

import (
"fmt"
"github.com/allero-io/allero/pkg/configurationManager"
"github.com/xanzy/go-gitlab"
)

func CreateGitlabClient(configurationManager configurationManager.ConfigurationManager) (*gitlab.Client, error) {
GITLAB_TOKEN := configurationManager.GetGitlabToken()
gitlabClient, err := gitlab.NewClient(GITLAB_TOKEN)
gitlabPrivateServerUrl := ""

gitlabCustomServerValue, err := configurationManager.Get("gitlabClientURL")
if err != nil {
return nil, err
}

if gitlabCustomServerValue != nil {
gitlabPrivateServerUrl = fmt.Sprintf("%s", gitlabCustomServerValue)
}

gitlabClient, err := generateGitlabClient(GITLAB_TOKEN, gitlabPrivateServerUrl)
if err != nil {
return nil, err
}

return gitlabClient, nil
}

func generateGitlabClient(gitlabToken, gitlabPrivateServerUrl string) (*gitlab.Client, error) {
if gitlabPrivateServerUrl != "" {
gitlabClient, err := gitlab.NewClient(gitlabToken, gitlab.WithBaseURL(gitlabPrivateServerUrl))
if err != nil {
return nil, err
}
return gitlabClient, nil
}

gitlabClient, err := gitlab.NewClient(gitlabToken)
if err != nil {
return nil, err
}
return gitlabClient, nil
}