Added wrapper around fetching users from gitlab group to make it fail gracefully
Signed-off-by: Jasper Boeijenga <jboeijenga@gmail.com>
This commit is contained in:
@@ -13,18 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import fetch from 'node-fetch';
|
||||
import {
|
||||
getGitLabRequestOptions,
|
||||
GitLabIntegrationConfig,
|
||||
} from '@backstage/integration';
|
||||
import fetch from 'node-fetch';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
import {
|
||||
GitLabGroup,
|
||||
GitLabDescendantGroupsResponse,
|
||||
GitLabGroup,
|
||||
GitLabGroupMembersResponse,
|
||||
GitLabUser,
|
||||
PagedResponse,
|
||||
} from './types';
|
||||
|
||||
export type CommonListOptions = {
|
||||
@@ -44,11 +45,6 @@ interface UserListOptions extends CommonListOptions {
|
||||
exclude_internal?: boolean | undefined;
|
||||
}
|
||||
|
||||
export type PagedResponse<T> = {
|
||||
items: T[];
|
||||
nextPage?: number;
|
||||
};
|
||||
|
||||
export class GitLabClient {
|
||||
private readonly config: GitLabIntegrationConfig;
|
||||
private readonly logger: Logger;
|
||||
|
||||
@@ -13,9 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TaskScheduleDefinition } from '@backstage/backend-tasks';
|
||||
|
||||
export type PagedResponse<T> = {
|
||||
items: T[];
|
||||
nextPage?: number;
|
||||
};
|
||||
|
||||
export type GitlabGroupDescription = {
|
||||
id: number;
|
||||
web_url: string;
|
||||
|
||||
+16
-13
@@ -13,31 +13,31 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';
|
||||
import {
|
||||
ANNOTATION_LOCATION,
|
||||
ANNOTATION_ORIGIN_LOCATION,
|
||||
Entity,
|
||||
GroupEntity,
|
||||
UserEntity,
|
||||
} from '@backstage/catalog-model';
|
||||
import { Config } from '@backstage/config';
|
||||
import { GitLabIntegration, ScmIntegrations } from '@backstage/integration';
|
||||
import {
|
||||
EntityProvider,
|
||||
EntityProviderConnection,
|
||||
} from '@backstage/plugin-catalog-node';
|
||||
import { merge } from 'lodash';
|
||||
import * as uuid from 'uuid';
|
||||
import { Logger } from 'winston';
|
||||
|
||||
import {
|
||||
GitLabClient,
|
||||
GitlabProviderConfig,
|
||||
paginated,
|
||||
readGitlabConfigs,
|
||||
} from '../lib';
|
||||
import { GitLabGroup, GitLabUser } from '../lib/types';
|
||||
import {
|
||||
ANNOTATION_LOCATION,
|
||||
ANNOTATION_ORIGIN_LOCATION,
|
||||
Entity,
|
||||
UserEntity,
|
||||
GroupEntity,
|
||||
} from '@backstage/catalog-model';
|
||||
import { merge } from 'lodash';
|
||||
import { GitLabGroup, GitLabUser, PagedResponse } from '../lib/types';
|
||||
|
||||
type Result = {
|
||||
scanned: number;
|
||||
@@ -245,9 +245,12 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
groupRes.scanned++;
|
||||
groupRes.matches.push(group);
|
||||
|
||||
const groupUsers = await client.getGroupMembers(group.full_path, [
|
||||
'DIRECT',
|
||||
]);
|
||||
let groupUsers: PagedResponse<GitLabUser> = { items: [] };
|
||||
try {
|
||||
groupUsers = await client.getGroupMembers(group.full_path, ['DIRECT']);
|
||||
} catch {
|
||||
logger.error(`Failed fetching user for group: ${group.full_path}`);
|
||||
}
|
||||
|
||||
for (const groupUser of groupUsers.items) {
|
||||
const user = idMappedUser[groupUser.id];
|
||||
|
||||
Reference in New Issue
Block a user