@backstage/plugin-catalog-backend-module-gitlab 0.3.6 → 0.3.7-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @backstage/plugin-catalog-backend-module-gitlab
2
2
 
3
+ ## 0.3.7-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 60e4c2a: Added the option to provide custom `groupTransformer`, `userTransformer` and `groupNameTransformer` to allow custom transformations of groups and users
8
+ - Updated dependencies
9
+ - @backstage/backend-common@0.21.0-next.0
10
+ - @backstage/backend-tasks@0.5.15-next.0
11
+ - @backstage/plugin-catalog-node@1.6.2-next.0
12
+ - @backstage/backend-plugin-api@0.6.10-next.0
13
+ - @backstage/catalog-model@1.4.3
14
+ - @backstage/config@1.1.1
15
+ - @backstage/integration@1.8.0
16
+
3
17
  ## 0.3.6
4
18
 
5
19
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend-module-gitlab",
3
- "version": "0.3.6",
3
+ "version": "0.3.7-next.0",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/index.cjs.js CHANGED
@@ -158,6 +158,99 @@ function parseUrl(urlString) {
158
158
  throw new Error(`Failed to parse ${urlString}`);
159
159
  }
160
160
 
161
+ function defaultGroupNameTransformer(options) {
162
+ if (options.providerConfig.group && options.group.full_path.startsWith(`${options.providerConfig.group}/`)) {
163
+ return options.group.full_path.replace(`${options.providerConfig.group}/`, "").replaceAll("/", "-");
164
+ }
165
+ return options.group.full_path.replaceAll("/", "-");
166
+ }
167
+ function defaultGroupEntitiesTransformer(options) {
168
+ const idMapped = {};
169
+ const entities = [];
170
+ for (const group of options.groups) {
171
+ idMapped[group.id] = group;
172
+ }
173
+ for (const group of options.groups) {
174
+ const annotations = {};
175
+ annotations[`${options.providerConfig.host}/team-path`] = group.full_path;
176
+ const entity = {
177
+ apiVersion: "backstage.io/v1alpha1",
178
+ kind: "Group",
179
+ metadata: {
180
+ name: options.groupNameTransformer({
181
+ group,
182
+ providerConfig: options.providerConfig
183
+ }),
184
+ annotations
185
+ },
186
+ spec: {
187
+ type: "team",
188
+ children: [],
189
+ profile: {
190
+ displayName: group.name
191
+ }
192
+ }
193
+ };
194
+ if (group.description) {
195
+ entity.metadata.description = group.description;
196
+ }
197
+ if (group.parent_id && idMapped.hasOwnProperty(group.parent_id)) {
198
+ entity.spec.parent = options.groupNameTransformer({
199
+ group: idMapped[group.parent_id],
200
+ providerConfig: options.providerConfig
201
+ });
202
+ }
203
+ entities.push(entity);
204
+ }
205
+ return entities;
206
+ }
207
+ function defaultUserTransformer(options) {
208
+ var _a, _b;
209
+ const annotations = {};
210
+ annotations[`${options.integrationConfig.host}/user-login`] = options.user.web_url;
211
+ if ((_b = (_a = options.user) == null ? void 0 : _a.group_saml_identity) == null ? void 0 : _b.extern_uid) {
212
+ annotations[`${options.integrationConfig.host}/saml-external-uid`] = options.user.group_saml_identity.extern_uid;
213
+ }
214
+ const entity = {
215
+ apiVersion: "backstage.io/v1alpha1",
216
+ kind: "User",
217
+ metadata: {
218
+ name: options.user.username,
219
+ annotations
220
+ },
221
+ spec: {
222
+ profile: {
223
+ displayName: options.user.name || void 0,
224
+ picture: options.user.avatar_url || void 0
225
+ },
226
+ memberOf: []
227
+ }
228
+ };
229
+ if (options.user.email) {
230
+ if (!entity.spec) {
231
+ entity.spec = {};
232
+ }
233
+ if (!entity.spec.profile) {
234
+ entity.spec.profile = {};
235
+ }
236
+ entity.spec.profile.email = options.user.email;
237
+ }
238
+ if (options.user.groups) {
239
+ for (const group of options.user.groups) {
240
+ if (!entity.spec.memberOf) {
241
+ entity.spec.memberOf = [];
242
+ }
243
+ entity.spec.memberOf.push(
244
+ options.groupNameTransformer({
245
+ group,
246
+ providerConfig: options.providerConfig
247
+ })
248
+ );
249
+ }
250
+ }
251
+ return entity;
252
+ }
253
+
161
254
  var __defProp = Object.defineProperty;
162
255
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
163
256
  var __publicField = (obj, key, value) => {
@@ -171,12 +264,19 @@ class GitlabOrgDiscoveryEntityProvider {
171
264
  __publicField(this, "logger");
172
265
  __publicField(this, "scheduleFn");
173
266
  __publicField(this, "connection");
267
+ __publicField(this, "userTransformer");
268
+ __publicField(this, "groupEntitiesTransformer");
269
+ __publicField(this, "groupNameTransformer");
270
+ var _a, _b, _c;
174
271
  this.config = options.config;
175
272
  this.integration = options.integration;
176
273
  this.logger = options.logger.child({
177
274
  target: this.getProviderName()
178
275
  });
179
276
  this.scheduleFn = this.createScheduleFn(options.taskRunner);
277
+ this.userTransformer = (_a = options.userTransformer) != null ? _a : defaultUserTransformer;
278
+ this.groupEntitiesTransformer = (_b = options.groupEntitiesTransformer) != null ? _b : defaultGroupEntitiesTransformer;
279
+ this.groupNameTransformer = (_c = options.groupNameTransformer) != null ? _c : defaultGroupNameTransformer;
180
280
  }
181
281
  static fromConfig(config, options) {
182
282
  if (!options.schedule && !options.scheduler) {
@@ -333,12 +433,18 @@ class GitlabOrgDiscoveryEntityProvider {
333
433
  }).length > 0;
334
434
  });
335
435
  const userEntities = res.matches.map(
336
- (p) => this.createUserEntity(p, this.integration.config.host)
337
- );
338
- const groupEntities = this.createGroupEntities(
339
- groupsWithUsers,
340
- this.integration.config.host
436
+ (p) => this.userTransformer({
437
+ user: p,
438
+ integrationConfig: this.integration.config,
439
+ providerConfig: this.config,
440
+ groupNameTransformer: this.groupNameTransformer
441
+ })
341
442
  );
443
+ const groupEntities = this.groupEntitiesTransformer({
444
+ groups: groupsWithUsers,
445
+ providerConfig: this.config,
446
+ groupNameTransformer: this.groupNameTransformer
447
+ });
342
448
  await this.connection.applyMutation({
343
449
  type: "full",
344
450
  entities: [...userEntities, ...groupEntities].map((entity) => ({
@@ -351,23 +457,6 @@ class GitlabOrgDiscoveryEntityProvider {
351
457
  }))
352
458
  });
353
459
  }
354
- createGroupEntities(groupResult, host) {
355
- const idMapped = {};
356
- const entities = [];
357
- for (const group of groupResult) {
358
- idMapped[group.id] = group;
359
- }
360
- for (const group of groupResult) {
361
- const entity = this.createGroupEntity(group, host);
362
- if (group.parent_id && idMapped.hasOwnProperty(group.parent_id)) {
363
- entity.spec.parent = this.groupName(
364
- idMapped[group.parent_id].full_path
365
- );
366
- }
367
- entities.push(entity);
368
- }
369
- return entities;
370
- }
371
460
  withLocations(host, baseUrl, entity) {
372
461
  var _a;
373
462
  const location = entity.kind === "Group" ? `url:${baseUrl}/${(_a = entity.metadata.annotations) == null ? void 0 : _a[`${host}/team-path`]}` : `url:${baseUrl}/${entity.metadata.name}`;
@@ -383,76 +472,6 @@ class GitlabOrgDiscoveryEntityProvider {
383
472
  entity
384
473
  );
385
474
  }
386
- createUserEntity(user, host) {
387
- var _a;
388
- const annotations = {};
389
- annotations[`${host}/user-login`] = user.web_url;
390
- if ((_a = user == null ? void 0 : user.group_saml_identity) == null ? void 0 : _a.extern_uid) {
391
- annotations[`${host}/saml-external-uid`] = user.group_saml_identity.extern_uid;
392
- }
393
- const entity = {
394
- apiVersion: "backstage.io/v1alpha1",
395
- kind: "User",
396
- metadata: {
397
- name: user.username,
398
- annotations
399
- },
400
- spec: {
401
- profile: {
402
- displayName: user.name || void 0,
403
- picture: user.avatar_url || void 0
404
- },
405
- memberOf: []
406
- }
407
- };
408
- if (user.email) {
409
- if (!entity.spec) {
410
- entity.spec = {};
411
- }
412
- if (!entity.spec.profile) {
413
- entity.spec.profile = {};
414
- }
415
- entity.spec.profile.email = user.email;
416
- }
417
- if (user.groups) {
418
- for (const group of user.groups) {
419
- if (!entity.spec.memberOf) {
420
- entity.spec.memberOf = [];
421
- }
422
- entity.spec.memberOf.push(this.groupName(group.full_path));
423
- }
424
- }
425
- return entity;
426
- }
427
- groupName(full_path) {
428
- if (this.config.group && full_path.startsWith(`${this.config.group}/`)) {
429
- return full_path.replace(`${this.config.group}/`, "").replaceAll("/", "-");
430
- }
431
- return full_path.replaceAll("/", "-");
432
- }
433
- createGroupEntity(group, host) {
434
- const annotations = {};
435
- annotations[`${host}/team-path`] = group.full_path;
436
- const entity = {
437
- apiVersion: "backstage.io/v1alpha1",
438
- kind: "Group",
439
- metadata: {
440
- name: this.groupName(group.full_path),
441
- annotations
442
- },
443
- spec: {
444
- type: "team",
445
- children: [],
446
- profile: {
447
- displayName: group.name
448
- }
449
- }
450
- };
451
- if (group.description) {
452
- entity.metadata.description = group.description;
453
- }
454
- return entity;
455
- }
456
475
  }
457
476
 
458
477
  exports.GitlabDiscoveryEntityProvider = GitlabDiscoveryEntityProvider.GitlabDiscoveryEntityProvider;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/GitLabDiscoveryProcessor.ts","../src/providers/GitlabOrgDiscoveryEntityProvider.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n CacheClient,\n CacheManager,\n PluginCacheManager,\n} from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport {\n ScmIntegrationRegistry,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n CatalogProcessor,\n CatalogProcessorEmit,\n LocationSpec,\n processingResult,\n} from '@backstage/plugin-catalog-node';\nimport { Logger } from 'winston';\nimport { GitLabClient, GitLabProject, paginated } from './lib';\n\n/**\n * Extracts repositories out of an GitLab instance.\n * @public\n */\nexport class GitLabDiscoveryProcessor implements CatalogProcessor {\n private readonly integrations: ScmIntegrationRegistry;\n private readonly logger: Logger;\n private readonly cache: CacheClient;\n private readonly skipReposWithoutExactFileMatch: boolean;\n private readonly skipForkedRepos: boolean;\n\n static fromConfig(\n config: Config,\n options: {\n logger: Logger;\n skipReposWithoutExactFileMatch?: boolean;\n skipForkedRepos?: boolean;\n },\n ): GitLabDiscoveryProcessor {\n const integrations = ScmIntegrations.fromConfig(config);\n const pluginCache =\n CacheManager.fromConfig(config).forPlugin('gitlab-discovery');\n\n return new GitLabDiscoveryProcessor({\n ...options,\n integrations,\n pluginCache,\n });\n }\n\n private constructor(options: {\n integrations: ScmIntegrationRegistry;\n pluginCache: PluginCacheManager;\n logger: Logger;\n skipReposWithoutExactFileMatch?: boolean;\n skipForkedRepos?: boolean;\n }) {\n this.integrations = options.integrations;\n this.cache = options.pluginCache.getClient();\n this.logger = options.logger;\n this.skipReposWithoutExactFileMatch =\n options.skipReposWithoutExactFileMatch || false;\n this.skipForkedRepos = options.skipForkedRepos || false;\n }\n\n getProcessorName(): string {\n return 'GitLabDiscoveryProcessor';\n }\n\n async readLocation(\n location: LocationSpec,\n _optional: boolean,\n emit: CatalogProcessorEmit,\n ): Promise<boolean> {\n if (location.type !== 'gitlab-discovery') {\n return false;\n }\n\n const startTime = new Date();\n const { group, host, branch, catalogPath } = parseUrl(location.target);\n\n const integration = this.integrations.gitlab.byUrl(`https://${host}`);\n if (!integration) {\n throw new Error(\n `There is no GitLab integration that matches ${host}. Please add a configuration entry for it under integrations.gitlab`,\n );\n }\n\n const client = new GitLabClient({\n config: integration.config,\n logger: this.logger,\n });\n this.logger.debug(`Reading GitLab projects from ${location.target}`);\n\n const lastActivity = (await this.cache.get(this.getCacheKey())) as string;\n const opts = {\n archived: false,\n group,\n page: 1,\n // We check for the existence of lastActivity and only set it if it's present to ensure\n // that the options doesn't include the key so that the API doesn't receive an empty query parameter.\n ...(lastActivity && { last_activity_after: lastActivity }),\n };\n\n const projects = paginated(options => client.listProjects(options), opts);\n\n const res: Result = {\n scanned: 0,\n matches: [],\n };\n for await (const project of projects) {\n res.scanned++;\n\n if (branch === '*' && project.default_branch === undefined) {\n continue;\n }\n\n if (this.skipReposWithoutExactFileMatch) {\n const project_branch = branch === '*' ? project.default_branch : branch;\n\n const projectHasFile: boolean = await client.hasFile(\n project.path_with_namespace,\n project_branch,\n catalogPath,\n );\n\n if (!projectHasFile) {\n continue;\n }\n }\n\n if (\n this.skipForkedRepos &&\n project.hasOwnProperty('forked_from_project')\n ) {\n continue;\n }\n\n res.matches.push(project);\n }\n\n for (const project of res.matches) {\n const project_branch = branch === '*' ? project.default_branch : branch;\n\n emit(\n processingResult.location({\n type: 'url',\n // The format expected by the GitLabUrlReader:\n // https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n //\n // This unfortunately will trigger another API call in `getGitLabFileFetchUrl` to get the project ID.\n // The alternative is using the `buildRawUrl` function, which does not support subgroups, so providing a raw\n // URL here won't work either.\n target: `${project.web_url}/-/blob/${project_branch}/${catalogPath}`,\n presence: 'optional',\n }),\n );\n }\n\n // Save an ISO formatted string in the cache as that's what GitLab expects in the API request.\n await this.cache.set(this.getCacheKey(), startTime.toISOString());\n\n const duration = ((Date.now() - startTime.getTime()) / 1000).toFixed(1);\n this.logger.debug(\n `Read ${res.scanned} GitLab repositories in ${duration} seconds`,\n );\n\n return true;\n }\n\n private getCacheKey(): string {\n return `processors/${this.getProcessorName()}/last-activity`;\n }\n}\n\ntype Result = {\n scanned: number;\n matches: GitLabProject[];\n};\n\n/*\n * Helpers\n */\n\nexport function parseUrl(urlString: string): {\n group?: string;\n host: string;\n branch: string;\n catalogPath: string;\n} {\n const url = new URL(urlString);\n const path = url.pathname.slice(1).split('/');\n\n // (/group/subgroup)/blob/branch|*/filepath\n const blobIndex = path.findIndex(p => p === 'blob');\n if (blobIndex !== -1 && path.length > blobIndex + 2) {\n const group =\n blobIndex > 0 ? path.slice(0, blobIndex).join('/') : undefined;\n\n return {\n group,\n host: url.host,\n branch: decodeURIComponent(path[blobIndex + 1]),\n catalogPath: decodeURIComponent(path.slice(blobIndex + 2).join('/')),\n };\n }\n\n throw new Error(`Failed to parse ${urlString}`);\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport {\n ANNOTATION_LOCATION,\n ANNOTATION_ORIGIN_LOCATION,\n Entity,\n GroupEntity,\n UserEntity,\n} from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { GitLabIntegration, ScmIntegrations } from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-node';\nimport { merge } from 'lodash';\nimport * as uuid from 'uuid';\nimport { Logger } from 'winston';\n\nimport {\n GitLabClient,\n GitlabProviderConfig,\n paginated,\n readGitlabConfigs,\n} from '../lib';\nimport { GitLabGroup, GitLabUser, PagedResponse } from '../lib/types';\n\ntype Result = {\n scanned: number;\n matches: GitLabUser[];\n};\n\ntype GroupResult = {\n scanned: number;\n matches: GitLabGroup[];\n};\n\n/**\n * Discovers users and groups from a Gitlab instance.\n * @public\n */\nexport class GitlabOrgDiscoveryEntityProvider implements EntityProvider {\n private readonly config: GitlabProviderConfig;\n private readonly integration: GitLabIntegration;\n private readonly logger: Logger;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n\n static fromConfig(\n config: Config,\n options: {\n logger: Logger;\n schedule?: TaskRunner;\n scheduler?: PluginTaskScheduler;\n },\n ): GitlabOrgDiscoveryEntityProvider[] {\n if (!options.schedule && !options.scheduler) {\n throw new Error('Either schedule or scheduler must be provided.');\n }\n\n const providerConfigs = readGitlabConfigs(config);\n const integrations = ScmIntegrations.fromConfig(config).gitlab;\n const providers: GitlabOrgDiscoveryEntityProvider[] = [];\n\n providerConfigs.forEach(providerConfig => {\n const integration = integrations.byHost(providerConfig.host);\n\n if (!providerConfig.orgEnabled) {\n return;\n }\n\n if (!integration) {\n throw new Error(\n `No gitlab integration found that matches host ${providerConfig.host}`,\n );\n }\n\n if (!providerConfig.group && providerConfig.host === 'gitlab.com') {\n throw new Error(\n `Missing 'group' value for GitlabOrgDiscoveryEntityProvider:${providerConfig.id}.`,\n );\n }\n\n if (!options.schedule && !providerConfig.schedule) {\n throw new Error(\n `No schedule provided neither via code nor config for GitlabOrgDiscoveryEntityProvider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n providers.push(\n new GitlabOrgDiscoveryEntityProvider({\n ...options,\n config: providerConfig,\n integration,\n taskRunner,\n }),\n );\n });\n return providers;\n }\n\n private constructor(options: {\n config: GitlabProviderConfig;\n integration: GitLabIntegration;\n logger: Logger;\n taskRunner: TaskRunner;\n }) {\n this.config = options.config;\n this.integration = options.integration;\n this.logger = options.logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(options.taskRunner);\n }\n\n getProviderName(): string {\n return `GitlabOrgDiscoveryEntityProvider:${this.config.id}`;\n }\n\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n private createScheduleFn(taskRunner: TaskRunner): () => Promise<void> {\n return async () => {\n const taskId = `${this.getProviderName()}:refresh`;\n return taskRunner.run({\n id: taskId,\n fn: async () => {\n const logger = this.logger.child({\n class: GitlabOrgDiscoveryEntityProvider.prototype.constructor.name,\n taskId,\n taskInstanceId: uuid.v4(),\n });\n\n try {\n await this.refresh(logger);\n } catch (error) {\n logger.error(\n `${this.getProviderName()} refresh failed, ${error}`,\n error,\n );\n }\n },\n });\n };\n }\n\n private async refresh(logger: Logger): Promise<void> {\n if (!this.connection) {\n throw new Error(\n `Gitlab discovery connection not initialized for ${this.getProviderName()}`,\n );\n }\n\n const client = new GitLabClient({\n config: this.integration.config,\n logger: logger,\n });\n\n let groups;\n let users;\n\n if (client.isSelfManaged()) {\n groups = paginated<GitLabGroup>(options => client.listGroups(options), {\n page: 1,\n per_page: 100,\n });\n\n users = paginated<GitLabUser>(options => client.listUsers(options), {\n page: 1,\n per_page: 100,\n active: true,\n });\n } else {\n groups = (await client.listDescendantGroups(this.config.group)).items;\n const rootGroup = this.config.group.split('/')[0];\n users = paginated<GitLabUser>(\n options => client.listSaaSUsers(rootGroup, options),\n {\n page: 1,\n per_page: 100,\n },\n );\n }\n\n const idMappedUser: { [userId: number]: GitLabUser } = {};\n\n const res: Result = {\n scanned: 0,\n matches: [],\n };\n\n const groupRes: GroupResult = {\n scanned: 0,\n matches: [],\n };\n\n for await (const user of users) {\n if (!this.config.userPattern.test(user.email ?? user.username ?? '')) {\n continue;\n }\n\n res.scanned++;\n\n if (user.state !== 'active') {\n continue;\n }\n\n idMappedUser[user.id] = user;\n res.matches.push(user);\n }\n\n for await (const group of groups) {\n if (!this.config.groupPattern.test(group.full_path ?? '')) {\n continue;\n }\n\n if (\n this.config.group &&\n !group.full_path.startsWith(`${this.config.group}/`)\n ) {\n continue;\n }\n\n groupRes.scanned++;\n groupRes.matches.push(group);\n\n let groupUsers: PagedResponse<GitLabUser> = { items: [] };\n try {\n groupUsers = await client.getGroupMembers(group.full_path, ['DIRECT']);\n } catch (e) {\n logger.error(\n `Failed fetching users for group '${group.full_path}': ${e}`,\n );\n }\n\n for (const groupUser of groupUsers.items) {\n const user = idMappedUser[groupUser.id];\n if (user) {\n user.groups = (user.groups ?? []).concat(group);\n }\n }\n }\n\n const groupsWithUsers = groupRes.matches.filter(group => {\n return (\n res.matches.filter(x => {\n return !!x.groups?.find(y => y.id === group.id);\n }).length > 0\n );\n });\n\n const userEntities = res.matches.map(p =>\n this.createUserEntity(p, this.integration.config.host),\n );\n const groupEntities = this.createGroupEntities(\n groupsWithUsers,\n this.integration.config.host,\n );\n\n await this.connection.applyMutation({\n type: 'full',\n entities: [...userEntities, ...groupEntities].map(entity => ({\n locationKey: this.getProviderName(),\n entity: this.withLocations(\n this.integration.config.host,\n this.integration.config.baseUrl,\n entity,\n ),\n })),\n });\n }\n\n private createGroupEntities(\n groupResult: GitLabGroup[],\n host: string,\n ): GroupEntity[] {\n const idMapped: { [groupId: number]: GitLabGroup } = {};\n const entities: GroupEntity[] = [];\n\n for (const group of groupResult) {\n idMapped[group.id] = group;\n }\n\n for (const group of groupResult) {\n const entity = this.createGroupEntity(group, host);\n\n if (group.parent_id && idMapped.hasOwnProperty(group.parent_id)) {\n entity.spec.parent = this.groupName(\n idMapped[group.parent_id].full_path,\n );\n }\n\n entities.push(entity);\n }\n\n return entities;\n }\n\n private withLocations(host: string, baseUrl: string, entity: Entity): Entity {\n const location =\n entity.kind === 'Group'\n ? `url:${baseUrl}/${entity.metadata.annotations?.[`${host}/team-path`]}`\n : `url:${baseUrl}/${entity.metadata.name}`;\n return merge(\n {\n metadata: {\n annotations: {\n [ANNOTATION_LOCATION]: location,\n [ANNOTATION_ORIGIN_LOCATION]: location,\n },\n },\n },\n entity,\n ) as Entity;\n }\n\n private createUserEntity(user: GitLabUser, host: string): UserEntity {\n const annotations: { [annotationName: string]: string } = {};\n\n annotations[`${host}/user-login`] = user.web_url;\n if (user?.group_saml_identity?.extern_uid) {\n annotations[`${host}/saml-external-uid`] =\n user.group_saml_identity.extern_uid;\n }\n\n const entity: UserEntity = {\n apiVersion: 'backstage.io/v1alpha1',\n kind: 'User',\n metadata: {\n name: user.username,\n annotations: annotations,\n },\n spec: {\n profile: {\n displayName: user.name || undefined,\n picture: user.avatar_url || undefined,\n },\n memberOf: [],\n },\n };\n\n if (user.email) {\n if (!entity.spec) {\n entity.spec = {};\n }\n\n if (!entity.spec.profile) {\n entity.spec.profile = {};\n }\n\n entity.spec.profile.email = user.email;\n }\n\n if (user.groups) {\n for (const group of user.groups) {\n if (!entity.spec.memberOf) {\n entity.spec.memberOf = [];\n }\n entity.spec.memberOf.push(this.groupName(group.full_path));\n }\n }\n\n return entity;\n }\n\n private groupName(full_path: string): string {\n if (this.config.group && full_path.startsWith(`${this.config.group}/`)) {\n return full_path\n .replace(`${this.config.group}/`, '')\n .replaceAll('/', '-');\n }\n return full_path.replaceAll('/', '-');\n }\n\n private createGroupEntity(group: GitLabGroup, host: string): GroupEntity {\n const annotations: { [annotationName: string]: string } = {};\n\n annotations[`${host}/team-path`] = group.full_path;\n\n const entity: GroupEntity = {\n apiVersion: 'backstage.io/v1alpha1',\n kind: 'Group',\n metadata: {\n name: this.groupName(group.full_path),\n annotations: annotations,\n },\n spec: {\n type: 'team',\n children: [],\n profile: {\n displayName: group.name,\n },\n },\n };\n\n if (group.description) {\n entity.metadata.description = group.description;\n }\n\n return entity;\n }\n}\n"],"names":["__publicField","ScmIntegrations","CacheManager","GitLabClient","paginated","processingResult","readGitlabConfigs","uuid","_a","merge","ANNOTATION_LOCATION","ANNOTATION_ORIGIN_LOCATION"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCO,MAAM,wBAAqD,CAAA;AAAA,EA0BxD,YAAY,OAMjB,EAAA;AA/BH,IAAiBA,eAAA,CAAA,IAAA,EAAA,cAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,OAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,gCAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,CAAA;AA4Bf,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,YAAA,CAAA;AAC5B,IAAK,IAAA,CAAA,KAAA,GAAQ,OAAQ,CAAA,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AY,UAAA,CAAA,CAAA,GAAI,KAAM,CAAA,SAAA,CAAA;AAEzC,IAAA,MAAM,MAAsB,GAAA;AAAA,MAC1B,UAAY,EAAA,uBAAA;AAAA,MACZ,IAAM,EAAA,OAAA;AAAA,MACN,QAAU,EAAA;AAAA,QACR,IAAM,EAAA,IAAA,CAAK,SAAU,CAAA,KAAA,CAAM,SAAS,CAAA;AAAA,QACpC,WAAA;AAAA,OACF;AAAA,MACA,IAAM,EAAA;AAAA,QACJ,IAAM,EAAA,MAAA;AAAA,QACN,UAAU,EAAC;AAAA,QACX,OAAS,EAAA;AAAA,UACP,aAAa,KAAM,CAAA,IAAA;AAAA,SACrB;AAAA,OACF;AAAA,KACF,CAAA;AAEA,IAAA,IAAI,MAAM,WAAa,EAAA;AACrB,MAAO,MAAA,CAAA,QAAA,CAAS,cAAc,KAAM,CAAA,WAAA,CAAA;AAAA,KACtC;AAEA,IAAO,OAAA,MAAA,CAAA;AAAA,GACT;AACF;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/GitLabDiscoveryProcessor.ts","../src/lib/defaultTransformers.ts","../src/providers/GitlabOrgDiscoveryEntityProvider.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n CacheClient,\n CacheManager,\n PluginCacheManager,\n} from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport {\n ScmIntegrationRegistry,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n CatalogProcessor,\n CatalogProcessorEmit,\n LocationSpec,\n processingResult,\n} from '@backstage/plugin-catalog-node';\nimport { Logger } from 'winston';\nimport { GitLabClient, GitLabProject, paginated } from './lib';\n\n/**\n * Extracts repositories out of an GitLab instance.\n * @public\n */\nexport class GitLabDiscoveryProcessor implements CatalogProcessor {\n private readonly integrations: ScmIntegrationRegistry;\n private readonly logger: Logger;\n private readonly cache: CacheClient;\n private readonly skipReposWithoutExactFileMatch: boolean;\n private readonly skipForkedRepos: boolean;\n\n static fromConfig(\n config: Config,\n options: {\n logger: Logger;\n skipReposWithoutExactFileMatch?: boolean;\n skipForkedRepos?: boolean;\n },\n ): GitLabDiscoveryProcessor {\n const integrations = ScmIntegrations.fromConfig(config);\n const pluginCache =\n CacheManager.fromConfig(config).forPlugin('gitlab-discovery');\n\n return new GitLabDiscoveryProcessor({\n ...options,\n integrations,\n pluginCache,\n });\n }\n\n private constructor(options: {\n integrations: ScmIntegrationRegistry;\n pluginCache: PluginCacheManager;\n logger: Logger;\n skipReposWithoutExactFileMatch?: boolean;\n skipForkedRepos?: boolean;\n }) {\n this.integrations = options.integrations;\n this.cache = options.pluginCache.getClient();\n this.logger = options.logger;\n this.skipReposWithoutExactFileMatch =\n options.skipReposWithoutExactFileMatch || false;\n this.skipForkedRepos = options.skipForkedRepos || false;\n }\n\n getProcessorName(): string {\n return 'GitLabDiscoveryProcessor';\n }\n\n async readLocation(\n location: LocationSpec,\n _optional: boolean,\n emit: CatalogProcessorEmit,\n ): Promise<boolean> {\n if (location.type !== 'gitlab-discovery') {\n return false;\n }\n\n const startTime = new Date();\n const { group, host, branch, catalogPath } = parseUrl(location.target);\n\n const integration = this.integrations.gitlab.byUrl(`https://${host}`);\n if (!integration) {\n throw new Error(\n `There is no GitLab integration that matches ${host}. Please add a configuration entry for it under integrations.gitlab`,\n );\n }\n\n const client = new GitLabClient({\n config: integration.config,\n logger: this.logger,\n });\n this.logger.debug(`Reading GitLab projects from ${location.target}`);\n\n const lastActivity = (await this.cache.get(this.getCacheKey())) as string;\n const opts = {\n archived: false,\n group,\n page: 1,\n // We check for the existence of lastActivity and only set it if it's present to ensure\n // that the options doesn't include the key so that the API doesn't receive an empty query parameter.\n ...(lastActivity && { last_activity_after: lastActivity }),\n };\n\n const projects = paginated(options => client.listProjects(options), opts);\n\n const res: Result = {\n scanned: 0,\n matches: [],\n };\n for await (const project of projects) {\n res.scanned++;\n\n if (branch === '*' && project.default_branch === undefined) {\n continue;\n }\n\n if (this.skipReposWithoutExactFileMatch) {\n const project_branch = branch === '*' ? project.default_branch : branch;\n\n const projectHasFile: boolean = await client.hasFile(\n project.path_with_namespace,\n project_branch,\n catalogPath,\n );\n\n if (!projectHasFile) {\n continue;\n }\n }\n\n if (\n this.skipForkedRepos &&\n project.hasOwnProperty('forked_from_project')\n ) {\n continue;\n }\n\n res.matches.push(project);\n }\n\n for (const project of res.matches) {\n const project_branch = branch === '*' ? project.default_branch : branch;\n\n emit(\n processingResult.location({\n type: 'url',\n // The format expected by the GitLabUrlReader:\n // https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath\n //\n // This unfortunately will trigger another API call in `getGitLabFileFetchUrl` to get the project ID.\n // The alternative is using the `buildRawUrl` function, which does not support subgroups, so providing a raw\n // URL here won't work either.\n target: `${project.web_url}/-/blob/${project_branch}/${catalogPath}`,\n presence: 'optional',\n }),\n );\n }\n\n // Save an ISO formatted string in the cache as that's what GitLab expects in the API request.\n await this.cache.set(this.getCacheKey(), startTime.toISOString());\n\n const duration = ((Date.now() - startTime.getTime()) / 1000).toFixed(1);\n this.logger.debug(\n `Read ${res.scanned} GitLab repositories in ${duration} seconds`,\n );\n\n return true;\n }\n\n private getCacheKey(): string {\n return `processors/${this.getProcessorName()}/last-activity`;\n }\n}\n\ntype Result = {\n scanned: number;\n matches: GitLabProject[];\n};\n\n/*\n * Helpers\n */\n\nexport function parseUrl(urlString: string): {\n group?: string;\n host: string;\n branch: string;\n catalogPath: string;\n} {\n const url = new URL(urlString);\n const path = url.pathname.slice(1).split('/');\n\n // (/group/subgroup)/blob/branch|*/filepath\n const blobIndex = path.findIndex(p => p === 'blob');\n if (blobIndex !== -1 && path.length > blobIndex + 2) {\n const group =\n blobIndex > 0 ? path.slice(0, blobIndex).join('/') : undefined;\n\n return {\n group,\n host: url.host,\n branch: decodeURIComponent(path[blobIndex + 1]),\n catalogPath: decodeURIComponent(path.slice(blobIndex + 2).join('/')),\n };\n }\n\n throw new Error(`Failed to parse ${urlString}`);\n}\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { GroupEntity, UserEntity } from '@backstage/catalog-model';\nimport {\n GitLabGroup,\n GroupNameTransformerOptions,\n GroupTransformerOptions,\n UserTransformerOptions,\n} from './types';\n\nexport function defaultGroupNameTransformer(\n options: GroupNameTransformerOptions,\n): string {\n if (\n options.providerConfig.group &&\n options.group.full_path.startsWith(`${options.providerConfig.group}/`)\n ) {\n return options.group.full_path\n .replace(`${options.providerConfig.group}/`, '')\n .replaceAll('/', '-');\n }\n return options.group.full_path.replaceAll('/', '-');\n}\n\nexport function defaultGroupEntitiesTransformer(\n options: GroupTransformerOptions,\n): GroupEntity[] {\n const idMapped: { [groupId: number]: GitLabGroup } = {};\n const entities: GroupEntity[] = [];\n\n for (const group of options.groups) {\n idMapped[group.id] = group;\n }\n\n for (const group of options.groups) {\n const annotations: { [annotationName: string]: string } = {};\n\n annotations[`${options.providerConfig.host}/team-path`] = group.full_path;\n\n const entity: GroupEntity = {\n apiVersion: 'backstage.io/v1alpha1',\n kind: 'Group',\n metadata: {\n name: options.groupNameTransformer({\n group,\n providerConfig: options.providerConfig,\n }),\n annotations: annotations,\n },\n spec: {\n type: 'team',\n children: [],\n profile: {\n displayName: group.name,\n },\n },\n };\n\n if (group.description) {\n entity.metadata.description = group.description;\n }\n\n if (group.parent_id && idMapped.hasOwnProperty(group.parent_id)) {\n entity.spec.parent = options.groupNameTransformer({\n group: idMapped[group.parent_id],\n providerConfig: options.providerConfig,\n });\n }\n\n entities.push(entity);\n }\n\n return entities;\n}\n\n/**\n * The default implementation of the transformation from a graph user entry to\n * a User entity.\n *\n * @public\n */\nexport function defaultUserTransformer(\n options: UserTransformerOptions,\n): UserEntity {\n const annotations: { [annotationName: string]: string } = {};\n\n annotations[`${options.integrationConfig.host}/user-login`] =\n options.user.web_url;\n if (options.user?.group_saml_identity?.extern_uid) {\n annotations[`${options.integrationConfig.host}/saml-external-uid`] =\n options.user.group_saml_identity.extern_uid;\n }\n\n const entity: UserEntity = {\n apiVersion: 'backstage.io/v1alpha1',\n kind: 'User',\n metadata: {\n name: options.user.username,\n annotations: annotations,\n },\n spec: {\n profile: {\n displayName: options.user.name || undefined,\n picture: options.user.avatar_url || undefined,\n },\n memberOf: [],\n },\n };\n\n if (options.user.email) {\n if (!entity.spec) {\n entity.spec = {};\n }\n\n if (!entity.spec.profile) {\n entity.spec.profile = {};\n }\n\n entity.spec.profile.email = options.user.email;\n }\n\n if (options.user.groups) {\n for (const group of options.user.groups) {\n if (!entity.spec.memberOf) {\n entity.spec.memberOf = [];\n }\n entity.spec.memberOf.push(\n options.groupNameTransformer({\n group,\n providerConfig: options.providerConfig,\n }),\n );\n }\n }\n\n return entity;\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport {\n ANNOTATION_LOCATION,\n ANNOTATION_ORIGIN_LOCATION,\n Entity,\n} from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { GitLabIntegration, ScmIntegrations } from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-node';\nimport { merge } from 'lodash';\nimport * as uuid from 'uuid';\nimport { Logger } from 'winston';\n\nimport {\n GitLabClient,\n GitlabProviderConfig,\n paginated,\n readGitlabConfigs,\n} from '../lib';\nimport {\n GitLabGroup,\n GitLabUser,\n PagedResponse,\n UserTransformer,\n GroupTransformer as GroupEntitiesTransformer,\n GroupNameTransformer,\n} from '../lib/types';\nimport {\n defaultGroupNameTransformer,\n defaultGroupEntitiesTransformer,\n defaultUserTransformer,\n} from '../lib/defaultTransformers';\n\ntype Result = {\n scanned: number;\n matches: GitLabUser[];\n};\n\ntype GroupResult = {\n scanned: number;\n matches: GitLabGroup[];\n};\n\n/**\n * Discovers users and groups from a Gitlab instance.\n * @public\n */\nexport class GitlabOrgDiscoveryEntityProvider implements EntityProvider {\n private readonly config: GitlabProviderConfig;\n private readonly integration: GitLabIntegration;\n private readonly logger: Logger;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n private userTransformer: UserTransformer;\n private groupEntitiesTransformer: GroupEntitiesTransformer;\n private groupNameTransformer: GroupNameTransformer;\n\n static fromConfig(\n config: Config,\n options: {\n logger: Logger;\n schedule?: TaskRunner;\n scheduler?: PluginTaskScheduler;\n userTransformer?: UserTransformer;\n groupEntitiesTransformer?: GroupEntitiesTransformer;\n groupNameTransformer?: GroupNameTransformer;\n },\n ): GitlabOrgDiscoveryEntityProvider[] {\n if (!options.schedule && !options.scheduler) {\n throw new Error('Either schedule or scheduler must be provided.');\n }\n\n const providerConfigs = readGitlabConfigs(config);\n const integrations = ScmIntegrations.fromConfig(config).gitlab;\n const providers: GitlabOrgDiscoveryEntityProvider[] = [];\n\n providerConfigs.forEach(providerConfig => {\n const integration = integrations.byHost(providerConfig.host);\n\n if (!providerConfig.orgEnabled) {\n return;\n }\n\n if (!integration) {\n throw new Error(\n `No gitlab integration found that matches host ${providerConfig.host}`,\n );\n }\n\n if (!providerConfig.group && providerConfig.host === 'gitlab.com') {\n throw new Error(\n `Missing 'group' value for GitlabOrgDiscoveryEntityProvider:${providerConfig.id}.`,\n );\n }\n\n if (!options.schedule && !providerConfig.schedule) {\n throw new Error(\n `No schedule provided neither via code nor config for GitlabOrgDiscoveryEntityProvider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n providers.push(\n new GitlabOrgDiscoveryEntityProvider({\n ...options,\n config: providerConfig,\n integration,\n taskRunner,\n }),\n );\n });\n return providers;\n }\n\n private constructor(options: {\n config: GitlabProviderConfig;\n integration: GitLabIntegration;\n logger: Logger;\n taskRunner: TaskRunner;\n userTransformer?: UserTransformer;\n groupEntitiesTransformer?: GroupEntitiesTransformer;\n groupNameTransformer?: GroupNameTransformer;\n }) {\n this.config = options.config;\n this.integration = options.integration;\n this.logger = options.logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(options.taskRunner);\n this.userTransformer = options.userTransformer ?? defaultUserTransformer;\n this.groupEntitiesTransformer =\n options.groupEntitiesTransformer ?? defaultGroupEntitiesTransformer;\n this.groupNameTransformer =\n options.groupNameTransformer ?? defaultGroupNameTransformer;\n }\n\n getProviderName(): string {\n return `GitlabOrgDiscoveryEntityProvider:${this.config.id}`;\n }\n\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n private createScheduleFn(taskRunner: TaskRunner): () => Promise<void> {\n return async () => {\n const taskId = `${this.getProviderName()}:refresh`;\n return taskRunner.run({\n id: taskId,\n fn: async () => {\n const logger = this.logger.child({\n class: GitlabOrgDiscoveryEntityProvider.prototype.constructor.name,\n taskId,\n taskInstanceId: uuid.v4(),\n });\n\n try {\n await this.refresh(logger);\n } catch (error) {\n logger.error(\n `${this.getProviderName()} refresh failed, ${error}`,\n error,\n );\n }\n },\n });\n };\n }\n\n private async refresh(logger: Logger): Promise<void> {\n if (!this.connection) {\n throw new Error(\n `Gitlab discovery connection not initialized for ${this.getProviderName()}`,\n );\n }\n\n const client = new GitLabClient({\n config: this.integration.config,\n logger: logger,\n });\n\n let groups;\n let users;\n\n if (client.isSelfManaged()) {\n groups = paginated<GitLabGroup>(options => client.listGroups(options), {\n page: 1,\n per_page: 100,\n });\n\n users = paginated<GitLabUser>(options => client.listUsers(options), {\n page: 1,\n per_page: 100,\n active: true,\n });\n } else {\n groups = (await client.listDescendantGroups(this.config.group)).items;\n const rootGroup = this.config.group.split('/')[0];\n users = paginated<GitLabUser>(\n options => client.listSaaSUsers(rootGroup, options),\n {\n page: 1,\n per_page: 100,\n },\n );\n }\n\n const idMappedUser: { [userId: number]: GitLabUser } = {};\n\n const res: Result = {\n scanned: 0,\n matches: [],\n };\n\n const groupRes: GroupResult = {\n scanned: 0,\n matches: [],\n };\n\n for await (const user of users) {\n if (!this.config.userPattern.test(user.email ?? user.username ?? '')) {\n continue;\n }\n\n res.scanned++;\n\n if (user.state !== 'active') {\n continue;\n }\n\n idMappedUser[user.id] = user;\n res.matches.push(user);\n }\n\n for await (const group of groups) {\n if (!this.config.groupPattern.test(group.full_path ?? '')) {\n continue;\n }\n\n if (\n this.config.group &&\n !group.full_path.startsWith(`${this.config.group}/`)\n ) {\n continue;\n }\n\n groupRes.scanned++;\n groupRes.matches.push(group);\n\n let groupUsers: PagedResponse<GitLabUser> = { items: [] };\n try {\n groupUsers = await client.getGroupMembers(group.full_path, ['DIRECT']);\n } catch (e) {\n logger.error(\n `Failed fetching users for group '${group.full_path}': ${e}`,\n );\n }\n\n for (const groupUser of groupUsers.items) {\n const user = idMappedUser[groupUser.id];\n if (user) {\n user.groups = (user.groups ?? []).concat(group);\n }\n }\n }\n\n const groupsWithUsers = groupRes.matches.filter(group => {\n return (\n res.matches.filter(x => {\n return !!x.groups?.find(y => y.id === group.id);\n }).length > 0\n );\n });\n\n const userEntities = res.matches.map(p =>\n this.userTransformer({\n user: p,\n integrationConfig: this.integration.config,\n providerConfig: this.config,\n groupNameTransformer: this.groupNameTransformer,\n }),\n );\n\n const groupEntities = this.groupEntitiesTransformer({\n groups: groupsWithUsers,\n providerConfig: this.config,\n groupNameTransformer: this.groupNameTransformer,\n });\n\n await this.connection.applyMutation({\n type: 'full',\n entities: [...userEntities, ...groupEntities].map(entity => ({\n locationKey: this.getProviderName(),\n entity: this.withLocations(\n this.integration.config.host,\n this.integration.config.baseUrl,\n entity,\n ),\n })),\n });\n }\n\n private withLocations(host: string, baseUrl: string, entity: Entity): Entity {\n const location =\n entity.kind === 'Group'\n ? `url:${baseUrl}/${entity.metadata.annotations?.[`${host}/team-path`]}`\n : `url:${baseUrl}/${entity.metadata.name}`;\n return merge(\n {\n metadata: {\n annotations: {\n [ANNOTATION_LOCATION]: location,\n [ANNOTATION_ORIGIN_LOCATION]: location,\n },\n },\n },\n entity,\n ) as Entity;\n }\n}\n"],"names":["__publicField","ScmIntegrations","CacheManager","GitLabClient","paginated","processingResult","readGitlabConfigs","uuid","_a","merge","ANNOTATION_LOCATION","ANNOTATION_ORIGIN_LOCATION"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCO,MAAM,wBAAqD,CAAA;AAAA,EA0BxD,YAAY,OAMjB,EAAA;AA/BH,IAAiBA,eAAA,CAAA,IAAA,EAAA,cAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,OAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,gCAAA,CAAA,CAAA;AACjB,IAAiBA,eAAA,CAAA,IAAA,EAAA,iBAAA,C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M,MAAA,QAAA,GACJ,OAAO,IAAS,KAAA,OAAA,GACZ,OAAO,OAAO,CAAA,CAAA,EAAA,CAAI,YAAO,QAAS,CAAA,WAAA,KAAhB,mBAA8B,CAAG,EAAA,IAAI,aAAa,CACpE,CAAA,GAAA,CAAA,IAAA,EAAO,OAAO,CAAI,CAAA,EAAA,MAAA,CAAO,SAAS,IAAI,CAAA,CAAA,CAAA;AAC5C,IAAO,OAAAC,YAAA;AAAA,MACL;AAAA,QACE,QAAU,EAAA;AAAA,UACR,WAAa,EAAA;AAAA,YACX,CAACC,gCAAmB,GAAG,QAAA;AAAA,YACvB,CAACC,uCAA0B,GAAG,QAAA;AAAA,WAChC;AAAA,SACF;AAAA,OACF;AAAA,MACA,MAAA;AAAA,KACF,CAAA;AAAA,GACF;AACF;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { Config } from '@backstage/config';
2
2
  import { CatalogProcessor, LocationSpec, CatalogProcessorEmit, EntityProvider, EntityProviderConnection } from '@backstage/plugin-catalog-node';
3
3
  import { Logger } from 'winston';
4
- import { TaskRunner, PluginTaskScheduler } from '@backstage/backend-tasks';
4
+ import { TaskRunner, PluginTaskScheduler, TaskScheduleDefinition } from '@backstage/backend-tasks';
5
+ import { UserEntity, GroupEntity } from '@backstage/catalog-model';
6
+ import { GitLabIntegrationConfig } from '@backstage/integration';
5
7
 
6
8
  /**
7
9
  * Extracts repositories out of an GitLab instance.
@@ -47,6 +49,145 @@ declare class GitlabDiscoveryEntityProvider implements EntityProvider {
47
49
  private createLocationSpec;
48
50
  }
49
51
 
52
+ /**
53
+ * Representation of a GitLab user in the GitLab API
54
+ *
55
+ * @public
56
+ */
57
+ type GitLabUser = {
58
+ id: number;
59
+ username: string;
60
+ email?: string;
61
+ name: string;
62
+ state: string;
63
+ web_url: string;
64
+ avatar_url: string;
65
+ groups?: GitLabGroup[];
66
+ group_saml_identity?: GitLabGroupSamlIdentity;
67
+ };
68
+ /**
69
+ * @public
70
+ */
71
+ type GitLabGroupSamlIdentity = {
72
+ extern_uid: string;
73
+ };
74
+ /**
75
+ * Representation of a GitLab group in the GitLab API
76
+ *
77
+ * @public
78
+ */
79
+ type GitLabGroup = {
80
+ id: number;
81
+ name: string;
82
+ full_path: string;
83
+ description?: string;
84
+ parent_id?: number;
85
+ };
86
+ /**
87
+ * The configuration parameters for the GitlabProvider
88
+ *
89
+ * @public
90
+ */
91
+ type GitlabProviderConfig = {
92
+ /**
93
+ * Identifies one of the hosts set up in the integrations
94
+ */
95
+ host: string;
96
+ /**
97
+ * Required for gitlab.com when `orgEnabled: true`.
98
+ * Optional for self managed. Must not end with slash.
99
+ * Accepts only groups under the provided path (which will be stripped)
100
+ */
101
+ group: string;
102
+ /**
103
+ * ???
104
+ */
105
+ id: string;
106
+ /**
107
+ * The name of the branch to be used, to discover catalog files.
108
+ */
109
+ branch?: string;
110
+ /**
111
+ * If no `branch` is configured and there is no default branch defined at the project as well, this fallback is used
112
+ * to discover catalog files.
113
+ * Defaults to: `master`
114
+ */
115
+ fallbackBranch: string;
116
+ /**
117
+ * Defaults to `catalog-info.yaml`
118
+ */
119
+ catalogFile: string;
120
+ /**
121
+ * Filters found projects based on provided patter.
122
+ * Defaults to `[\s\S]*`, which means to not filter anything
123
+ */
124
+ projectPattern: RegExp;
125
+ /**
126
+ * Filters found users based on provided patter.
127
+ * Defaults to `[\s\S]*`, which means to not filter anything
128
+ */
129
+ userPattern: RegExp;
130
+ /**
131
+ * Filters found groups based on provided patter.
132
+ * Defaults to `[\s\S]*`, which means to not filter anything
133
+ */
134
+ groupPattern: RegExp;
135
+ orgEnabled?: boolean;
136
+ schedule?: TaskScheduleDefinition;
137
+ /**
138
+ * If the project is a fork, skip repository
139
+ */
140
+ skipForkedRepos?: boolean;
141
+ };
142
+ /**
143
+ * Customize how group names are generated
144
+ *
145
+ * @public
146
+ */
147
+ type GroupNameTransformer = (options: GroupNameTransformerOptions) => string;
148
+ /**
149
+ * The GroupTransformerOptions
150
+ *
151
+ * @public
152
+ */
153
+ interface GroupNameTransformerOptions {
154
+ group: GitLabGroup;
155
+ providerConfig: GitlabProviderConfig;
156
+ }
157
+ /**
158
+ * Customize the ingested User entity
159
+ *
160
+ * @public
161
+ */
162
+ type UserTransformer = (options: UserTransformerOptions) => UserEntity;
163
+ /**
164
+ * The UserTransformerOptions
165
+ *
166
+ * @public
167
+ */
168
+ interface UserTransformerOptions {
169
+ user: GitLabUser;
170
+ integrationConfig: GitLabIntegrationConfig;
171
+ providerConfig: GitlabProviderConfig;
172
+ groupNameTransformer: GroupNameTransformer;
173
+ }
174
+ /**
175
+ * Customize the ingested Group entity
176
+ *
177
+ * @public
178
+ */
179
+ type GroupTransformer = (options: GroupTransformerOptions) => GroupEntity[];
180
+ /**
181
+ * The GroupTransformer options
182
+ *
183
+ * @public
184
+ */
185
+ interface GroupTransformerOptions {
186
+ groups: GitLabGroup[];
187
+ providerConfig: GitlabProviderConfig;
188
+ groupNameTransformer: GroupNameTransformer;
189
+ }
190
+
50
191
  /**
51
192
  * Discovers users and groups from a Gitlab instance.
52
193
  * @public
@@ -57,21 +198,23 @@ declare class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
57
198
  private readonly logger;
58
199
  private readonly scheduleFn;
59
200
  private connection?;
201
+ private userTransformer;
202
+ private groupEntitiesTransformer;
203
+ private groupNameTransformer;
60
204
  static fromConfig(config: Config, options: {
61
205
  logger: Logger;
62
206
  schedule?: TaskRunner;
63
207
  scheduler?: PluginTaskScheduler;
208
+ userTransformer?: UserTransformer;
209
+ groupEntitiesTransformer?: GroupTransformer;
210
+ groupNameTransformer?: GroupNameTransformer;
64
211
  }): GitlabOrgDiscoveryEntityProvider[];
65
212
  private constructor();
66
213
  getProviderName(): string;
67
214
  connect(connection: EntityProviderConnection): Promise<void>;
68
215
  private createScheduleFn;
69
216
  private refresh;
70
- private createGroupEntities;
71
217
  private withLocations;
72
- private createUserEntity;
73
- private groupName;
74
- private createGroupEntity;
75
218
  }
76
219
 
77
- export { GitLabDiscoveryProcessor, GitlabDiscoveryEntityProvider, GitlabOrgDiscoveryEntityProvider };
220
+ export { GitLabDiscoveryProcessor, GitLabGroup, GitLabGroupSamlIdentity, GitLabUser, GitlabDiscoveryEntityProvider, GitlabOrgDiscoveryEntityProvider, GitlabProviderConfig, GroupNameTransformer, GroupNameTransformerOptions, GroupTransformer, GroupTransformerOptions, UserTransformer, UserTransformerOptions };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend-module-gitlab",
3
3
  "description": "A Backstage catalog backend module that helps integrate towards GitLab",
4
- "version": "0.3.6",
4
+ "version": "0.3.7-next.0",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -43,21 +43,21 @@
43
43
  "clean": "backstage-cli package clean"
44
44
  },
45
45
  "dependencies": {
46
- "@backstage/backend-common": "^0.20.1",
47
- "@backstage/backend-plugin-api": "^0.6.9",
48
- "@backstage/backend-tasks": "^0.5.14",
46
+ "@backstage/backend-common": "^0.21.0-next.0",
47
+ "@backstage/backend-plugin-api": "^0.6.10-next.0",
48
+ "@backstage/backend-tasks": "^0.5.15-next.0",
49
49
  "@backstage/catalog-model": "^1.4.3",
50
50
  "@backstage/config": "^1.1.1",
51
51
  "@backstage/integration": "^1.8.0",
52
- "@backstage/plugin-catalog-node": "^1.6.1",
52
+ "@backstage/plugin-catalog-node": "^1.6.2-next.0",
53
53
  "lodash": "^4.17.21",
54
54
  "node-fetch": "^2.6.7",
55
55
  "uuid": "^8.0.0",
56
56
  "winston": "^3.2.1"
57
57
  },
58
58
  "devDependencies": {
59
- "@backstage/backend-test-utils": "^0.2.10",
60
- "@backstage/cli": "^0.25.1",
59
+ "@backstage/backend-test-utils": "^0.3.0-next.0",
60
+ "@backstage/cli": "^0.25.2-next.0",
61
61
  "@types/lodash": "^4.14.151",
62
62
  "@types/uuid": "^8.0.0",
63
63
  "luxon": "^3.0.0",