Skip to content

Commit 776cf8f

Browse files
authored
Merge pull request #60 from ConductorOne/lauren/log-member-counts
Add profile fields/use simple param for reduced api response
2 parents 5e6c5dc + 28b2867 commit 776cf8f

File tree

4 files changed

+44
-18
lines changed

4 files changed

+44
-18
lines changed

pkg/connector/client/client.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ func (c *GitlabClient) ListProjects(ctx context.Context, groupID string, nextLin
277277
opts := KeysetPaginationOpts{OrderBy: "id", Sort: "asc"}
278278

279279
newNextLink, rateLimitDesc, err := c.listWithKeysetPagination(ctx, endpoint, nextLink, &projects, opts,
280-
WithQueryParam("include_subgroups", "true"))
280+
WithQueryParam("include_subgroups", "true"),
281+
WithQueryParam("simple", "true"),
282+
)
281283
if err != nil {
282284
return nil, "", rateLimitDesc, err
283285
}

pkg/connector/client/models.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,29 @@ import (
55
)
66

77
type User struct {
8-
ID int `json:"id"`
9-
Email string `json:"email"`
10-
Username string `json:"username"`
11-
Name string `json:"name"`
12-
State string `json:"state"`
13-
LastActivityOn *ISOTime `json:"last_activity_on"`
8+
ID int `json:"id"`
9+
Email string `json:"email"`
10+
Username string `json:"username"`
11+
Name string `json:"name"`
12+
State string `json:"state"`
13+
LastActivityOn *ISOTime `json:"last_activity_on"`
14+
MembershipState string `json:"membership_state"`
15+
Locked bool `json:"locked"`
1416
}
1517

1618
type PendingInviteUser struct {
1719
InviteEmail string `json:"invite_email"`
1820
}
1921

2022
type Group struct {
21-
ID int `json:"id"`
22-
Name string `json:"name"`
23-
Description string `json:"description"`
24-
FullName string `json:"full_name"`
25-
ParentID int `json:"parent_id"`
23+
ID int `json:"id"`
24+
Name string `json:"name"`
25+
Description string `json:"description"`
26+
FullName string `json:"full_name"`
27+
ParentID int `json:"parent_id"`
28+
Archived bool `json:"archived"`
29+
Visibility string `json:"visibility"`
30+
MarkedForDeletion *ISOTime `json:"marked_for_deletion"`
2631
}
2732

2833
type Namespace struct {
@@ -50,6 +55,8 @@ type GroupMember struct {
5055
State string `json:"state"`
5156
AccessLevel int `json:"access_level"`
5257
GroupSAMLIdentity *SAMLIdentity `json:"group_saml_identity"`
58+
MembershipState string `json:"membership_state"`
59+
Locked bool `json:"locked"`
5360
}
5461

5562
type ProjectMember struct {

pkg/connector/groups.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"strconv"
99
"strings"
10+
"time"
1011

1112
"github.com/conductorone/baton-gitlab/pkg/connector/client"
1213
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
@@ -275,7 +276,14 @@ func groupResource(group *client.Group, parentResourceID *v2.ResourceId, isOnPre
275276
"name": group.Name,
276277
"full_name": group.FullName,
277278
"description": group.Description,
279+
"archived": group.Archived,
280+
"visibility": group.Visibility,
278281
}
282+
283+
if group.MarkedForDeletion != nil && !time.Time(*group.MarkedForDeletion).IsZero() {
284+
profile["marked_for_deletion"] = time.Time(*group.MarkedForDeletion)
285+
}
286+
279287
if group.ParentID != 0 {
280288
profile["parent_group_id"] = group.ParentID
281289
}

pkg/connector/users.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ func userResource(user any) (*v2.Resource, error) {
391391
var name string
392392
var state string
393393
var accessLevel int
394+
var membershipState string
395+
var locked *bool
394396
// NOTE: The last login attribute is only visible in the DC version (on-premise/self-hosted). To get this attribute you need admin permissions and in the cloud version it does not exist.
395397
// https://docs.gitlab.com/api/users/
396398
var lastLogin time.Time
@@ -403,6 +405,9 @@ func userResource(user any) (*v2.Resource, error) {
403405
name = user.Name
404406
username = user.Username
405407
accessLevel = user.AccessLevel
408+
membershipState = user.MembershipState
409+
lockedVal := user.Locked
410+
locked = &lockedVal
406411
case *client.ProjectMember:
407412
id = user.ID
408413
email = user.Email
@@ -452,12 +457,16 @@ func userResource(user any) (*v2.Resource, error) {
452457
}
453458

454459
profile := map[string]interface{}{
455-
"first_name": name,
456-
"username": username,
457-
"email": email,
458-
"state": state,
459-
"access_level": accessLevel,
460-
"id": id,
460+
"first_name": name,
461+
"username": username,
462+
"email": email,
463+
"state": state,
464+
"access_level": accessLevel,
465+
"id": id,
466+
"membership_state": membershipState,
467+
}
468+
if locked != nil {
469+
profile["locked"] = *locked
461470
}
462471

463472
userTraitOptions := []resourceSdk.UserTraitOption{

0 commit comments

Comments
 (0)