@backstage/plugin-catalog-backend-module-gitlab 0.1.14 → 0.2.0-next.1
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 +44 -0
- package/alpha/package.json +1 -1
- package/dist/alpha.cjs.js +7 -349
- package/dist/alpha.cjs.js.map +1 -1
- package/dist/cjs/GitlabDiscoveryEntityProvider-1de558b0.cjs.js +366 -0
- package/dist/cjs/GitlabDiscoveryEntityProvider-1de558b0.cjs.js.map +1 -0
- package/dist/index.cjs.js +27 -354
- package/dist/index.cjs.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-gitlab
|
|
2
2
|
|
|
3
|
+
## 0.2.0-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/backend-tasks@0.5.1-next.1
|
|
9
|
+
- @backstage/integration@1.4.4-next.0
|
|
10
|
+
- @backstage/backend-common@0.18.4-next.1
|
|
11
|
+
- @backstage/backend-plugin-api@0.5.1-next.1
|
|
12
|
+
- @backstage/catalog-model@1.2.1
|
|
13
|
+
- @backstage/config@1.0.7
|
|
14
|
+
- @backstage/errors@1.1.5
|
|
15
|
+
- @backstage/types@1.0.2
|
|
16
|
+
- @backstage/plugin-catalog-node@1.3.5-next.1
|
|
17
|
+
|
|
18
|
+
## 0.2.0-next.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- f64345108a0: **BREAKING**: The configuration of the `GitlabDiscoveryEntityProvider` has changed as follows:
|
|
23
|
+
|
|
24
|
+
- The configuration key `branch` is now used to define the branch from which the catalog-info should be discovered.
|
|
25
|
+
- The old configuration key `branch` is now called `fallbackBranch`. This value specifies which branch should be used
|
|
26
|
+
if no default branch is defined on the project itself.
|
|
27
|
+
|
|
28
|
+
To migrate to the new configuration value, rename `branch` to `fallbackBranch`
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- 7b1b7bfdb7b: The gitlab org data integration now makes use of the GraphQL API to determine
|
|
33
|
+
the relationships between imported User and Group entities, effectively making
|
|
34
|
+
this integration usable without an administrator account's Personal Access
|
|
35
|
+
Token.
|
|
36
|
+
- Updated dependencies
|
|
37
|
+
- @backstage/backend-common@0.18.4-next.0
|
|
38
|
+
- @backstage/config@1.0.7
|
|
39
|
+
- @backstage/integration@1.4.3
|
|
40
|
+
- @backstage/backend-plugin-api@0.5.1-next.0
|
|
41
|
+
- @backstage/backend-tasks@0.5.1-next.0
|
|
42
|
+
- @backstage/catalog-model@1.2.1
|
|
43
|
+
- @backstage/errors@1.1.5
|
|
44
|
+
- @backstage/types@1.0.2
|
|
45
|
+
- @backstage/plugin-catalog-node@1.3.5-next.0
|
|
46
|
+
|
|
3
47
|
## 0.1.14
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
package/alpha/package.json
CHANGED
package/dist/alpha.cjs.js
CHANGED
|
@@ -5,356 +5,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
6
|
var backendCommon = require('@backstage/backend-common');
|
|
7
7
|
var alpha = require('@backstage/plugin-catalog-node/alpha');
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
var GitlabDiscoveryEntityProvider = require('./cjs/GitlabDiscoveryEntityProvider-1de558b0.cjs.js');
|
|
9
|
+
require('@backstage/integration');
|
|
10
|
+
require('uuid');
|
|
11
|
+
require('node-fetch');
|
|
12
|
+
require('@backstage/backend-tasks');
|
|
13
13
|
require('@backstage/catalog-model');
|
|
14
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, logger) {
|
|
171
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
172
|
-
const group = (_a = config.getOptionalString("group")) != null ? _a : "";
|
|
173
|
-
const host = config.getString("host");
|
|
174
|
-
const branch = config.getOptionalString("branch");
|
|
175
|
-
if (branch) {
|
|
176
|
-
logger.warn(
|
|
177
|
-
"The configuration key `branch` has been deprecated in favor of the configuration key `fallbackBranch`."
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
const fallbackBranch = (_c = (_b = config.getOptionalString("fallbackBranch")) != null ? _b : branch) != null ? _c : "master";
|
|
181
|
-
const catalogFile = (_d = config.getOptionalString("entityFilename")) != null ? _d : "catalog-info.yaml";
|
|
182
|
-
const projectPattern = new RegExp(
|
|
183
|
-
(_e = config.getOptionalString("projectPattern")) != null ? _e : /[\s\S]*/
|
|
184
|
-
);
|
|
185
|
-
const userPattern = new RegExp(
|
|
186
|
-
(_f = config.getOptionalString("userPattern")) != null ? _f : /[\s\S]*/
|
|
187
|
-
);
|
|
188
|
-
const groupPattern = new RegExp(
|
|
189
|
-
(_g = config.getOptionalString("groupPattern")) != null ? _g : /[\s\S]*/
|
|
190
|
-
);
|
|
191
|
-
const orgEnabled = (_h = config.getOptionalBoolean("orgEnabled")) != null ? _h : false;
|
|
192
|
-
const schedule = config.has("schedule") ? backendTasks.readTaskScheduleDefinitionFromConfig(config.getConfig("schedule")) : void 0;
|
|
193
|
-
return {
|
|
194
|
-
id,
|
|
195
|
-
group,
|
|
196
|
-
fallbackBranch,
|
|
197
|
-
host,
|
|
198
|
-
catalogFile,
|
|
199
|
-
projectPattern,
|
|
200
|
-
userPattern,
|
|
201
|
-
groupPattern,
|
|
202
|
-
schedule,
|
|
203
|
-
orgEnabled
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
function readGitlabConfigs(config, logger) {
|
|
207
|
-
const configs = [];
|
|
208
|
-
const providerConfigs = config.getOptionalConfig("catalog.providers.gitlab");
|
|
209
|
-
if (!providerConfigs) {
|
|
210
|
-
return configs;
|
|
211
|
-
}
|
|
212
|
-
for (const id of providerConfigs.keys()) {
|
|
213
|
-
configs.push(
|
|
214
|
-
readGitlabConfig(
|
|
215
|
-
id,
|
|
216
|
-
providerConfigs.getConfig(id),
|
|
217
|
-
logger.child({ target: id })
|
|
218
|
-
)
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
return configs;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
class GitlabDiscoveryEntityProvider {
|
|
225
|
-
static fromConfig(config, options) {
|
|
226
|
-
if (!options.schedule && !options.scheduler) {
|
|
227
|
-
throw new Error("Either schedule or scheduler must be provided.");
|
|
228
|
-
}
|
|
229
|
-
const providerConfigs = readGitlabConfigs(
|
|
230
|
-
config,
|
|
231
|
-
options.logger.child({ target: "GitlabDiscoveryEntityProvider" })
|
|
232
|
-
);
|
|
233
|
-
const integrations = integration.ScmIntegrations.fromConfig(config).gitlab;
|
|
234
|
-
const providers = [];
|
|
235
|
-
providerConfigs.forEach((providerConfig) => {
|
|
236
|
-
var _a;
|
|
237
|
-
const integration = integrations.byHost(providerConfig.host);
|
|
238
|
-
if (!integration) {
|
|
239
|
-
throw new Error(
|
|
240
|
-
`No gitlab integration found that matches host ${providerConfig.host}`
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
if (!options.schedule && !providerConfig.schedule) {
|
|
244
|
-
throw new Error(
|
|
245
|
-
`No schedule provided neither via code nor config for GitlabDiscoveryEntityProvider:${providerConfig.id}.`
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
const taskRunner = (_a = options.schedule) != null ? _a : options.scheduler.createScheduledTaskRunner(providerConfig.schedule);
|
|
249
|
-
providers.push(
|
|
250
|
-
new GitlabDiscoveryEntityProvider({
|
|
251
|
-
...options,
|
|
252
|
-
config: providerConfig,
|
|
253
|
-
integration,
|
|
254
|
-
taskRunner
|
|
255
|
-
})
|
|
256
|
-
);
|
|
257
|
-
});
|
|
258
|
-
return providers;
|
|
259
|
-
}
|
|
260
|
-
constructor(options) {
|
|
261
|
-
this.config = options.config;
|
|
262
|
-
this.integration = options.integration;
|
|
263
|
-
this.logger = options.logger.child({
|
|
264
|
-
target: this.getProviderName()
|
|
265
|
-
});
|
|
266
|
-
this.scheduleFn = this.createScheduleFn(options.taskRunner);
|
|
267
|
-
}
|
|
268
|
-
getProviderName() {
|
|
269
|
-
return `GitlabDiscoveryEntityProvider:${this.config.id}`;
|
|
270
|
-
}
|
|
271
|
-
async connect(connection) {
|
|
272
|
-
this.connection = connection;
|
|
273
|
-
await this.scheduleFn();
|
|
274
|
-
}
|
|
275
|
-
createScheduleFn(taskRunner) {
|
|
276
|
-
return async () => {
|
|
277
|
-
const taskId = `${this.getProviderName()}:refresh`;
|
|
278
|
-
return taskRunner.run({
|
|
279
|
-
id: taskId,
|
|
280
|
-
fn: async () => {
|
|
281
|
-
const logger = this.logger.child({
|
|
282
|
-
class: GitlabDiscoveryEntityProvider.prototype.constructor.name,
|
|
283
|
-
taskId,
|
|
284
|
-
taskInstanceId: uuid__namespace.v4()
|
|
285
|
-
});
|
|
286
|
-
try {
|
|
287
|
-
await this.refresh(logger);
|
|
288
|
-
} catch (error) {
|
|
289
|
-
logger.error(`${this.getProviderName()} refresh failed`, error);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
async refresh(logger) {
|
|
296
|
-
var _a, _b, _c;
|
|
297
|
-
if (!this.connection) {
|
|
298
|
-
throw new Error(
|
|
299
|
-
`Gitlab discovery connection not initialized for ${this.getProviderName()}`
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
const client = new GitLabClient({
|
|
303
|
-
config: this.integration.config,
|
|
304
|
-
logger
|
|
305
|
-
});
|
|
306
|
-
const projects = paginated(
|
|
307
|
-
(options) => client.listProjects(options),
|
|
308
|
-
{
|
|
309
|
-
group: this.config.group,
|
|
310
|
-
page: 1,
|
|
311
|
-
per_page: 50
|
|
312
|
-
}
|
|
313
|
-
);
|
|
314
|
-
const res = {
|
|
315
|
-
scanned: 0,
|
|
316
|
-
matches: []
|
|
317
|
-
};
|
|
318
|
-
for await (const project of projects) {
|
|
319
|
-
if (!this.config.projectPattern.test((_a = project.path_with_namespace) != null ? _a : "")) {
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
|
-
res.scanned++;
|
|
323
|
-
if (project.archived) {
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
if (this.config.fallbackBranch === "*" && project.default_branch === void 0) {
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
const project_branch = (_b = project.default_branch) != null ? _b : this.config.fallbackBranch;
|
|
330
|
-
const projectHasFile = await client.hasFile(
|
|
331
|
-
(_c = project.path_with_namespace) != null ? _c : "",
|
|
332
|
-
project_branch,
|
|
333
|
-
this.config.catalogFile
|
|
334
|
-
);
|
|
335
|
-
if (projectHasFile) {
|
|
336
|
-
res.matches.push(project);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
const locations = res.matches.map((p) => this.createLocationSpec(p));
|
|
340
|
-
await this.connection.applyMutation({
|
|
341
|
-
type: "full",
|
|
342
|
-
entities: locations.map((location) => ({
|
|
343
|
-
locationKey: this.getProviderName(),
|
|
344
|
-
entity: pluginCatalogNode.locationSpecToLocationEntity({ location })
|
|
345
|
-
}))
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
createLocationSpec(project) {
|
|
349
|
-
var _a;
|
|
350
|
-
const project_branch = (_a = project.default_branch) != null ? _a : this.config.fallbackBranch;
|
|
351
|
-
return {
|
|
352
|
-
type: "url",
|
|
353
|
-
target: `${project.web_url}/-/blob/${project_branch}/${this.config.catalogFile}`,
|
|
354
|
-
presence: "optional"
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
}
|
|
15
|
+
require('@backstage/plugin-catalog-node');
|
|
358
16
|
|
|
359
17
|
const catalogModuleGitlabDiscoveryEntityProvider = backendPluginApi.createBackendModule({
|
|
360
18
|
pluginId: "catalog",
|
|
@@ -369,7 +27,7 @@ const catalogModuleGitlabDiscoveryEntityProvider = backendPluginApi.createBacken
|
|
|
369
27
|
},
|
|
370
28
|
async init({ config, catalog, logger, scheduler }) {
|
|
371
29
|
catalog.addEntityProvider(
|
|
372
|
-
GitlabDiscoveryEntityProvider.fromConfig(config, {
|
|
30
|
+
GitlabDiscoveryEntityProvider.GitlabDiscoveryEntityProvider.fromConfig(config, {
|
|
373
31
|
logger: backendCommon.loggerToWinstonLogger(logger),
|
|
374
32
|
scheduler
|
|
375
33
|
})
|
package/dist/alpha.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alpha.cjs.js","sources":["../src/lib/client.ts","../src/providers/config.ts","../src/providers/GitlabDiscoveryEntityProvider.ts","../src/module/catalogModuleGitlabDiscoveryEntityProvider.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';\nimport { Logger } from 'winston';\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 * @param logger - The logger\n */\nfunction readGitlabConfig(\n id: string,\n config: Config,\n logger: Logger,\n): GitlabProviderConfig {\n const group = config.getOptionalString('group') ?? '';\n const host = config.getString('host');\n const branch = config.getOptionalString('branch');\n\n if (branch) {\n logger.warn(\n 'The configuration key `branch` has been deprecated in favor of the configuration key `fallbackBranch`.',\n );\n }\n\n const fallbackBranch =\n config.getOptionalString('fallbackBranch') ?? 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 fallbackBranch,\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 * @param logger - The logger\n */\nexport function readGitlabConfigs(\n config: Config,\n logger: Logger,\n): 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(\n readGitlabConfig(\n id,\n providerConfigs.getConfig(id),\n logger.child({ target: id }),\n ),\n );\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-node';\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(\n config,\n options.logger.child({ target: 'GitlabDiscoveryEntityProvider' }),\n );\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 (\n this.config.fallbackBranch === '*' &&\n project.default_branch === undefined\n ) {\n continue;\n }\n\n const project_branch =\n project.default_branch ?? this.config.fallbackBranch;\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.fallbackBranch;\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 catalogModuleGitlabDiscoveryEntityProvider = 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,M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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;;;;"}
|
|
1
|
+
{"version":3,"file":"alpha.cjs.js","sources":["../src/module/catalogModuleGitlabDiscoveryEntityProvider.ts"],"sourcesContent":["/*\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 catalogModuleGitlabDiscoveryEntityProvider = 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":["createBackendModule","coreServices","catalogProcessingExtensionPoint","GitlabDiscoveryEntityProvider","loggerToWinstonLogger"],"mappings":";;;;;;;;;;;;;;;;AA6BO,MAAM,6CAA6CA,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,UACNE,2DAAA,CAA8B,WAAW,MAAQ,EAAA;AAAA,YAC/C,MAAA,EAAQC,oCAAsB,MAAM,CAAA;AAAA,YACpC,SAAA;AAAA,WACD,CAAA;AAAA,SACH,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
|