@backstage/plugin-catalog-backend-module-gitlab 0.1.13-next.2 → 0.1.14-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 +36 -0
- package/alpha/package.json +3 -3
- package/dist/alpha.cjs.js +368 -0
- package/dist/alpha.cjs.js.map +1 -0
- package/dist/alpha.d.ts +10 -0
- package/dist/index.cjs.js +0 -26
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +24 -38
- package/package.json +28 -18
- package/dist/index.alpha.d.ts +0 -93
- package/dist/index.beta.d.ts +0 -88
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-gitlab
|
|
2
2
|
|
|
3
|
+
## 0.1.14-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 928a12a9b3: Internal refactor of `/alpha` exports.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/plugin-catalog-backend@1.8.0-next.0
|
|
10
|
+
- @backstage/backend-tasks@0.4.4-next.0
|
|
11
|
+
- @backstage/backend-plugin-api@0.4.1-next.0
|
|
12
|
+
- @backstage/backend-common@0.18.3-next.0
|
|
13
|
+
- @backstage/catalog-model@1.2.1-next.0
|
|
14
|
+
- @backstage/plugin-catalog-node@1.3.4-next.0
|
|
15
|
+
- @backstage/config@1.0.6
|
|
16
|
+
- @backstage/errors@1.1.4
|
|
17
|
+
- @backstage/integration@1.4.2
|
|
18
|
+
- @backstage/types@1.0.2
|
|
19
|
+
|
|
20
|
+
## 0.1.13
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 49948f644f: The config now consistently uses the term 'instance' to refer to a single GitLab API host.
|
|
25
|
+
- 85b04f659a: Internal refactor to not use deprecated `substr`
|
|
26
|
+
- 52c5685ceb: Implement Group and User Catalog Provider
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
- @backstage/plugin-catalog-backend@1.7.2
|
|
29
|
+
- @backstage/backend-plugin-api@0.4.0
|
|
30
|
+
- @backstage/backend-common@0.18.2
|
|
31
|
+
- @backstage/catalog-model@1.2.0
|
|
32
|
+
- @backstage/plugin-catalog-node@1.3.3
|
|
33
|
+
- @backstage/backend-tasks@0.4.3
|
|
34
|
+
- @backstage/config@1.0.6
|
|
35
|
+
- @backstage/errors@1.1.4
|
|
36
|
+
- @backstage/integration@1.4.2
|
|
37
|
+
- @backstage/types@1.0.2
|
|
38
|
+
|
|
3
39
|
## 0.1.13-next.2
|
|
4
40
|
|
|
5
41
|
### Patch Changes
|
package/alpha/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-backend-module-gitlab",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"main": "../dist/
|
|
5
|
-
"types": "../dist/
|
|
3
|
+
"version": "0.1.14-next.0",
|
|
4
|
+
"main": "../dist/alpha.cjs.js",
|
|
5
|
+
"types": "../dist/alpha.d.ts"
|
|
6
6
|
}
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
var backendCommon = require('@backstage/backend-common');
|
|
7
|
+
var alpha = require('@backstage/plugin-catalog-node/alpha');
|
|
8
|
+
var integration = require('@backstage/integration');
|
|
9
|
+
var pluginCatalogBackend = require('@backstage/plugin-catalog-backend');
|
|
10
|
+
var uuid = require('uuid');
|
|
11
|
+
var fetch = require('node-fetch');
|
|
12
|
+
var backendTasks = require('@backstage/backend-tasks');
|
|
13
|
+
require('@backstage/catalog-model');
|
|
14
|
+
require('lodash');
|
|
15
|
+
|
|
16
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
|
+
|
|
18
|
+
function _interopNamespace(e) {
|
|
19
|
+
if (e && e.__esModule) return e;
|
|
20
|
+
var n = Object.create(null);
|
|
21
|
+
if (e) {
|
|
22
|
+
Object.keys(e).forEach(function (k) {
|
|
23
|
+
if (k !== 'default') {
|
|
24
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
25
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return e[k]; }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
n["default"] = e;
|
|
33
|
+
return Object.freeze(n);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
|
|
37
|
+
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
38
|
+
|
|
39
|
+
class GitLabClient {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.config = options.config;
|
|
42
|
+
this.logger = options.logger;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Indicates whether the client is for a SaaS or self managed GitLab instance.
|
|
46
|
+
*/
|
|
47
|
+
isSelfManaged() {
|
|
48
|
+
return this.config.host !== "gitlab.com";
|
|
49
|
+
}
|
|
50
|
+
async listProjects(options) {
|
|
51
|
+
if (options == null ? void 0 : options.group) {
|
|
52
|
+
return this.pagedRequest(
|
|
53
|
+
`/groups/${encodeURIComponent(options == null ? void 0 : options.group)}/projects`,
|
|
54
|
+
{
|
|
55
|
+
...options,
|
|
56
|
+
include_subgroups: true
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return this.pagedRequest(`/projects`, options);
|
|
61
|
+
}
|
|
62
|
+
async listUsers(options) {
|
|
63
|
+
let requestOptions = options;
|
|
64
|
+
if (!requestOptions) {
|
|
65
|
+
requestOptions = {};
|
|
66
|
+
}
|
|
67
|
+
requestOptions.without_project_bots = true;
|
|
68
|
+
requestOptions.exclude_internal = true;
|
|
69
|
+
return this.pagedRequest(`/users?`, requestOptions);
|
|
70
|
+
}
|
|
71
|
+
async listGroups(options) {
|
|
72
|
+
return this.pagedRequest(`/groups`, options);
|
|
73
|
+
}
|
|
74
|
+
async getUserMemberships(userId) {
|
|
75
|
+
const endpoint = `/users/${encodeURIComponent(userId)}/memberships`;
|
|
76
|
+
const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);
|
|
77
|
+
request.searchParams.append("per_page", "100");
|
|
78
|
+
const response = await fetch__default["default"](request.toString(), {
|
|
79
|
+
headers: integration.getGitLabRequestOptions(this.config).headers,
|
|
80
|
+
method: "GET"
|
|
81
|
+
});
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
if (response.status >= 500) {
|
|
84
|
+
this.logger.debug(
|
|
85
|
+
`Unexpected response when fetching ${request.toString()}. Expected 200 but got ${response.status} - ${response.statusText}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
return response.json().then((items) => {
|
|
91
|
+
return items;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* General existence check.
|
|
96
|
+
*
|
|
97
|
+
* @param projectPath - The path to the project
|
|
98
|
+
* @param branch - The branch used to search
|
|
99
|
+
* @param filePath - The path to the file
|
|
100
|
+
*/
|
|
101
|
+
async hasFile(projectPath, branch, filePath) {
|
|
102
|
+
const endpoint = `/projects/${encodeURIComponent(
|
|
103
|
+
projectPath
|
|
104
|
+
)}/repository/files/${encodeURIComponent(filePath)}`;
|
|
105
|
+
const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);
|
|
106
|
+
request.searchParams.append("ref", branch);
|
|
107
|
+
const response = await fetch__default["default"](request.toString(), {
|
|
108
|
+
headers: integration.getGitLabRequestOptions(this.config).headers,
|
|
109
|
+
method: "HEAD"
|
|
110
|
+
});
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
if (response.status >= 500) {
|
|
113
|
+
this.logger.debug(
|
|
114
|
+
`Unexpected response when fetching ${request.toString()}. Expected 200 but got ${response.status} - ${response.statusText}`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Performs a request against a given paginated GitLab endpoint.
|
|
123
|
+
*
|
|
124
|
+
* This method may be used to perform authenticated REST calls against any
|
|
125
|
+
* paginated GitLab endpoint which uses X-NEXT-PAGE headers. The return value
|
|
126
|
+
* can be be used with the {@link paginated} async-generator function to yield
|
|
127
|
+
* each item from the paged request.
|
|
128
|
+
*
|
|
129
|
+
* @see {@link paginated}
|
|
130
|
+
* @param endpoint - The request endpoint, e.g. /projects.
|
|
131
|
+
* @param options - Request queryString options which may also include page variables.
|
|
132
|
+
*/
|
|
133
|
+
async pagedRequest(endpoint, options) {
|
|
134
|
+
const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);
|
|
135
|
+
for (const key in options) {
|
|
136
|
+
if (options[key]) {
|
|
137
|
+
request.searchParams.append(key, options[key].toString());
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
this.logger.debug(`Fetching: ${request.toString()}`);
|
|
141
|
+
const response = await fetch__default["default"](
|
|
142
|
+
request.toString(),
|
|
143
|
+
integration.getGitLabRequestOptions(this.config)
|
|
144
|
+
);
|
|
145
|
+
if (!response.ok) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Unexpected response when fetching ${request.toString()}. Expected 200 but got ${response.status} - ${response.statusText}`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return response.json().then((items) => {
|
|
151
|
+
const nextPage = response.headers.get("x-next-page");
|
|
152
|
+
return {
|
|
153
|
+
items,
|
|
154
|
+
nextPage: nextPage ? Number(nextPage) : null
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function* paginated(request, options) {
|
|
160
|
+
let res;
|
|
161
|
+
do {
|
|
162
|
+
res = await request(options);
|
|
163
|
+
options.page = res.nextPage;
|
|
164
|
+
for (const item of res.items) {
|
|
165
|
+
yield item;
|
|
166
|
+
}
|
|
167
|
+
} while (res.nextPage);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function readGitlabConfig(id, config) {
|
|
171
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
172
|
+
const group = (_a = config.getOptionalString("group")) != null ? _a : "";
|
|
173
|
+
const host = config.getString("host");
|
|
174
|
+
const branch = (_b = config.getOptionalString("branch")) != null ? _b : "master";
|
|
175
|
+
const catalogFile = (_c = config.getOptionalString("entityFilename")) != null ? _c : "catalog-info.yaml";
|
|
176
|
+
const projectPattern = new RegExp(
|
|
177
|
+
(_d = config.getOptionalString("projectPattern")) != null ? _d : /[\s\S]*/
|
|
178
|
+
);
|
|
179
|
+
const userPattern = new RegExp(
|
|
180
|
+
(_e = config.getOptionalString("userPattern")) != null ? _e : /[\s\S]*/
|
|
181
|
+
);
|
|
182
|
+
const groupPattern = new RegExp(
|
|
183
|
+
(_f = config.getOptionalString("groupPattern")) != null ? _f : /[\s\S]*/
|
|
184
|
+
);
|
|
185
|
+
const orgEnabled = (_g = config.getOptionalBoolean("orgEnabled")) != null ? _g : false;
|
|
186
|
+
const schedule = config.has("schedule") ? backendTasks.readTaskScheduleDefinitionFromConfig(config.getConfig("schedule")) : void 0;
|
|
187
|
+
return {
|
|
188
|
+
id,
|
|
189
|
+
group,
|
|
190
|
+
branch,
|
|
191
|
+
host,
|
|
192
|
+
catalogFile,
|
|
193
|
+
projectPattern,
|
|
194
|
+
userPattern,
|
|
195
|
+
groupPattern,
|
|
196
|
+
schedule,
|
|
197
|
+
orgEnabled
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function readGitlabConfigs(config) {
|
|
201
|
+
const configs = [];
|
|
202
|
+
const providerConfigs = config.getOptionalConfig("catalog.providers.gitlab");
|
|
203
|
+
if (!providerConfigs) {
|
|
204
|
+
return configs;
|
|
205
|
+
}
|
|
206
|
+
for (const id of providerConfigs.keys()) {
|
|
207
|
+
configs.push(readGitlabConfig(id, providerConfigs.getConfig(id)));
|
|
208
|
+
}
|
|
209
|
+
return configs;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
class GitlabDiscoveryEntityProvider {
|
|
213
|
+
static fromConfig(config, options) {
|
|
214
|
+
if (!options.schedule && !options.scheduler) {
|
|
215
|
+
throw new Error("Either schedule or scheduler must be provided.");
|
|
216
|
+
}
|
|
217
|
+
const providerConfigs = readGitlabConfigs(config);
|
|
218
|
+
const integrations = integration.ScmIntegrations.fromConfig(config).gitlab;
|
|
219
|
+
const providers = [];
|
|
220
|
+
providerConfigs.forEach((providerConfig) => {
|
|
221
|
+
var _a;
|
|
222
|
+
const integration = integrations.byHost(providerConfig.host);
|
|
223
|
+
if (!integration) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
`No gitlab integration found that matches host ${providerConfig.host}`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
if (!options.schedule && !providerConfig.schedule) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`No schedule provided neither via code nor config for GitlabDiscoveryEntityProvider:${providerConfig.id}.`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const taskRunner = (_a = options.schedule) != null ? _a : options.scheduler.createScheduledTaskRunner(providerConfig.schedule);
|
|
234
|
+
providers.push(
|
|
235
|
+
new GitlabDiscoveryEntityProvider({
|
|
236
|
+
...options,
|
|
237
|
+
config: providerConfig,
|
|
238
|
+
integration,
|
|
239
|
+
taskRunner
|
|
240
|
+
})
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
return providers;
|
|
244
|
+
}
|
|
245
|
+
constructor(options) {
|
|
246
|
+
this.config = options.config;
|
|
247
|
+
this.integration = options.integration;
|
|
248
|
+
this.logger = options.logger.child({
|
|
249
|
+
target: this.getProviderName()
|
|
250
|
+
});
|
|
251
|
+
this.scheduleFn = this.createScheduleFn(options.taskRunner);
|
|
252
|
+
}
|
|
253
|
+
getProviderName() {
|
|
254
|
+
return `GitlabDiscoveryEntityProvider:${this.config.id}`;
|
|
255
|
+
}
|
|
256
|
+
async connect(connection) {
|
|
257
|
+
this.connection = connection;
|
|
258
|
+
await this.scheduleFn();
|
|
259
|
+
}
|
|
260
|
+
createScheduleFn(taskRunner) {
|
|
261
|
+
return async () => {
|
|
262
|
+
const taskId = `${this.getProviderName()}:refresh`;
|
|
263
|
+
return taskRunner.run({
|
|
264
|
+
id: taskId,
|
|
265
|
+
fn: async () => {
|
|
266
|
+
const logger = this.logger.child({
|
|
267
|
+
class: GitlabDiscoveryEntityProvider.prototype.constructor.name,
|
|
268
|
+
taskId,
|
|
269
|
+
taskInstanceId: uuid__namespace.v4()
|
|
270
|
+
});
|
|
271
|
+
try {
|
|
272
|
+
await this.refresh(logger);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
logger.error(`${this.getProviderName()} refresh failed`, error);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
async refresh(logger) {
|
|
281
|
+
var _a, _b, _c;
|
|
282
|
+
if (!this.connection) {
|
|
283
|
+
throw new Error(
|
|
284
|
+
`Gitlab discovery connection not initialized for ${this.getProviderName()}`
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const client = new GitLabClient({
|
|
288
|
+
config: this.integration.config,
|
|
289
|
+
logger
|
|
290
|
+
});
|
|
291
|
+
const projects = paginated(
|
|
292
|
+
(options) => client.listProjects(options),
|
|
293
|
+
{
|
|
294
|
+
group: this.config.group,
|
|
295
|
+
page: 1,
|
|
296
|
+
per_page: 50
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
const res = {
|
|
300
|
+
scanned: 0,
|
|
301
|
+
matches: []
|
|
302
|
+
};
|
|
303
|
+
for await (const project of projects) {
|
|
304
|
+
if (!this.config.projectPattern.test((_a = project.path_with_namespace) != null ? _a : "")) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
res.scanned++;
|
|
308
|
+
if (project.archived) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (this.config.branch === "*" && project.default_branch === void 0) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
const project_branch = (_b = project.default_branch) != null ? _b : this.config.branch;
|
|
315
|
+
const projectHasFile = await client.hasFile(
|
|
316
|
+
(_c = project.path_with_namespace) != null ? _c : "",
|
|
317
|
+
project_branch,
|
|
318
|
+
this.config.catalogFile
|
|
319
|
+
);
|
|
320
|
+
if (projectHasFile) {
|
|
321
|
+
res.matches.push(project);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const locations = res.matches.map((p) => this.createLocationSpec(p));
|
|
325
|
+
await this.connection.applyMutation({
|
|
326
|
+
type: "full",
|
|
327
|
+
entities: locations.map((location) => ({
|
|
328
|
+
locationKey: this.getProviderName(),
|
|
329
|
+
entity: pluginCatalogBackend.locationSpecToLocationEntity({ location })
|
|
330
|
+
}))
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
createLocationSpec(project) {
|
|
334
|
+
var _a;
|
|
335
|
+
const project_branch = (_a = project.default_branch) != null ? _a : this.config.branch;
|
|
336
|
+
return {
|
|
337
|
+
type: "url",
|
|
338
|
+
target: `${project.web_url}/-/blob/${project_branch}/${this.config.catalogFile}`,
|
|
339
|
+
presence: "optional"
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const gitlabDiscoveryEntityProviderCatalogModule = backendPluginApi.createBackendModule({
|
|
345
|
+
pluginId: "catalog",
|
|
346
|
+
moduleId: "gitlabDiscoveryEntityProvider",
|
|
347
|
+
register(env) {
|
|
348
|
+
env.registerInit({
|
|
349
|
+
deps: {
|
|
350
|
+
config: backendPluginApi.coreServices.config,
|
|
351
|
+
catalog: alpha.catalogProcessingExtensionPoint,
|
|
352
|
+
logger: backendPluginApi.coreServices.logger,
|
|
353
|
+
scheduler: backendPluginApi.coreServices.scheduler
|
|
354
|
+
},
|
|
355
|
+
async init({ config, catalog, logger, scheduler }) {
|
|
356
|
+
catalog.addEntityProvider(
|
|
357
|
+
GitlabDiscoveryEntityProvider.fromConfig(config, {
|
|
358
|
+
logger: backendCommon.loggerToWinstonLogger(logger),
|
|
359
|
+
scheduler
|
|
360
|
+
})
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
exports.gitlabDiscoveryEntityProviderCatalogModule = gitlabDiscoveryEntityProviderCatalogModule;
|
|
368
|
+
//# sourceMappingURL=alpha.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alpha.cjs.js","sources":["../src/lib/client.ts","../src/providers/config.ts","../src/providers/GitlabDiscoveryEntityProvider.ts","../src/service/GitlabDiscoveryEntityProviderCatalogModule.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 fetch from 'node-fetch';\nimport {\n getGitLabRequestOptions,\n GitLabIntegrationConfig,\n} from '@backstage/integration';\nimport { Logger } from 'winston';\nimport { GitLabGroup, GitLabMembership, GitLabUser } from './types';\n\nexport type CommonListOptions = {\n [key: string]: string | number | boolean | undefined;\n per_page?: number | undefined;\n page?: number | undefined;\n active?: boolean;\n};\n\ninterface ListProjectOptions extends CommonListOptions {\n group?: string;\n}\n\ninterface UserListOptions extends CommonListOptions {\n without_project_bots?: boolean | undefined;\n exclude_internal?: boolean | undefined;\n}\n\nexport type PagedResponse<T> = {\n items: T[];\n nextPage?: number;\n};\n\nexport class GitLabClient {\n private readonly config: GitLabIntegrationConfig;\n private readonly logger: Logger;\n\n constructor(options: { config: GitLabIntegrationConfig; logger: Logger }) {\n this.config = options.config;\n this.logger = options.logger;\n }\n\n /**\n * Indicates whether the client is for a SaaS or self managed GitLab instance.\n */\n isSelfManaged(): boolean {\n return this.config.host !== 'gitlab.com';\n }\n\n async listProjects(\n options?: ListProjectOptions,\n ): Promise<PagedResponse<any>> {\n if (options?.group) {\n return this.pagedRequest(\n `/groups/${encodeURIComponent(options?.group)}/projects`,\n {\n ...options,\n include_subgroups: true,\n },\n );\n }\n\n return this.pagedRequest(`/projects`, options);\n }\n\n async listUsers(\n options?: UserListOptions,\n ): Promise<PagedResponse<GitLabUser>> {\n let requestOptions = options;\n\n if (!requestOptions) {\n requestOptions = {};\n }\n\n requestOptions.without_project_bots = true;\n requestOptions.exclude_internal = true;\n\n return this.pagedRequest(`/users?`, requestOptions);\n }\n\n async listGroups(\n options?: CommonListOptions,\n ): Promise<PagedResponse<GitLabGroup>> {\n return this.pagedRequest(`/groups`, options);\n }\n\n async getUserMemberships(userId: number): Promise<GitLabMembership[]> {\n const endpoint: string = `/users/${encodeURIComponent(userId)}/memberships`;\n const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);\n request.searchParams.append('per_page', '100');\n\n const response = await fetch(request.toString(), {\n headers: getGitLabRequestOptions(this.config).headers,\n method: 'GET',\n });\n\n if (!response.ok) {\n if (response.status >= 500) {\n this.logger.debug(\n `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${\n response.status\n } - ${response.statusText}`,\n );\n }\n return [];\n }\n\n return response.json().then(items => {\n return items as GitLabMembership[];\n });\n }\n\n /**\n * General existence check.\n *\n * @param projectPath - The path to the project\n * @param branch - The branch used to search\n * @param filePath - The path to the file\n */\n async hasFile(\n projectPath: string,\n branch: string,\n filePath: string,\n ): Promise<boolean> {\n const endpoint: string = `/projects/${encodeURIComponent(\n projectPath,\n )}/repository/files/${encodeURIComponent(filePath)}`;\n const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);\n request.searchParams.append('ref', branch);\n\n const response = await fetch(request.toString(), {\n headers: getGitLabRequestOptions(this.config).headers,\n method: 'HEAD',\n });\n\n if (!response.ok) {\n if (response.status >= 500) {\n this.logger.debug(\n `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${\n response.status\n } - ${response.statusText}`,\n );\n }\n return false;\n }\n\n return true;\n }\n\n /**\n * Performs a request against a given paginated GitLab endpoint.\n *\n * This method may be used to perform authenticated REST calls against any\n * paginated GitLab endpoint which uses X-NEXT-PAGE headers. The return value\n * can be be used with the {@link paginated} async-generator function to yield\n * each item from the paged request.\n *\n * @see {@link paginated}\n * @param endpoint - The request endpoint, e.g. /projects.\n * @param options - Request queryString options which may also include page variables.\n */\n async pagedRequest<T = any>(\n endpoint: string,\n options?: CommonListOptions,\n ): Promise<PagedResponse<T>> {\n const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n\n this.logger.debug(`Fetching: ${request.toString()}`);\n const response = await fetch(\n request.toString(),\n getGitLabRequestOptions(this.config),\n );\n if (!response.ok) {\n throw new Error(\n `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${\n response.status\n } - ${response.statusText}`,\n );\n }\n return response.json().then(items => {\n const nextPage = response.headers.get('x-next-page');\n\n return {\n items,\n nextPage: nextPage ? Number(nextPage) : null,\n } as PagedResponse<any>;\n });\n }\n}\n\n/**\n * Advances through each page and provides each item from a paginated request.\n *\n * The async generator function yields each item from repeated calls to the\n * provided request function. The generator walks through each available page by\n * setting the page key in the options passed into the request function and\n * making repeated calls until there are no more pages.\n *\n * @see {@link pagedRequest}\n * @param request - Function which returns a PagedResponse to walk through.\n * @param options - Initial ListOptions for the request function.\n */\nexport async function* paginated<T = any>(\n request: (options: CommonListOptions) => Promise<PagedResponse<T>>,\n options: CommonListOptions,\n) {\n let res;\n do {\n res = await request(options);\n options.page = res.nextPage;\n for (const item of res.items) {\n yield item;\n }\n } while (res.nextPage);\n}\n","/*\n * Copyright 2022 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 { readTaskScheduleDefinitionFromConfig } from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\nimport { GitlabProviderConfig } from '../lib';\n\n/**\n * Extracts the gitlab config from a config object\n *\n * @public\n *\n * @param id - The provider key\n * @param config - The config object to extract from\n */\nfunction readGitlabConfig(id: string, config: Config): GitlabProviderConfig {\n const group = config.getOptionalString('group') ?? '';\n const host = config.getString('host');\n const branch = config.getOptionalString('branch') ?? 'master';\n const catalogFile =\n config.getOptionalString('entityFilename') ?? 'catalog-info.yaml';\n const projectPattern = new RegExp(\n config.getOptionalString('projectPattern') ?? /[\\s\\S]*/,\n );\n const userPattern = new RegExp(\n config.getOptionalString('userPattern') ?? /[\\s\\S]*/,\n );\n const groupPattern = new RegExp(\n config.getOptionalString('groupPattern') ?? /[\\s\\S]*/,\n );\n const orgEnabled: boolean = config.getOptionalBoolean('orgEnabled') ?? false;\n\n const schedule = config.has('schedule')\n ? readTaskScheduleDefinitionFromConfig(config.getConfig('schedule'))\n : undefined;\n\n return {\n id,\n group,\n branch,\n host,\n catalogFile,\n projectPattern,\n userPattern,\n groupPattern,\n schedule,\n orgEnabled,\n };\n}\n\n/**\n * Extracts the gitlab config from a config object array\n *\n * @public\n *\n * @param config - The config object to extract from\n */\nexport function readGitlabConfigs(config: Config): GitlabProviderConfig[] {\n const configs: GitlabProviderConfig[] = [];\n\n const providerConfigs = config.getOptionalConfig('catalog.providers.gitlab');\n\n if (!providerConfigs) {\n return configs;\n }\n\n for (const id of providerConfigs.keys()) {\n configs.push(readGitlabConfig(id, providerConfigs.getConfig(id)));\n }\n\n return configs;\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 */\n\nimport { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\nimport { GitLabIntegration, ScmIntegrations } from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n LocationSpec,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-backend';\nimport * as uuid from 'uuid';\nimport { Logger } from 'winston';\nimport {\n GitLabClient,\n GitLabProject,\n GitlabProviderConfig,\n paginated,\n readGitlabConfigs,\n} from '../lib';\n\ntype Result = {\n scanned: number;\n matches: GitLabProject[];\n};\n\n/**\n * Discovers entity definition files in the groups of a Gitlab instance.\n * @public\n */\nexport class GitlabDiscoveryEntityProvider 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 ): GitlabDiscoveryEntityProvider[] {\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: GitlabDiscoveryEntityProvider[] = [];\n\n providerConfigs.forEach(providerConfig => {\n const integration = integrations.byHost(providerConfig.host);\n if (!integration) {\n throw new Error(\n `No gitlab integration found that matches host ${providerConfig.host}`,\n );\n }\n\n if (!options.schedule && !providerConfig.schedule) {\n throw new Error(\n `No schedule provided neither via code nor config for GitlabDiscoveryEntityProvider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n providers.push(\n new GitlabDiscoveryEntityProvider({\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 `GitlabDiscoveryEntityProvider:${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: GitlabDiscoveryEntityProvider.prototype.constructor.name,\n taskId,\n taskInstanceId: uuid.v4(),\n });\n\n try {\n await this.refresh(logger);\n } catch (error) {\n logger.error(`${this.getProviderName()} refresh failed`, error);\n }\n },\n });\n };\n }\n\n 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 const projects = paginated<GitLabProject>(\n options => client.listProjects(options),\n {\n group: this.config.group,\n page: 1,\n per_page: 50,\n },\n );\n\n const res: Result = {\n scanned: 0,\n matches: [],\n };\n\n for await (const project of projects) {\n if (!this.config.projectPattern.test(project.path_with_namespace ?? '')) {\n continue;\n }\n\n res.scanned++;\n\n if (project.archived) {\n continue;\n }\n\n if (this.config.branch === '*' && project.default_branch === undefined) {\n continue;\n }\n\n const project_branch = project.default_branch ?? this.config.branch;\n\n const projectHasFile: boolean = await client.hasFile(\n project.path_with_namespace ?? '',\n project_branch,\n this.config.catalogFile,\n );\n if (projectHasFile) {\n res.matches.push(project);\n }\n }\n\n const locations = res.matches.map(p => this.createLocationSpec(p));\n await this.connection.applyMutation({\n type: 'full',\n entities: locations.map(location => ({\n locationKey: this.getProviderName(),\n entity: locationSpecToLocationEntity({ location }),\n })),\n });\n }\n\n private createLocationSpec(project: GitLabProject): LocationSpec {\n const project_branch = project.default_branch ?? this.config.branch;\n return {\n type: 'url',\n target: `${project.web_url}/-/blob/${project_branch}/${this.config.catalogFile}`,\n presence: 'optional',\n };\n }\n}\n","/*\n * Copyright 2022 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 createBackendModule,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport { loggerToWinstonLogger } from '@backstage/backend-common';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\nimport { GitlabDiscoveryEntityProvider } from '../providers';\n\n/**\n * Registers the GitlabDiscoveryEntityProvider with the catalog processing extension point.\n *\n * @alpha\n */\nexport const gitlabDiscoveryEntityProviderCatalogModule = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'gitlabDiscoveryEntityProvider',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.config,\n catalog: catalogProcessingExtensionPoint,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({ config, catalog, logger, scheduler }) {\n catalog.addEntityProvider(\n GitlabDiscoveryEntityProvider.fromConfig(config, {\n logger: loggerToWinstonLogger(logger),\n scheduler,\n }),\n );\n },\n });\n },\n});\n"],"names":["fetch","getGitLabRequestOptions","readTaskScheduleDefinitionFromConfig","ScmIntegrations","uuid","locationSpecToLocationEntity","createBackendModule","coreServices","catalogProcessingExtensionPoint","loggerToWinstonLogger"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CO,MAAM,YAAa,CAAA;AAAA,EAIxB,YAAY,OAA8D,EAAA;AACxE,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AACtB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA,EAKA,aAAyB,GAAA;AACvB,IAAO,OAAA,IAAA,CAAK,OAAO,IAAS,KAAA,YAAA,CAAA;AAAA,GAC9B;AAAA,EAEA,MAAM,aACJ,OAC6B,EAAA;AAC7B,IAAA,IAAI,mCAAS,KAAO,EAAA;AAClB,MAAA,OAAO,IAAK,CAAA,YAAA;AAAA,QACV,CAAA,QAAA,EAAW,kBAAmB,CAAA,OAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAS,KAAK,CAAA,CAAA,SAAA,CAAA;AAAA,QAC5C;AAAA,UACE,GAAG,OAAA;AAAA,UACH,iBAAmB,EAAA,IAAA;AAAA,SACrB;AAAA,OACF,CAAA;AAAA,KACF;AAEA,IAAO,OAAA,IAAA,CAAK,YAAa,CAAA,CAAA,SAAA,CAAA,EAAa,OAAO,CAAA,CAAA;AAAA,GAC/C;AAAA,EAEA,MAAM,UACJ,OACoC,EAAA;AACpC,IAAA,IAAI,cAAiB,GAAA,OAAA,CAA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,cAAA,CAAA,CAAA,EAAkB,KAAK,MAAO,CAAA,WAAA,CAAA,CAAA;AAAA,MACnE,QAAU,EAAA,UAAA;AAAA,KACZ,CAAA;AAAA,GACF;AACF;;ACxLO,MAAM,6CAA6CC,oCAAoB,CAAA;AAAA,EAC5E,QAAU,EAAA,SAAA;AAAA,EACV,QAAU,EAAA,+BAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,MAAA;AAAA,QACrB,OAAS,EAAAC,qCAAA;AAAA,QACT,QAAQD,6BAAa,CAAA,MAAA;AAAA,QACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,OAC1B;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,QAAQ,OAAS,EAAA,MAAA,EAAQ,WAAa,EAAA;AACjD,QAAQ,OAAA,CAAA,iBAAA;AAAA,UACN,6BAAA,CAA8B,WAAW,MAAQ,EAAA;AAAA,YAC/C,MAAA,EAAQE,oCAAsB,MAAM,CAAA;AAAA,YACpC,SAAA;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
|
package/dist/alpha.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Registers the GitlabDiscoveryEntityProvider with the catalog processing extension point.
|
|
5
|
+
*
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
8
|
+
declare const gitlabDiscoveryEntityProviderCatalogModule: () => _backstage_backend_plugin_api.BackendFeature;
|
|
9
|
+
|
|
10
|
+
export { gitlabDiscoveryEntityProviderCatalogModule };
|
package/dist/index.cjs.js
CHANGED
|
@@ -10,8 +10,6 @@ var backendTasks = require('@backstage/backend-tasks');
|
|
|
10
10
|
var uuid = require('uuid');
|
|
11
11
|
var catalogModel = require('@backstage/catalog-model');
|
|
12
12
|
var lodash = require('lodash');
|
|
13
|
-
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
14
|
-
var pluginCatalogNode = require('@backstage/plugin-catalog-node');
|
|
15
13
|
|
|
16
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
15
|
|
|
@@ -695,31 +693,7 @@ class GitlabOrgDiscoveryEntityProvider {
|
|
|
695
693
|
}
|
|
696
694
|
}
|
|
697
695
|
|
|
698
|
-
const gitlabDiscoveryEntityProviderCatalogModule = backendPluginApi.createBackendModule({
|
|
699
|
-
pluginId: "catalog",
|
|
700
|
-
moduleId: "gitlabDiscoveryEntityProvider",
|
|
701
|
-
register(env) {
|
|
702
|
-
env.registerInit({
|
|
703
|
-
deps: {
|
|
704
|
-
config: backendPluginApi.coreServices.config,
|
|
705
|
-
catalog: pluginCatalogNode.catalogProcessingExtensionPoint,
|
|
706
|
-
logger: backendPluginApi.coreServices.logger,
|
|
707
|
-
scheduler: backendPluginApi.coreServices.scheduler
|
|
708
|
-
},
|
|
709
|
-
async init({ config, catalog, logger, scheduler }) {
|
|
710
|
-
catalog.addEntityProvider(
|
|
711
|
-
GitlabDiscoveryEntityProvider.fromConfig(config, {
|
|
712
|
-
logger: backendCommon.loggerToWinstonLogger(logger),
|
|
713
|
-
scheduler
|
|
714
|
-
})
|
|
715
|
-
);
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
});
|
|
720
|
-
|
|
721
696
|
exports.GitLabDiscoveryProcessor = GitLabDiscoveryProcessor;
|
|
722
697
|
exports.GitlabDiscoveryEntityProvider = GitlabDiscoveryEntityProvider;
|
|
723
698
|
exports.GitlabOrgDiscoveryEntityProvider = GitlabOrgDiscoveryEntityProvider;
|
|
724
|
-
exports.gitlabDiscoveryEntityProviderCatalogModule = gitlabDiscoveryEntityProviderCatalogModule;
|
|
725
699
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/lib/client.ts","../src/providers/config.ts","../src/GitLabDiscoveryProcessor.ts","../src/providers/GitlabDiscoveryEntityProvider.ts","../src/providers/GitlabOrgDiscoveryEntityProvider.ts","../src/service/GitlabDiscoveryEntityProviderCatalogModule.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 fetch from 'node-fetch';\nimport {\n getGitLabRequestOptions,\n GitLabIntegrationConfig,\n} from '@backstage/integration';\nimport { Logger } from 'winston';\nimport { GitLabGroup, GitLabMembership, GitLabUser } from './types';\n\nexport type CommonListOptions = {\n [key: string]: string | number | boolean | undefined;\n per_page?: number | undefined;\n page?: number | undefined;\n active?: boolean;\n};\n\ninterface ListProjectOptions extends CommonListOptions {\n group?: string;\n}\n\ninterface UserListOptions extends CommonListOptions {\n without_project_bots?: boolean | undefined;\n exclude_internal?: boolean | undefined;\n}\n\nexport type PagedResponse<T> = {\n items: T[];\n nextPage?: number;\n};\n\nexport class GitLabClient {\n private readonly config: GitLabIntegrationConfig;\n private readonly logger: Logger;\n\n constructor(options: { config: GitLabIntegrationConfig; logger: Logger }) {\n this.config = options.config;\n this.logger = options.logger;\n }\n\n /**\n * Indicates whether the client is for a SaaS or self managed GitLab instance.\n */\n isSelfManaged(): boolean {\n return this.config.host !== 'gitlab.com';\n }\n\n async listProjects(\n options?: ListProjectOptions,\n ): Promise<PagedResponse<any>> {\n if (options?.group) {\n return this.pagedRequest(\n `/groups/${encodeURIComponent(options?.group)}/projects`,\n {\n ...options,\n include_subgroups: true,\n },\n );\n }\n\n return this.pagedRequest(`/projects`, options);\n }\n\n async listUsers(\n options?: UserListOptions,\n ): Promise<PagedResponse<GitLabUser>> {\n let requestOptions = options;\n\n if (!requestOptions) {\n requestOptions = {};\n }\n\n requestOptions.without_project_bots = true;\n requestOptions.exclude_internal = true;\n\n return this.pagedRequest(`/users?`, requestOptions);\n }\n\n async listGroups(\n options?: CommonListOptions,\n ): Promise<PagedResponse<GitLabGroup>> {\n return this.pagedRequest(`/groups`, options);\n }\n\n async getUserMemberships(userId: number): Promise<GitLabMembership[]> {\n const endpoint: string = `/users/${encodeURIComponent(userId)}/memberships`;\n const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);\n request.searchParams.append('per_page', '100');\n\n const response = await fetch(request.toString(), {\n headers: getGitLabRequestOptions(this.config).headers,\n method: 'GET',\n });\n\n if (!response.ok) {\n if (response.status >= 500) {\n this.logger.debug(\n `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${\n response.status\n } - ${response.statusText}`,\n );\n }\n return [];\n }\n\n return response.json().then(items => {\n return items as GitLabMembership[];\n });\n }\n\n /**\n * General existence check.\n *\n * @param projectPath - The path to the project\n * @param branch - The branch used to search\n * @param filePath - The path to the file\n */\n async hasFile(\n projectPath: string,\n branch: string,\n filePath: string,\n ): Promise<boolean> {\n const endpoint: string = `/projects/${encodeURIComponent(\n projectPath,\n )}/repository/files/${encodeURIComponent(filePath)}`;\n const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);\n request.searchParams.append('ref', branch);\n\n const response = await fetch(request.toString(), {\n headers: getGitLabRequestOptions(this.config).headers,\n method: 'HEAD',\n });\n\n if (!response.ok) {\n if (response.status >= 500) {\n this.logger.debug(\n `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${\n response.status\n } - ${response.statusText}`,\n );\n }\n return false;\n }\n\n return true;\n }\n\n /**\n * Performs a request against a given paginated GitLab endpoint.\n *\n * This method may be used to perform authenticated REST calls against any\n * paginated GitLab endpoint which uses X-NEXT-PAGE headers. The return value\n * can be be used with the {@link paginated} async-generator function to yield\n * each item from the paged request.\n *\n * @see {@link paginated}\n * @param endpoint - The request endpoint, e.g. /projects.\n * @param options - Request queryString options which may also include page variables.\n */\n async pagedRequest<T = any>(\n endpoint: string,\n options?: CommonListOptions,\n ): Promise<PagedResponse<T>> {\n const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n\n this.logger.debug(`Fetching: ${request.toString()}`);\n const response = await fetch(\n request.toString(),\n getGitLabRequestOptions(this.config),\n );\n if (!response.ok) {\n throw new Error(\n `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${\n response.status\n } - ${response.statusText}`,\n );\n }\n return response.json().then(items => {\n const nextPage = response.headers.get('x-next-page');\n\n return {\n items,\n nextPage: nextPage ? Number(nextPage) : null,\n } as PagedResponse<any>;\n });\n }\n}\n\n/**\n * Advances through each page and provides each item from a paginated request.\n *\n * The async generator function yields each item from repeated calls to the\n * provided request function. The generator walks through each available page by\n * setting the page key in the options passed into the request function and\n * making repeated calls until there are no more pages.\n *\n * @see {@link pagedRequest}\n * @param request - Function which returns a PagedResponse to walk through.\n * @param options - Initial ListOptions for the request function.\n */\nexport async function* paginated<T = any>(\n request: (options: CommonListOptions) => Promise<PagedResponse<T>>,\n options: CommonListOptions,\n) {\n let res;\n do {\n res = await request(options);\n options.page = res.nextPage;\n for (const item of res.items) {\n yield item;\n }\n } while (res.nextPage);\n}\n","/*\n * Copyright 2022 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 { readTaskScheduleDefinitionFromConfig } from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\nimport { GitlabProviderConfig } from '../lib';\n\n/**\n * Extracts the gitlab config from a config object\n *\n * @public\n *\n * @param id - The provider key\n * @param config - The config object to extract from\n */\nfunction readGitlabConfig(id: string, config: Config): GitlabProviderConfig {\n const group = config.getOptionalString('group') ?? '';\n const host = config.getString('host');\n const branch = config.getOptionalString('branch') ?? 'master';\n const catalogFile =\n config.getOptionalString('entityFilename') ?? 'catalog-info.yaml';\n const projectPattern = new RegExp(\n config.getOptionalString('projectPattern') ?? /[\\s\\S]*/,\n );\n const userPattern = new RegExp(\n config.getOptionalString('userPattern') ?? /[\\s\\S]*/,\n );\n const groupPattern = new RegExp(\n config.getOptionalString('groupPattern') ?? /[\\s\\S]*/,\n );\n const orgEnabled: boolean = config.getOptionalBoolean('orgEnabled') ?? false;\n\n const schedule = config.has('schedule')\n ? readTaskScheduleDefinitionFromConfig(config.getConfig('schedule'))\n : undefined;\n\n return {\n id,\n group,\n branch,\n host,\n catalogFile,\n projectPattern,\n userPattern,\n groupPattern,\n schedule,\n orgEnabled,\n };\n}\n\n/**\n * Extracts the gitlab config from a config object array\n *\n * @public\n *\n * @param config - The config object to extract from\n */\nexport function readGitlabConfigs(config: Config): GitlabProviderConfig[] {\n const configs: GitlabProviderConfig[] = [];\n\n const providerConfigs = config.getOptionalConfig('catalog.providers.gitlab');\n\n if (!providerConfigs) {\n return configs;\n }\n\n for (const id of providerConfigs.keys()) {\n configs.push(readGitlabConfig(id, providerConfigs.getConfig(id)));\n }\n\n return configs;\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 */\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-backend';\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\n static fromConfig(\n config: Config,\n options: { logger: Logger; skipReposWithoutExactFileMatch?: boolean },\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 }) {\n this.integrations = options.integrations;\n this.cache = options.pluginCache.getClient();\n this.logger = options.logger;\n this.skipReposWithoutExactFileMatch =\n options.skipReposWithoutExactFileMatch || 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 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 (project.archived) {\n continue;\n }\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 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 */\n\nimport { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\nimport { GitLabIntegration, ScmIntegrations } from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n LocationSpec,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-backend';\nimport * as uuid from 'uuid';\nimport { Logger } from 'winston';\nimport {\n GitLabClient,\n GitLabProject,\n GitlabProviderConfig,\n paginated,\n readGitlabConfigs,\n} from '../lib';\n\ntype Result = {\n scanned: number;\n matches: GitLabProject[];\n};\n\n/**\n * Discovers entity definition files in the groups of a Gitlab instance.\n * @public\n */\nexport class GitlabDiscoveryEntityProvider 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 ): GitlabDiscoveryEntityProvider[] {\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: GitlabDiscoveryEntityProvider[] = [];\n\n providerConfigs.forEach(providerConfig => {\n const integration = integrations.byHost(providerConfig.host);\n if (!integration) {\n throw new Error(\n `No gitlab integration found that matches host ${providerConfig.host}`,\n );\n }\n\n if (!options.schedule && !providerConfig.schedule) {\n throw new Error(\n `No schedule provided neither via code nor config for GitlabDiscoveryEntityProvider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n providers.push(\n new GitlabDiscoveryEntityProvider({\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 `GitlabDiscoveryEntityProvider:${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: GitlabDiscoveryEntityProvider.prototype.constructor.name,\n taskId,\n taskInstanceId: uuid.v4(),\n });\n\n try {\n await this.refresh(logger);\n } catch (error) {\n logger.error(`${this.getProviderName()} refresh failed`, error);\n }\n },\n });\n };\n }\n\n 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 const projects = paginated<GitLabProject>(\n options => client.listProjects(options),\n {\n group: this.config.group,\n page: 1,\n per_page: 50,\n },\n );\n\n const res: Result = {\n scanned: 0,\n matches: [],\n };\n\n for await (const project of projects) {\n if (!this.config.projectPattern.test(project.path_with_namespace ?? '')) {\n continue;\n }\n\n res.scanned++;\n\n if (project.archived) {\n continue;\n }\n\n if (this.config.branch === '*' && project.default_branch === undefined) {\n continue;\n }\n\n const project_branch = project.default_branch ?? this.config.branch;\n\n const projectHasFile: boolean = await client.hasFile(\n project.path_with_namespace ?? '',\n project_branch,\n this.config.catalogFile,\n );\n if (projectHasFile) {\n res.matches.push(project);\n }\n }\n\n const locations = res.matches.map(p => this.createLocationSpec(p));\n await this.connection.applyMutation({\n type: 'full',\n entities: locations.map(location => ({\n locationKey: this.getProviderName(),\n entity: locationSpecToLocationEntity({ location }),\n })),\n });\n }\n\n private createLocationSpec(project: GitLabProject): LocationSpec {\n const project_branch = project.default_branch ?? this.config.branch;\n return {\n type: 'url',\n target: `${project.web_url}/-/blob/${project_branch}/${this.config.catalogFile}`,\n presence: 'optional',\n };\n }\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 */\n\nimport { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\nimport { GitLabIntegration, ScmIntegrations } from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-backend';\nimport * as uuid from 'uuid';\nimport { Logger } from 'winston';\nimport {\n GitLabClient,\n GitlabProviderConfig,\n paginated,\n readGitlabConfigs,\n} from '../lib';\nimport { GitLabGroup, GitLabUser } from '../lib/types';\nimport {\n ANNOTATION_LOCATION,\n ANNOTATION_ORIGIN_LOCATION,\n Entity,\n UserEntity,\n GroupEntity,\n} from '@backstage/catalog-model';\nimport { merge } from 'lodash';\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 (!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(`${this.getProviderName()} refresh failed`, error);\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 const users = paginated<GitLabUser>(options => client.listUsers(options), {\n page: 1,\n per_page: 100,\n active: true,\n });\n\n const groups = paginated<GitLabGroup>(\n options => client.listGroups(options),\n {\n page: 1,\n per_page: 100,\n },\n );\n\n const idMappedGroup: { [groupId: number]: GitLabGroup } = {};\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 group of groups) {\n if (!this.config.groupPattern.test(group.full_path ?? '')) {\n continue;\n }\n\n groupRes.scanned++;\n groupRes.matches.push(group);\n\n idMappedGroup[group.id] = group;\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 const memberships = await client.getUserMemberships(user.id);\n const userGroups: GitLabGroup[] = [];\n\n for (const i of memberships) {\n if (\n i.source_type === 'Namespace' &&\n idMappedGroup.hasOwnProperty(i.source_id)\n ) {\n userGroups.push(idMappedGroup[i.source_id]);\n }\n }\n\n user.groups = userGroups;\n\n res.matches.push(user);\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(this.integration.config.host, entity),\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 = idMapped[group.parent_id].full_path;\n }\n\n entities.push(entity);\n }\n\n return entities;\n }\n\n private withLocations(host: string, entity: Entity): Entity {\n const location =\n entity.kind === 'Group'\n ? `url:${host}/teams/${entity.metadata.name}`\n : `url:${host}/${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\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,\n picture: user.avatar_url,\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(group.full_path.replace('/', '-'));\n }\n }\n\n return entity;\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: group.full_path.replace('/', '-'),\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","/*\n * Copyright 2022 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 createBackendModule,\n coreServices,\n} from '@backstage/backend-plugin-api';\nimport { loggerToWinstonLogger } from '@backstage/backend-common';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node';\nimport { GitlabDiscoveryEntityProvider } from '../providers';\n\n/**\n * Registers the GitlabDiscoveryEntityProvider with the catalog processing extension point.\n *\n * @alpha\n */\nexport const gitlabDiscoveryEntityProviderCatalogModule = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'gitlabDiscoveryEntityProvider',\n register(env) {\n env.registerInit({\n deps: {\n config: coreServices.config,\n catalog: catalogProcessingExtensionPoint,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({ config, catalog, logger, scheduler }) {\n catalog.addEntityProvider(\n GitlabDiscoveryEntityProvider.fromConfig(config, {\n logger: loggerToWinstonLogger(logger),\n scheduler,\n }),\n );\n },\n });\n },\n});\n"],"names":["fetch","getGitLabRequestOptions","readTaskScheduleDefinitionFromConfig","ScmIntegrations","CacheManager","processingResult","uuid","locationSpecToLocationEntity","_a","merge","ANNOTATION_LOCATION","ANNOTATION_ORIGIN_LOCATION","createBackendModule","coreServices","catalogProcessingExtensionPoint","loggerToWinstonLogger"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CO,MAAM,YAAa,CAAA;AAAA,EAIxB,YAAY,OAA8D,EAAA;AACxE,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AACtB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA,EAKA,aAAyB,GAAA;AACvB,IAAO,OAAA,IAAA,CAAK,OAAO,IAAS,KAAA,YAAA,CAAA;AAAA,GAC9B;AAAA,EAEA,MAAM,aACJ,OAC6B,EAAA;AAC7B,IAAA,IAAI,mCAAS,KAAO,EAAA;AAClB,MAAA,OAAO,IAAK,CAAA,YAAA;AAAA,QACV,CAAA,QAAA,EAAW,kBAAmB,CAAA,OAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAS,KAAK,CAAA,CAAA,SAAA,CAAA;AAAA,QAC5C;AAAA,UACE,GAAG,OAAA;AAAA,UACH,iBAAmB,EAAA,IAAA;AAAA,SACrB;AAAA,OACF,CAAA;AAAA,KACF;AAEA,IAAO,OAAA,IAAA,CAAK,YAAa,CAAA,CAAA,SAAA,CAAA,EAAa,OAAO,CAAA,CAAA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AAQ,OAAS,EAAA,MAAA,EAAQ,WAAa,EAAA;AACjD,QAAQ,OAAA,CAAA,iBAAA;AAAA,UACN,6BAAA,CAA8B,WAAW,MAAQ,EAAA;AAAA,YAC/C,MAAA,EAAQE,oCAAsB,MAAM,CAAA;AAAA,YACpC,SAAA;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/lib/client.ts","../src/providers/config.ts","../src/GitLabDiscoveryProcessor.ts","../src/providers/GitlabDiscoveryEntityProvider.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 fetch from 'node-fetch';\nimport {\n getGitLabRequestOptions,\n GitLabIntegrationConfig,\n} from '@backstage/integration';\nimport { Logger } from 'winston';\nimport { GitLabGroup, GitLabMembership, GitLabUser } from './types';\n\nexport type CommonListOptions = {\n [key: string]: string | number | boolean | undefined;\n per_page?: number | undefined;\n page?: number | undefined;\n active?: boolean;\n};\n\ninterface ListProjectOptions extends CommonListOptions {\n group?: string;\n}\n\ninterface UserListOptions extends CommonListOptions {\n without_project_bots?: boolean | undefined;\n exclude_internal?: boolean | undefined;\n}\n\nexport type PagedResponse<T> = {\n items: T[];\n nextPage?: number;\n};\n\nexport class GitLabClient {\n private readonly config: GitLabIntegrationConfig;\n private readonly logger: Logger;\n\n constructor(options: { config: GitLabIntegrationConfig; logger: Logger }) {\n this.config = options.config;\n this.logger = options.logger;\n }\n\n /**\n * Indicates whether the client is for a SaaS or self managed GitLab instance.\n */\n isSelfManaged(): boolean {\n return this.config.host !== 'gitlab.com';\n }\n\n async listProjects(\n options?: ListProjectOptions,\n ): Promise<PagedResponse<any>> {\n if (options?.group) {\n return this.pagedRequest(\n `/groups/${encodeURIComponent(options?.group)}/projects`,\n {\n ...options,\n include_subgroups: true,\n },\n );\n }\n\n return this.pagedRequest(`/projects`, options);\n }\n\n async listUsers(\n options?: UserListOptions,\n ): Promise<PagedResponse<GitLabUser>> {\n let requestOptions = options;\n\n if (!requestOptions) {\n requestOptions = {};\n }\n\n requestOptions.without_project_bots = true;\n requestOptions.exclude_internal = true;\n\n return this.pagedRequest(`/users?`, requestOptions);\n }\n\n async listGroups(\n options?: CommonListOptions,\n ): Promise<PagedResponse<GitLabGroup>> {\n return this.pagedRequest(`/groups`, options);\n }\n\n async getUserMemberships(userId: number): Promise<GitLabMembership[]> {\n const endpoint: string = `/users/${encodeURIComponent(userId)}/memberships`;\n const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);\n request.searchParams.append('per_page', '100');\n\n const response = await fetch(request.toString(), {\n headers: getGitLabRequestOptions(this.config).headers,\n method: 'GET',\n });\n\n if (!response.ok) {\n if (response.status >= 500) {\n this.logger.debug(\n `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${\n response.status\n } - ${response.statusText}`,\n );\n }\n return [];\n }\n\n return response.json().then(items => {\n return items as GitLabMembership[];\n });\n }\n\n /**\n * General existence check.\n *\n * @param projectPath - The path to the project\n * @param branch - The branch used to search\n * @param filePath - The path to the file\n */\n async hasFile(\n projectPath: string,\n branch: string,\n filePath: string,\n ): Promise<boolean> {\n const endpoint: string = `/projects/${encodeURIComponent(\n projectPath,\n )}/repository/files/${encodeURIComponent(filePath)}`;\n const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);\n request.searchParams.append('ref', branch);\n\n const response = await fetch(request.toString(), {\n headers: getGitLabRequestOptions(this.config).headers,\n method: 'HEAD',\n });\n\n if (!response.ok) {\n if (response.status >= 500) {\n this.logger.debug(\n `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${\n response.status\n } - ${response.statusText}`,\n );\n }\n return false;\n }\n\n return true;\n }\n\n /**\n * Performs a request against a given paginated GitLab endpoint.\n *\n * This method may be used to perform authenticated REST calls against any\n * paginated GitLab endpoint which uses X-NEXT-PAGE headers. The return value\n * can be be used with the {@link paginated} async-generator function to yield\n * each item from the paged request.\n *\n * @see {@link paginated}\n * @param endpoint - The request endpoint, e.g. /projects.\n * @param options - Request queryString options which may also include page variables.\n */\n async pagedRequest<T = any>(\n endpoint: string,\n options?: CommonListOptions,\n ): Promise<PagedResponse<T>> {\n const request = new URL(`${this.config.apiBaseUrl}${endpoint}`);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n\n this.logger.debug(`Fetching: ${request.toString()}`);\n const response = await fetch(\n request.toString(),\n getGitLabRequestOptions(this.config),\n );\n if (!response.ok) {\n throw new Error(\n `Unexpected response when fetching ${request.toString()}. Expected 200 but got ${\n response.status\n } - ${response.statusText}`,\n );\n }\n return response.json().then(items => {\n const nextPage = response.headers.get('x-next-page');\n\n return {\n items,\n nextPage: nextPage ? Number(nextPage) : null,\n } as PagedResponse<any>;\n });\n }\n}\n\n/**\n * Advances through each page and provides each item from a paginated request.\n *\n * The async generator function yields each item from repeated calls to the\n * provided request function. The generator walks through each available page by\n * setting the page key in the options passed into the request function and\n * making repeated calls until there are no more pages.\n *\n * @see {@link pagedRequest}\n * @param request - Function which returns a PagedResponse to walk through.\n * @param options - Initial ListOptions for the request function.\n */\nexport async function* paginated<T = any>(\n request: (options: CommonListOptions) => Promise<PagedResponse<T>>,\n options: CommonListOptions,\n) {\n let res;\n do {\n res = await request(options);\n options.page = res.nextPage;\n for (const item of res.items) {\n yield item;\n }\n } while (res.nextPage);\n}\n","/*\n * Copyright 2022 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 { readTaskScheduleDefinitionFromConfig } from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\nimport { GitlabProviderConfig } from '../lib';\n\n/**\n * Extracts the gitlab config from a config object\n *\n * @public\n *\n * @param id - The provider key\n * @param config - The config object to extract from\n */\nfunction readGitlabConfig(id: string, config: Config): GitlabProviderConfig {\n const group = config.getOptionalString('group') ?? '';\n const host = config.getString('host');\n const branch = config.getOptionalString('branch') ?? 'master';\n const catalogFile =\n config.getOptionalString('entityFilename') ?? 'catalog-info.yaml';\n const projectPattern = new RegExp(\n config.getOptionalString('projectPattern') ?? /[\\s\\S]*/,\n );\n const userPattern = new RegExp(\n config.getOptionalString('userPattern') ?? /[\\s\\S]*/,\n );\n const groupPattern = new RegExp(\n config.getOptionalString('groupPattern') ?? /[\\s\\S]*/,\n );\n const orgEnabled: boolean = config.getOptionalBoolean('orgEnabled') ?? false;\n\n const schedule = config.has('schedule')\n ? readTaskScheduleDefinitionFromConfig(config.getConfig('schedule'))\n : undefined;\n\n return {\n id,\n group,\n branch,\n host,\n catalogFile,\n projectPattern,\n userPattern,\n groupPattern,\n schedule,\n orgEnabled,\n };\n}\n\n/**\n * Extracts the gitlab config from a config object array\n *\n * @public\n *\n * @param config - The config object to extract from\n */\nexport function readGitlabConfigs(config: Config): GitlabProviderConfig[] {\n const configs: GitlabProviderConfig[] = [];\n\n const providerConfigs = config.getOptionalConfig('catalog.providers.gitlab');\n\n if (!providerConfigs) {\n return configs;\n }\n\n for (const id of providerConfigs.keys()) {\n configs.push(readGitlabConfig(id, providerConfigs.getConfig(id)));\n }\n\n return configs;\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 */\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-backend';\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\n static fromConfig(\n config: Config,\n options: { logger: Logger; skipReposWithoutExactFileMatch?: boolean },\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 }) {\n this.integrations = options.integrations;\n this.cache = options.pluginCache.getClient();\n this.logger = options.logger;\n this.skipReposWithoutExactFileMatch =\n options.skipReposWithoutExactFileMatch || 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 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 (project.archived) {\n continue;\n }\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 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 */\n\nimport { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\nimport { GitLabIntegration, ScmIntegrations } from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n LocationSpec,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-backend';\nimport * as uuid from 'uuid';\nimport { Logger } from 'winston';\nimport {\n GitLabClient,\n GitLabProject,\n GitlabProviderConfig,\n paginated,\n readGitlabConfigs,\n} from '../lib';\n\ntype Result = {\n scanned: number;\n matches: GitLabProject[];\n};\n\n/**\n * Discovers entity definition files in the groups of a Gitlab instance.\n * @public\n */\nexport class GitlabDiscoveryEntityProvider 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 ): GitlabDiscoveryEntityProvider[] {\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: GitlabDiscoveryEntityProvider[] = [];\n\n providerConfigs.forEach(providerConfig => {\n const integration = integrations.byHost(providerConfig.host);\n if (!integration) {\n throw new Error(\n `No gitlab integration found that matches host ${providerConfig.host}`,\n );\n }\n\n if (!options.schedule && !providerConfig.schedule) {\n throw new Error(\n `No schedule provided neither via code nor config for GitlabDiscoveryEntityProvider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n providers.push(\n new GitlabDiscoveryEntityProvider({\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 `GitlabDiscoveryEntityProvider:${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: GitlabDiscoveryEntityProvider.prototype.constructor.name,\n taskId,\n taskInstanceId: uuid.v4(),\n });\n\n try {\n await this.refresh(logger);\n } catch (error) {\n logger.error(`${this.getProviderName()} refresh failed`, error);\n }\n },\n });\n };\n }\n\n 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 const projects = paginated<GitLabProject>(\n options => client.listProjects(options),\n {\n group: this.config.group,\n page: 1,\n per_page: 50,\n },\n );\n\n const res: Result = {\n scanned: 0,\n matches: [],\n };\n\n for await (const project of projects) {\n if (!this.config.projectPattern.test(project.path_with_namespace ?? '')) {\n continue;\n }\n\n res.scanned++;\n\n if (project.archived) {\n continue;\n }\n\n if (this.config.branch === '*' && project.default_branch === undefined) {\n continue;\n }\n\n const project_branch = project.default_branch ?? this.config.branch;\n\n const projectHasFile: boolean = await client.hasFile(\n project.path_with_namespace ?? '',\n project_branch,\n this.config.catalogFile,\n );\n if (projectHasFile) {\n res.matches.push(project);\n }\n }\n\n const locations = res.matches.map(p => this.createLocationSpec(p));\n await this.connection.applyMutation({\n type: 'full',\n entities: locations.map(location => ({\n locationKey: this.getProviderName(),\n entity: locationSpecToLocationEntity({ location }),\n })),\n });\n }\n\n private createLocationSpec(project: GitLabProject): LocationSpec {\n const project_branch = project.default_branch ?? this.config.branch;\n return {\n type: 'url',\n target: `${project.web_url}/-/blob/${project_branch}/${this.config.catalogFile}`,\n presence: 'optional',\n };\n }\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 */\n\nimport { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\nimport { GitLabIntegration, ScmIntegrations } from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-backend';\nimport * as uuid from 'uuid';\nimport { Logger } from 'winston';\nimport {\n GitLabClient,\n GitlabProviderConfig,\n paginated,\n readGitlabConfigs,\n} from '../lib';\nimport { GitLabGroup, GitLabUser } from '../lib/types';\nimport {\n ANNOTATION_LOCATION,\n ANNOTATION_ORIGIN_LOCATION,\n Entity,\n UserEntity,\n GroupEntity,\n} from '@backstage/catalog-model';\nimport { merge } from 'lodash';\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 (!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(`${this.getProviderName()} refresh failed`, error);\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 const users = paginated<GitLabUser>(options => client.listUsers(options), {\n page: 1,\n per_page: 100,\n active: true,\n });\n\n const groups = paginated<GitLabGroup>(\n options => client.listGroups(options),\n {\n page: 1,\n per_page: 100,\n },\n );\n\n const idMappedGroup: { [groupId: number]: GitLabGroup } = {};\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 group of groups) {\n if (!this.config.groupPattern.test(group.full_path ?? '')) {\n continue;\n }\n\n groupRes.scanned++;\n groupRes.matches.push(group);\n\n idMappedGroup[group.id] = group;\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 const memberships = await client.getUserMemberships(user.id);\n const userGroups: GitLabGroup[] = [];\n\n for (const i of memberships) {\n if (\n i.source_type === 'Namespace' &&\n idMappedGroup.hasOwnProperty(i.source_id)\n ) {\n userGroups.push(idMappedGroup[i.source_id]);\n }\n }\n\n user.groups = userGroups;\n\n res.matches.push(user);\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(this.integration.config.host, entity),\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 = idMapped[group.parent_id].full_path;\n }\n\n entities.push(entity);\n }\n\n return entities;\n }\n\n private withLocations(host: string, entity: Entity): Entity {\n const location =\n entity.kind === 'Group'\n ? `url:${host}/teams/${entity.metadata.name}`\n : `url:${host}/${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\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,\n picture: user.avatar_url,\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(group.full_path.replace('/', '-'));\n }\n }\n\n return entity;\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: group.full_path.replace('/', '-'),\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":["fetch","getGitLabRequestOptions","readTaskScheduleDefinitionFromConfig","ScmIntegrations","CacheManager","processingResult","uuid","locationSpecToLocationEntity","_a","merge","ANNOTATION_LOCATION","ANNOTATION_ORIGIN_LOCATION"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CO,MAAM,YAAa,CAAA;AAAA,EAIxB,YAAY,OAA8D,EAAA;AACxE,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AACtB,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AAAA,GACxB;AAAA;AAAA;AAAA;AAAA,EAKA,aAAyB,GAAA;A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MAAO,MAAA,CAAA,QAAA,CAAS,cAAc,KAAM,CAAA,WAAA,CAAA;AAAA,KACtC;AAEA,IAAO,OAAA,MAAA,CAAA;AAAA,GACT;AACF;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A Backstage catalog backend module that helps integrate towards GitLab
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { BackendFeature } from '@backstage/backend-plugin-api';
|
|
8
|
-
import { CatalogProcessor } from '@backstage/plugin-catalog-backend';
|
|
9
|
-
import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend';
|
|
10
1
|
import { Config } from '@backstage/config';
|
|
11
|
-
import { EntityProvider } from '@backstage/plugin-catalog-backend';
|
|
12
|
-
import { EntityProviderConnection } from '@backstage/plugin-catalog-backend';
|
|
13
|
-
import { LocationSpec } from '@backstage/plugin-catalog-backend';
|
|
2
|
+
import { CatalogProcessor, LocationSpec, CatalogProcessorEmit, EntityProvider, EntityProviderConnection } from '@backstage/plugin-catalog-backend';
|
|
14
3
|
import { Logger } from 'winston';
|
|
15
|
-
import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
|
16
|
-
|
|
4
|
+
import { TaskRunner, PluginTaskScheduler } from '@backstage/backend-tasks';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Extracts repositories out of an GitLab instance.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
declare class GitLabDiscoveryProcessor implements CatalogProcessor {
|
|
11
|
+
private readonly integrations;
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private readonly cache;
|
|
14
|
+
private readonly skipReposWithoutExactFileMatch;
|
|
15
|
+
static fromConfig(config: Config, options: {
|
|
16
|
+
logger: Logger;
|
|
17
|
+
skipReposWithoutExactFileMatch?: boolean;
|
|
18
|
+
}): GitLabDiscoveryProcessor;
|
|
19
|
+
private constructor();
|
|
20
|
+
getProcessorName(): string;
|
|
21
|
+
readLocation(location: LocationSpec, _optional: boolean, emit: CatalogProcessorEmit): Promise<boolean>;
|
|
22
|
+
private getCacheKey;
|
|
23
|
+
}
|
|
17
24
|
|
|
18
25
|
/**
|
|
19
26
|
* Discovers entity definition files in the groups of a Gitlab instance.
|
|
20
27
|
* @public
|
|
21
28
|
*/
|
|
22
|
-
|
|
29
|
+
declare class GitlabDiscoveryEntityProvider implements EntityProvider {
|
|
23
30
|
private readonly config;
|
|
24
31
|
private readonly integration;
|
|
25
32
|
private readonly logger;
|
|
@@ -38,32 +45,11 @@ export declare class GitlabDiscoveryEntityProvider implements EntityProvider {
|
|
|
38
45
|
private createLocationSpec;
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
/* Excluded from this release type: gitlabDiscoveryEntityProviderCatalogModule */
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Extracts repositories out of an GitLab instance.
|
|
45
|
-
* @public
|
|
46
|
-
*/
|
|
47
|
-
export declare class GitLabDiscoveryProcessor implements CatalogProcessor {
|
|
48
|
-
private readonly integrations;
|
|
49
|
-
private readonly logger;
|
|
50
|
-
private readonly cache;
|
|
51
|
-
private readonly skipReposWithoutExactFileMatch;
|
|
52
|
-
static fromConfig(config: Config, options: {
|
|
53
|
-
logger: Logger;
|
|
54
|
-
skipReposWithoutExactFileMatch?: boolean;
|
|
55
|
-
}): GitLabDiscoveryProcessor;
|
|
56
|
-
private constructor();
|
|
57
|
-
getProcessorName(): string;
|
|
58
|
-
readLocation(location: LocationSpec, _optional: boolean, emit: CatalogProcessorEmit): Promise<boolean>;
|
|
59
|
-
private getCacheKey;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
48
|
/**
|
|
63
49
|
* Discovers users and groups from a Gitlab instance.
|
|
64
50
|
* @public
|
|
65
51
|
*/
|
|
66
|
-
|
|
52
|
+
declare class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
|
67
53
|
private readonly config;
|
|
68
54
|
private readonly integration;
|
|
69
55
|
private readonly logger;
|
|
@@ -85,4 +71,4 @@ export declare class GitlabOrgDiscoveryEntityProvider implements EntityProvider
|
|
|
85
71
|
private createGroupEntity;
|
|
86
72
|
}
|
|
87
73
|
|
|
88
|
-
export { }
|
|
74
|
+
export { GitLabDiscoveryProcessor, GitlabDiscoveryEntityProvider, GitlabOrgDiscoveryEntityProvider };
|
package/package.json
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
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.1.
|
|
5
|
-
"main": "dist/index.cjs.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
4
|
+
"version": "0.1.14-next.0",
|
|
5
|
+
"main": "./dist/index.cjs.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"publishConfig": {
|
|
9
|
-
"access": "public"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"require": "./dist/index.cjs.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.cjs.js"
|
|
16
|
+
},
|
|
17
|
+
"./alpha": {
|
|
18
|
+
"require": "./dist/alpha.cjs.js",
|
|
19
|
+
"types": "./dist/alpha.d.ts",
|
|
20
|
+
"default": "./dist/alpha.cjs.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
13
23
|
},
|
|
14
24
|
"backstage": {
|
|
15
25
|
"role": "backend-plugin-module"
|
|
@@ -25,7 +35,7 @@
|
|
|
25
35
|
],
|
|
26
36
|
"scripts": {
|
|
27
37
|
"start": "backstage-cli package start",
|
|
28
|
-
"build": "backstage-cli package build
|
|
38
|
+
"build": "backstage-cli package build",
|
|
29
39
|
"lint": "backstage-cli package lint",
|
|
30
40
|
"test": "backstage-cli package test",
|
|
31
41
|
"prepack": "backstage-cli package prepack",
|
|
@@ -33,15 +43,15 @@
|
|
|
33
43
|
"clean": "backstage-cli package clean"
|
|
34
44
|
},
|
|
35
45
|
"dependencies": {
|
|
36
|
-
"@backstage/backend-common": "^0.18.
|
|
37
|
-
"@backstage/backend-plugin-api": "^0.4.
|
|
38
|
-
"@backstage/backend-tasks": "^0.4.
|
|
39
|
-
"@backstage/catalog-model": "^1.2.
|
|
46
|
+
"@backstage/backend-common": "^0.18.3-next.0",
|
|
47
|
+
"@backstage/backend-plugin-api": "^0.4.1-next.0",
|
|
48
|
+
"@backstage/backend-tasks": "^0.4.4-next.0",
|
|
49
|
+
"@backstage/catalog-model": "^1.2.1-next.0",
|
|
40
50
|
"@backstage/config": "^1.0.6",
|
|
41
51
|
"@backstage/errors": "^1.1.4",
|
|
42
52
|
"@backstage/integration": "^1.4.2",
|
|
43
|
-
"@backstage/plugin-catalog-backend": "^1.
|
|
44
|
-
"@backstage/plugin-catalog-node": "^1.3.
|
|
53
|
+
"@backstage/plugin-catalog-backend": "^1.8.0-next.0",
|
|
54
|
+
"@backstage/plugin-catalog-node": "^1.3.4-next.0",
|
|
45
55
|
"@backstage/types": "^1.0.2",
|
|
46
56
|
"lodash": "^4.17.21",
|
|
47
57
|
"node-fetch": "^2.6.7",
|
|
@@ -49,17 +59,17 @@
|
|
|
49
59
|
"winston": "^3.2.1"
|
|
50
60
|
},
|
|
51
61
|
"devDependencies": {
|
|
52
|
-
"@backstage/backend-test-utils": "^0.1.
|
|
53
|
-
"@backstage/cli": "^0.22.
|
|
62
|
+
"@backstage/backend-test-utils": "^0.1.35-next.0",
|
|
63
|
+
"@backstage/cli": "^0.22.4-next.0",
|
|
54
64
|
"@types/lodash": "^4.14.151",
|
|
55
65
|
"@types/uuid": "^8.0.0",
|
|
56
66
|
"luxon": "^3.0.0",
|
|
57
67
|
"msw": "^0.49.0"
|
|
58
68
|
},
|
|
59
69
|
"files": [
|
|
60
|
-
"alpha",
|
|
61
70
|
"config.d.ts",
|
|
62
|
-
"dist"
|
|
71
|
+
"dist",
|
|
72
|
+
"alpha"
|
|
63
73
|
],
|
|
64
74
|
"configSchema": "config.d.ts"
|
|
65
75
|
}
|
package/dist/index.alpha.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A Backstage catalog backend module that helps integrate towards GitLab
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { BackendFeature } from '@backstage/backend-plugin-api';
|
|
8
|
-
import { CatalogProcessor } from '@backstage/plugin-catalog-backend';
|
|
9
|
-
import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend';
|
|
10
|
-
import { Config } from '@backstage/config';
|
|
11
|
-
import { EntityProvider } from '@backstage/plugin-catalog-backend';
|
|
12
|
-
import { EntityProviderConnection } from '@backstage/plugin-catalog-backend';
|
|
13
|
-
import { LocationSpec } from '@backstage/plugin-catalog-backend';
|
|
14
|
-
import { Logger } from 'winston';
|
|
15
|
-
import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
|
16
|
-
import { TaskRunner } from '@backstage/backend-tasks';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Discovers entity definition files in the groups of a Gitlab instance.
|
|
20
|
-
* @public
|
|
21
|
-
*/
|
|
22
|
-
export declare class GitlabDiscoveryEntityProvider implements EntityProvider {
|
|
23
|
-
private readonly config;
|
|
24
|
-
private readonly integration;
|
|
25
|
-
private readonly logger;
|
|
26
|
-
private readonly scheduleFn;
|
|
27
|
-
private connection?;
|
|
28
|
-
static fromConfig(config: Config, options: {
|
|
29
|
-
logger: Logger;
|
|
30
|
-
schedule?: TaskRunner;
|
|
31
|
-
scheduler?: PluginTaskScheduler;
|
|
32
|
-
}): GitlabDiscoveryEntityProvider[];
|
|
33
|
-
private constructor();
|
|
34
|
-
getProviderName(): string;
|
|
35
|
-
connect(connection: EntityProviderConnection): Promise<void>;
|
|
36
|
-
private createScheduleFn;
|
|
37
|
-
refresh(logger: Logger): Promise<void>;
|
|
38
|
-
private createLocationSpec;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Registers the GitlabDiscoveryEntityProvider with the catalog processing extension point.
|
|
43
|
-
*
|
|
44
|
-
* @alpha
|
|
45
|
-
*/
|
|
46
|
-
export declare const gitlabDiscoveryEntityProviderCatalogModule: () => BackendFeature;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Extracts repositories out of an GitLab instance.
|
|
50
|
-
* @public
|
|
51
|
-
*/
|
|
52
|
-
export declare class GitLabDiscoveryProcessor implements CatalogProcessor {
|
|
53
|
-
private readonly integrations;
|
|
54
|
-
private readonly logger;
|
|
55
|
-
private readonly cache;
|
|
56
|
-
private readonly skipReposWithoutExactFileMatch;
|
|
57
|
-
static fromConfig(config: Config, options: {
|
|
58
|
-
logger: Logger;
|
|
59
|
-
skipReposWithoutExactFileMatch?: boolean;
|
|
60
|
-
}): GitLabDiscoveryProcessor;
|
|
61
|
-
private constructor();
|
|
62
|
-
getProcessorName(): string;
|
|
63
|
-
readLocation(location: LocationSpec, _optional: boolean, emit: CatalogProcessorEmit): Promise<boolean>;
|
|
64
|
-
private getCacheKey;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Discovers users and groups from a Gitlab instance.
|
|
69
|
-
* @public
|
|
70
|
-
*/
|
|
71
|
-
export declare class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
|
72
|
-
private readonly config;
|
|
73
|
-
private readonly integration;
|
|
74
|
-
private readonly logger;
|
|
75
|
-
private readonly scheduleFn;
|
|
76
|
-
private connection?;
|
|
77
|
-
static fromConfig(config: Config, options: {
|
|
78
|
-
logger: Logger;
|
|
79
|
-
schedule?: TaskRunner;
|
|
80
|
-
scheduler?: PluginTaskScheduler;
|
|
81
|
-
}): GitlabOrgDiscoveryEntityProvider[];
|
|
82
|
-
private constructor();
|
|
83
|
-
getProviderName(): string;
|
|
84
|
-
connect(connection: EntityProviderConnection): Promise<void>;
|
|
85
|
-
private createScheduleFn;
|
|
86
|
-
private refresh;
|
|
87
|
-
private createGroupEntities;
|
|
88
|
-
private withLocations;
|
|
89
|
-
private createUserEntity;
|
|
90
|
-
private createGroupEntity;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { }
|
package/dist/index.beta.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A Backstage catalog backend module that helps integrate towards GitLab
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { BackendFeature } from '@backstage/backend-plugin-api';
|
|
8
|
-
import { CatalogProcessor } from '@backstage/plugin-catalog-backend';
|
|
9
|
-
import { CatalogProcessorEmit } from '@backstage/plugin-catalog-backend';
|
|
10
|
-
import { Config } from '@backstage/config';
|
|
11
|
-
import { EntityProvider } from '@backstage/plugin-catalog-backend';
|
|
12
|
-
import { EntityProviderConnection } from '@backstage/plugin-catalog-backend';
|
|
13
|
-
import { LocationSpec } from '@backstage/plugin-catalog-backend';
|
|
14
|
-
import { Logger } from 'winston';
|
|
15
|
-
import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
|
16
|
-
import { TaskRunner } from '@backstage/backend-tasks';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Discovers entity definition files in the groups of a Gitlab instance.
|
|
20
|
-
* @public
|
|
21
|
-
*/
|
|
22
|
-
export declare class GitlabDiscoveryEntityProvider implements EntityProvider {
|
|
23
|
-
private readonly config;
|
|
24
|
-
private readonly integration;
|
|
25
|
-
private readonly logger;
|
|
26
|
-
private readonly scheduleFn;
|
|
27
|
-
private connection?;
|
|
28
|
-
static fromConfig(config: Config, options: {
|
|
29
|
-
logger: Logger;
|
|
30
|
-
schedule?: TaskRunner;
|
|
31
|
-
scheduler?: PluginTaskScheduler;
|
|
32
|
-
}): GitlabDiscoveryEntityProvider[];
|
|
33
|
-
private constructor();
|
|
34
|
-
getProviderName(): string;
|
|
35
|
-
connect(connection: EntityProviderConnection): Promise<void>;
|
|
36
|
-
private createScheduleFn;
|
|
37
|
-
refresh(logger: Logger): Promise<void>;
|
|
38
|
-
private createLocationSpec;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/* Excluded from this release type: gitlabDiscoveryEntityProviderCatalogModule */
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Extracts repositories out of an GitLab instance.
|
|
45
|
-
* @public
|
|
46
|
-
*/
|
|
47
|
-
export declare class GitLabDiscoveryProcessor implements CatalogProcessor {
|
|
48
|
-
private readonly integrations;
|
|
49
|
-
private readonly logger;
|
|
50
|
-
private readonly cache;
|
|
51
|
-
private readonly skipReposWithoutExactFileMatch;
|
|
52
|
-
static fromConfig(config: Config, options: {
|
|
53
|
-
logger: Logger;
|
|
54
|
-
skipReposWithoutExactFileMatch?: boolean;
|
|
55
|
-
}): GitLabDiscoveryProcessor;
|
|
56
|
-
private constructor();
|
|
57
|
-
getProcessorName(): string;
|
|
58
|
-
readLocation(location: LocationSpec, _optional: boolean, emit: CatalogProcessorEmit): Promise<boolean>;
|
|
59
|
-
private getCacheKey;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Discovers users and groups from a Gitlab instance.
|
|
64
|
-
* @public
|
|
65
|
-
*/
|
|
66
|
-
export declare class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
|
67
|
-
private readonly config;
|
|
68
|
-
private readonly integration;
|
|
69
|
-
private readonly logger;
|
|
70
|
-
private readonly scheduleFn;
|
|
71
|
-
private connection?;
|
|
72
|
-
static fromConfig(config: Config, options: {
|
|
73
|
-
logger: Logger;
|
|
74
|
-
schedule?: TaskRunner;
|
|
75
|
-
scheduler?: PluginTaskScheduler;
|
|
76
|
-
}): GitlabOrgDiscoveryEntityProvider[];
|
|
77
|
-
private constructor();
|
|
78
|
-
getProviderName(): string;
|
|
79
|
-
connect(connection: EntityProviderConnection): Promise<void>;
|
|
80
|
-
private createScheduleFn;
|
|
81
|
-
private refresh;
|
|
82
|
-
private createGroupEntities;
|
|
83
|
-
private withLocations;
|
|
84
|
-
private createUserEntity;
|
|
85
|
-
private createGroupEntity;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { }
|