Skip to content

Commit 3ac4a32

Browse files
committed
changed empty strings to nil, when passing emoty admin configs, also GetMember in Groups now runs in parallel
1 parent 4bdefcf commit 3ac4a32

3 files changed

Lines changed: 29 additions & 17 deletions

File tree

internal/accesscontrol/external_entity_provider_rbac_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestHasAccess(t *testing.T) {
176176
nil,
177177
thirdpartyIntegrationMock,
178178
"external-entity-provider-id",
179-
utils.Ptr(""),
179+
nil,
180180
)
181181

182182
hasAccess, err := rbac.HasAccess("user1")
@@ -191,7 +191,7 @@ func TestHasAccess(t *testing.T) {
191191
nil,
192192
thirdpartyIntegrationMock,
193193
"external-entity-provider-id",
194-
utils.Ptr(""),
194+
nil,
195195
)
196196

197197
hasAccess, err := rbac.HasAccess("user1")

internal/core/integrations/gitlabint/gitlab_integration.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -346,23 +346,35 @@ func (g *GitlabIntegration) ListGroups(ctx core.Context, userID string, provider
346346
return nil, err
347347
}
348348

349-
cleanedGroups := make([]*gitlab.Group, 0, len(groups))
350-
349+
errgroup := utils.ErrGroup[*gitlab.Group](10)
351350
for _, group := range groups {
352-
//only check if we are member of the given group
353-
member, _, err := gitlabClient.GetMemberInGroup(ctx.Request().Context(), token.GitLabUserID, (*group).ID)
354-
if err != nil {
355-
if strings.Contains(err.Error(), "403 Forbidden") || strings.Contains(err.Error(), "404 Not Found") {
356-
//swallow the error
357-
continue
358-
} else {
359-
return nil, err
351+
errgroup.Go(func() (*gitlab.Group, error) {
352+
member, _, err := gitlabClient.GetMemberInGroup(ctx.Request().Context(), token.GitLabUserID, (*group).ID)
353+
if err != nil {
354+
if strings.Contains(err.Error(), "403 Forbidden") || strings.Contains(err.Error(), "404 Not Found") {
355+
return nil, nil
356+
} else {
357+
358+
return nil, err
359+
}
360360
}
361-
}
362-
if member.AccessLevel >= gitlab.ReporterPermissions {
363-
cleanedGroups = append(cleanedGroups, group)
364-
}
361+
if member.AccessLevel >= gitlab.ReporterPermissions {
362+
return group, nil
363+
}
364+
return nil, nil
365+
})
366+
}
365367

368+
allGroups, err := errgroup.WaitAndCollect()
369+
if err != nil {
370+
return nil, err
371+
}
372+
// filter all the nil values from the result
373+
cleanedGroups := make([]*gitlab.Group, 0, len(groups))
374+
for i := range allGroups {
375+
if allGroups[i] != nil {
376+
cleanedGroups = append(cleanedGroups, allGroups[i])
377+
}
366378
}
367379

368380
return utils.Map(cleanedGroups, func(el *gitlab.Group) models.Project {

internal/core/integrations/gitlabint/gitlab_oauth2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func parseGitlabEnvs() map[string]gitlabEnvConfig {
106106
conf.botUserAccessToken = value
107107
case "admintoken":
108108
if value == "" {
109-
conf.adminToken = utils.Ptr("")
109+
conf.adminToken = nil
110110
} else {
111111
conf.adminToken = &value
112112
}

0 commit comments

Comments
 (0)