use GitLab group members REST API

Signed-off-by: Matteo Silvestri <matteosilv@gmail.com>
This commit is contained in:
Matteo Silvestri
2023-10-03 10:38:47 +02:00
parent 4f70fdfc93
commit 753b35afb5
3 changed files with 33 additions and 8 deletions
+9 -2
View File
@@ -2,6 +2,13 @@
'@backstage/plugin-catalog-backend-module-gitlab': patch
---
fix: use publicEmail in GitLab client
fix: use REST API to get root group memberships for GitLab SaaS users listing
client was using commitEmail that is visible only for self-managed GitLab admins. publicEmail is visible, but only if the user explicitly enable the corresponding setting on GitLab.
This API is the only one that shows `email` field for enterprise users and
allows to filter out bot users not using a license using the `is_using_seat`
field.
ref:
https://docs.gitlab.com/ee/user/enterprise_user/#get-users-email-addresses-through-the-api
https://docs.gitlab.com/ee/api/members.html#limitations
@@ -91,6 +91,22 @@ export class GitLabClient {
});
}
async listSaaSUsers(
groupPath: string,
options?: CommonListOptions,
): Promise<PagedResponse<GitLabUser>> {
return this.pagedRequest(
`/groups/${encodeURIComponent(groupPath)}/members`,
{
...options,
show_seat_info: true,
},
).then(resp => {
resp.items = resp.items.filter(user => user.is_using_seat);
return resp;
});
}
async listGroups(
options?: CommonListOptions,
): Promise<PagedResponse<GitLabGroup>> {
@@ -190,12 +190,14 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
});
} else {
groups = (await client.listDescendantGroups(this.config.group)).items;
users = (
await client.getGroupMembers(this.config.group.split('/')[0], [
'DIRECT',
'DESCENDANTS',
])
).items;
const rootGroup = this.config.group.split('/')[0];
users = paginated<GitLabUser>(
options => client.listSaaSUsers(rootGroup, options),
{
page: 1,
per_page: 100,
},
);
}
const idMappedUser: { [userId: number]: GitLabUser } = {};