Skip to content

Commit 61fdbb6

Browse files
authored
feat(gitlab): add toggle for collecting all users (#8528)
- Add GITLAB_SERVER_COLLECT_ALL_USERS configuration option - Implement logic to collect all users when enabled - Update task data and configuration reader to support new option - Modify account collector to use new option #8523
1 parent 3238fc4 commit 61fdbb6

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

backend/plugins/gitlab/impl/impl.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ func (p Gitlab) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]i
207207
if err := regexEnricher.TryAdd(devops.ENV_NAME_PATTERN, op.ScopeConfig.EnvNamePattern); err != nil {
208208
return nil, errors.BadInput.Wrap(err, "invalid value for `envNamePattern`")
209209
}
210-
210+
cfg := taskCtx.GetConfigReader()
211+
op.CollectAllUsers = true
212+
if cfg.IsSet("GITLAB_SERVER_COLLECT_ALL_USERS") {
213+
op.CollectAllUsers = cfg.GetBool("GITLAB_SERVER_COLLECT_ALL_USERS")
214+
}
211215
taskData := tasks.GitlabTaskData{
212216
Options: op,
213217
ApiClient: apiClient,

backend/plugins/gitlab/tasks/account_collector.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ func CollectAccounts(taskCtx plugin.SubTaskContext) errors.Error {
5050
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_USER_TABLE)
5151
logger := taskCtx.GetLogger()
5252
logger.Info("collect gitlab users")
53-
54-
// it means we can not use /members/all to get the data
53+
options := taskCtx.GetData().(*GitlabTaskData).Options
5554
urlTemplate := "/projects/{{ .Params.ProjectId }}/members/all"
5655
if semver.Compare(data.ApiClient.GetData(models.GitlabApiClientData_ApiVersion).(string), "v13.11") < 0 {
56+
// it means we can not use /members/all to get the data
5757
urlTemplate = "/projects/{{ .Params.ProjectId }}/members/"
5858
}
5959

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

backend/plugins/gitlab/tasks/task_data.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ import (
2424
)
2525

2626
type GitlabOptions struct {
27-
ConnectionId uint64 `mapstructure:"connectionId" json:"connectionId"`
28-
ProjectId int `mapstructure:"projectId" json:"projectId"`
29-
FullName string `mapstructure:"fullName" json:"fullName"`
30-
ScopeConfigId uint64 `mapstructure:"scopeConfigId" json:"scopeConfigId"`
31-
ScopeConfig *models.GitlabScopeConfig `mapstructure:"scopeConfig" json:"scopeConfig"`
27+
ConnectionId uint64 `mapstructure:"connectionId" json:"connectionId"`
28+
ProjectId int `mapstructure:"projectId" json:"projectId"`
29+
FullName string `mapstructure:"fullName" json:"fullName"`
30+
ScopeConfigId uint64 `mapstructure:"scopeConfigId" json:"scopeConfigId"`
31+
ScopeConfig *models.GitlabScopeConfig `mapstructure:"scopeConfig" json:"scopeConfig"`
32+
CollectAllUsers bool
3233
}
3334

3435
type GitlabTaskData struct {

env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ ENDPOINT_CIDR_BLACKLIST=
6969
# Do not follow redirection when requesting data source APIs
7070
FORBID_REDIRECTION=false
7171

72+
##########################
73+
# Plugin settings
74+
##########################
75+
GITLAB_SERVER_COLLECT_ALL_USERS=true
76+
7277
##########################
7378
# In plugin gitextractor, use go-git to collector repo's data
7479
##########################

0 commit comments

Comments
 (0)