Skip to content
Merged
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
6 changes: 5 additions & 1 deletion backend/plugins/gitlab/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ func (p Gitlab) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]i
if err := regexEnricher.TryAdd(devops.ENV_NAME_PATTERN, op.ScopeConfig.EnvNamePattern); err != nil {
return nil, errors.BadInput.Wrap(err, "invalid value for `envNamePattern`")
}

cfg := taskCtx.GetConfigReader()
op.CollectAllUsers = true
if cfg.IsSet("GITLAB_SERVER_COLLECT_ALL_USERS") {
op.CollectAllUsers = cfg.GetBool("GITLAB_SERVER_COLLECT_ALL_USERS")
}
taskData := tasks.GitlabTaskData{
Options: op,
ApiClient: apiClient,
Expand Down
8 changes: 4 additions & 4 deletions backend/plugins/gitlab/tasks/account_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ func CollectAccounts(taskCtx plugin.SubTaskContext) errors.Error {
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_USER_TABLE)
logger := taskCtx.GetLogger()
logger.Info("collect gitlab users")

// it means we can not use /members/all to get the data
options := taskCtx.GetData().(*GitlabTaskData).Options
urlTemplate := "/projects/{{ .Params.ProjectId }}/members/all"
if semver.Compare(data.ApiClient.GetData(models.GitlabApiClientData_ApiVersion).(string), "v13.11") < 0 {
// it means we can not use /members/all to get the data
urlTemplate = "/projects/{{ .Params.ProjectId }}/members/"
}

// Collect all users if endpoint is private gitlab instance
if !strings.HasPrefix(data.ApiClient.GetEndpoint(), "https://gitlab.com") && !strings.HasPrefix(data.ApiClient.GetEndpoint(), "https://jihulab.com") {
// Collect all users if endpoint is private gitlab instance and GITLAB_SERVER_COLLECT_ALL_USERS
if !strings.HasPrefix(data.ApiClient.GetEndpoint(), "https://gitlab.com") && !strings.HasPrefix(data.ApiClient.GetEndpoint(), "https://jihulab.com") && options.CollectAllUsers {
urlTemplate = "/users"
}

Expand Down
11 changes: 6 additions & 5 deletions backend/plugins/gitlab/tasks/task_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import (
)

type GitlabOptions struct {
ConnectionId uint64 `mapstructure:"connectionId" json:"connectionId"`
ProjectId int `mapstructure:"projectId" json:"projectId"`
FullName string `mapstructure:"fullName" json:"fullName"`
ScopeConfigId uint64 `mapstructure:"scopeConfigId" json:"scopeConfigId"`
ScopeConfig *models.GitlabScopeConfig `mapstructure:"scopeConfig" json:"scopeConfig"`
ConnectionId uint64 `mapstructure:"connectionId" json:"connectionId"`
ProjectId int `mapstructure:"projectId" json:"projectId"`
FullName string `mapstructure:"fullName" json:"fullName"`
ScopeConfigId uint64 `mapstructure:"scopeConfigId" json:"scopeConfigId"`
ScopeConfig *models.GitlabScopeConfig `mapstructure:"scopeConfig" json:"scopeConfig"`
CollectAllUsers bool
}

type GitlabTaskData struct {
Expand Down
5 changes: 5 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ ENDPOINT_CIDR_BLACKLIST=
# Do not follow redirection when requesting data source APIs
FORBID_REDIRECTION=false

##########################
# Plugin settings
##########################
GITLAB_SERVER_COLLECT_ALL_USERS=true

##########################
# In plugin gitextractor, use go-git to collector repo's data
##########################
Expand Down
Loading