@backstage/plugin-catalog-backend-module-bitbucket-server 0.1.7 → 0.1.8-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 +32 -0
- package/alpha/package.json +3 -3
- package/dist/alpha.cjs.js +312 -0
- package/dist/alpha.cjs.js.map +1 -0
- package/dist/alpha.d.ts +8 -0
- package/dist/index.cjs.js +0 -27
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +55 -70
- package/package.json +32 -22
- package/dist/index.alpha.d.ts +0 -147
- package/dist/index.beta.d.ts +0 -144
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-bitbucket-server
|
|
2
2
|
|
|
3
|
+
## 0.1.8-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 52b0022dab7: Updated dependency `msw` to `^1.0.0`.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/errors@1.1.5-next.0
|
|
10
|
+
- @backstage/backend-common@0.18.3-next.1
|
|
11
|
+
- @backstage/integration@1.4.3-next.0
|
|
12
|
+
- @backstage/plugin-catalog-backend@1.8.0-next.1
|
|
13
|
+
- @backstage/backend-plugin-api@0.4.1-next.1
|
|
14
|
+
- @backstage/backend-tasks@0.4.4-next.1
|
|
15
|
+
- @backstage/config@1.0.7-next.0
|
|
16
|
+
- @backstage/catalog-model@1.2.1-next.1
|
|
17
|
+
- @backstage/plugin-catalog-node@1.3.4-next.1
|
|
18
|
+
|
|
19
|
+
## 0.1.8-next.0
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- 928a12a9b3: Internal refactor of `/alpha` exports.
|
|
24
|
+
- Updated dependencies
|
|
25
|
+
- @backstage/plugin-catalog-backend@1.8.0-next.0
|
|
26
|
+
- @backstage/backend-tasks@0.4.4-next.0
|
|
27
|
+
- @backstage/backend-plugin-api@0.4.1-next.0
|
|
28
|
+
- @backstage/backend-common@0.18.3-next.0
|
|
29
|
+
- @backstage/catalog-model@1.2.1-next.0
|
|
30
|
+
- @backstage/plugin-catalog-node@1.3.4-next.0
|
|
31
|
+
- @backstage/config@1.0.6
|
|
32
|
+
- @backstage/errors@1.1.4
|
|
33
|
+
- @backstage/integration@1.4.2
|
|
34
|
+
|
|
3
35
|
## 0.1.7
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/alpha/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-backend-module-bitbucket-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"main": "../dist/
|
|
5
|
-
"types": "../dist/
|
|
3
|
+
"version": "0.1.8-next.1",
|
|
4
|
+
"main": "../dist/alpha.cjs.js",
|
|
5
|
+
"types": "../dist/alpha.d.ts"
|
|
6
6
|
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var backendCommon = require('@backstage/backend-common');
|
|
6
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
7
|
+
var alpha = require('@backstage/plugin-catalog-node/alpha');
|
|
8
|
+
var errors = require('@backstage/errors');
|
|
9
|
+
var integration = require('@backstage/integration');
|
|
10
|
+
var uuid = require('uuid');
|
|
11
|
+
var fetch = require('node-fetch');
|
|
12
|
+
var backendTasks = require('@backstage/backend-tasks');
|
|
13
|
+
var pluginCatalogBackend = require('@backstage/plugin-catalog-backend');
|
|
14
|
+
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
function _interopNamespace(e) {
|
|
18
|
+
if (e && e.__esModule) return e;
|
|
19
|
+
var n = Object.create(null);
|
|
20
|
+
if (e) {
|
|
21
|
+
Object.keys(e).forEach(function (k) {
|
|
22
|
+
if (k !== 'default') {
|
|
23
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return e[k]; }
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
n["default"] = e;
|
|
32
|
+
return Object.freeze(n);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
|
|
36
|
+
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
37
|
+
|
|
38
|
+
class BitbucketServerClient {
|
|
39
|
+
static fromConfig(options) {
|
|
40
|
+
return new BitbucketServerClient(options);
|
|
41
|
+
}
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.config = options.config;
|
|
44
|
+
}
|
|
45
|
+
async listProjects(options) {
|
|
46
|
+
return this.pagedRequest(
|
|
47
|
+
`${this.config.apiBaseUrl}/projects`,
|
|
48
|
+
options.listOptions
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
async listRepositories(options) {
|
|
52
|
+
return this.pagedRequest(
|
|
53
|
+
`${this.config.apiBaseUrl}/projects/${encodeURIComponent(
|
|
54
|
+
options.projectKey
|
|
55
|
+
)}/repos`,
|
|
56
|
+
options.listOptions
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
async getFile(options) {
|
|
60
|
+
const base = new URL(this.config.apiBaseUrl);
|
|
61
|
+
return fetch__default["default"](
|
|
62
|
+
`${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,
|
|
63
|
+
integration.getBitbucketServerRequestOptions(this.config)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
async getRepository(options) {
|
|
67
|
+
const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;
|
|
68
|
+
const response = await fetch__default["default"](
|
|
69
|
+
request,
|
|
70
|
+
integration.getBitbucketServerRequestOptions(this.config)
|
|
71
|
+
);
|
|
72
|
+
return response.json();
|
|
73
|
+
}
|
|
74
|
+
resolvePath(options) {
|
|
75
|
+
const base = new URL(this.config.apiBaseUrl || "");
|
|
76
|
+
return {
|
|
77
|
+
path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async pagedRequest(endpoint, options) {
|
|
81
|
+
const request = new URL(endpoint);
|
|
82
|
+
for (const key in options) {
|
|
83
|
+
if (options[key]) {
|
|
84
|
+
request.searchParams.append(key, options[key].toString());
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return this.getTypeMapped(request);
|
|
88
|
+
}
|
|
89
|
+
async getTypeMapped(url) {
|
|
90
|
+
return this.get(url).then((response) => {
|
|
91
|
+
return response.json();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async get(url) {
|
|
95
|
+
return this.request(new fetch.Request(url.toString(), { method: "GET" }));
|
|
96
|
+
}
|
|
97
|
+
async request(req) {
|
|
98
|
+
return fetch__default["default"](req, integration.getBitbucketServerRequestOptions(this.config)).then(
|
|
99
|
+
(response) => {
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
return response;
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function* paginated(request, options) {
|
|
111
|
+
const opts = options || { start: 0 };
|
|
112
|
+
let res;
|
|
113
|
+
do {
|
|
114
|
+
res = await request(opts);
|
|
115
|
+
opts.start = res.nextPageStart;
|
|
116
|
+
for (const item of res.values) {
|
|
117
|
+
yield item;
|
|
118
|
+
}
|
|
119
|
+
} while (!res.isLastPage);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const DEFAULT_CATALOG_PATH = "/catalog-info.yaml";
|
|
123
|
+
const DEFAULT_PROVIDER_ID = "default";
|
|
124
|
+
function readProviderConfigs(config) {
|
|
125
|
+
const providersConfig = config.getOptionalConfig(
|
|
126
|
+
"catalog.providers.bitbucketServer"
|
|
127
|
+
);
|
|
128
|
+
if (!providersConfig) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
if (providersConfig.has("host")) {
|
|
132
|
+
return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];
|
|
133
|
+
}
|
|
134
|
+
return providersConfig.keys().map((id) => {
|
|
135
|
+
const providerConfig = providersConfig.getConfig(id);
|
|
136
|
+
return readProviderConfig(id, providerConfig);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function readProviderConfig(id, config) {
|
|
140
|
+
var _a;
|
|
141
|
+
const host = config.getString("host");
|
|
142
|
+
const catalogPath = (_a = config.getOptionalString("catalogPath")) != null ? _a : DEFAULT_CATALOG_PATH;
|
|
143
|
+
const projectKeyPattern = config.getOptionalString("filters.projectKey");
|
|
144
|
+
const repoSlugPattern = config.getOptionalString("filters.repoSlug");
|
|
145
|
+
const schedule = config.has("schedule") ? backendTasks.readTaskScheduleDefinitionFromConfig(config.getConfig("schedule")) : void 0;
|
|
146
|
+
return {
|
|
147
|
+
id,
|
|
148
|
+
host,
|
|
149
|
+
catalogPath,
|
|
150
|
+
filters: {
|
|
151
|
+
projectKey: projectKeyPattern ? new RegExp(projectKeyPattern) : void 0,
|
|
152
|
+
repoSlug: repoSlugPattern ? new RegExp(repoSlugPattern) : void 0
|
|
153
|
+
},
|
|
154
|
+
schedule
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const defaultBitbucketServerLocationParser = async function* defaultBitbucketServerLocationParser2(options) {
|
|
159
|
+
yield pluginCatalogBackend.locationSpecToLocationEntity({ location: options.location });
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
class BitbucketServerEntityProvider {
|
|
163
|
+
static fromConfig(config, options) {
|
|
164
|
+
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
165
|
+
if (!options.schedule && !options.scheduler) {
|
|
166
|
+
throw new Error("Either schedule or scheduler must be provided.");
|
|
167
|
+
}
|
|
168
|
+
return readProviderConfigs(config).map((providerConfig) => {
|
|
169
|
+
var _a;
|
|
170
|
+
const integration = integrations.bitbucketServer.byHost(
|
|
171
|
+
providerConfig.host
|
|
172
|
+
);
|
|
173
|
+
if (!integration) {
|
|
174
|
+
throw new errors.InputError(
|
|
175
|
+
`No BitbucketServer integration found that matches host ${providerConfig.host}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
if (!options.schedule && !providerConfig.schedule) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`No schedule provided neither via code nor config for bitbucketServer-provider:${providerConfig.id}.`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
const taskRunner = (_a = options.schedule) != null ? _a : options.scheduler.createScheduledTaskRunner(providerConfig.schedule);
|
|
184
|
+
return new BitbucketServerEntityProvider(
|
|
185
|
+
providerConfig,
|
|
186
|
+
integration,
|
|
187
|
+
options.logger,
|
|
188
|
+
taskRunner,
|
|
189
|
+
options.parser
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
constructor(config, integration, logger, taskRunner, parser) {
|
|
194
|
+
this.integration = integration;
|
|
195
|
+
this.config = config;
|
|
196
|
+
this.parser = parser || defaultBitbucketServerLocationParser;
|
|
197
|
+
this.logger = logger.child({
|
|
198
|
+
target: this.getProviderName()
|
|
199
|
+
});
|
|
200
|
+
this.scheduleFn = this.createScheduleFn(taskRunner);
|
|
201
|
+
}
|
|
202
|
+
createScheduleFn(taskRunner) {
|
|
203
|
+
return async () => {
|
|
204
|
+
const taskId = `${this.getProviderName()}:refresh`;
|
|
205
|
+
return taskRunner.run({
|
|
206
|
+
id: taskId,
|
|
207
|
+
fn: async () => {
|
|
208
|
+
const logger = this.logger.child({
|
|
209
|
+
class: BitbucketServerEntityProvider.prototype.constructor.name,
|
|
210
|
+
taskId,
|
|
211
|
+
taskInstanceId: uuid__namespace.v4()
|
|
212
|
+
});
|
|
213
|
+
try {
|
|
214
|
+
await this.refresh(logger);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
logger.error(`${this.getProviderName()} refresh failed`, error);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
|
|
223
|
+
getProviderName() {
|
|
224
|
+
return `bitbucketServer-provider:${this.config.id}`;
|
|
225
|
+
}
|
|
226
|
+
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
|
|
227
|
+
async connect(connection) {
|
|
228
|
+
this.connection = connection;
|
|
229
|
+
await this.scheduleFn();
|
|
230
|
+
}
|
|
231
|
+
async refresh(logger) {
|
|
232
|
+
if (!this.connection) {
|
|
233
|
+
throw new Error("Not initialized");
|
|
234
|
+
}
|
|
235
|
+
logger.info("Discovering catalog files in Bitbucket Server repositories");
|
|
236
|
+
const entities = await this.findEntities();
|
|
237
|
+
await this.connection.applyMutation({
|
|
238
|
+
type: "full",
|
|
239
|
+
entities: entities.map((entity) => ({
|
|
240
|
+
locationKey: this.getProviderName(),
|
|
241
|
+
entity
|
|
242
|
+
}))
|
|
243
|
+
});
|
|
244
|
+
logger.info(
|
|
245
|
+
`Committed ${entities.length} entities for Bitbucket Server repositories`
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
async findEntities() {
|
|
249
|
+
var _a, _b, _c, _d;
|
|
250
|
+
const client = BitbucketServerClient.fromConfig({
|
|
251
|
+
config: this.integration.config
|
|
252
|
+
});
|
|
253
|
+
const projects = paginated(
|
|
254
|
+
(options) => client.listProjects({ listOptions: options })
|
|
255
|
+
);
|
|
256
|
+
const result = [];
|
|
257
|
+
for await (const project of projects) {
|
|
258
|
+
if (((_b = (_a = this.config) == null ? void 0 : _a.filters) == null ? void 0 : _b.projectKey) && !this.config.filters.projectKey.test(project.key)) {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const repositories = paginated(
|
|
262
|
+
(options) => client.listRepositories({
|
|
263
|
+
projectKey: project.key,
|
|
264
|
+
listOptions: options
|
|
265
|
+
})
|
|
266
|
+
);
|
|
267
|
+
for await (const repository of repositories) {
|
|
268
|
+
if (((_d = (_c = this.config) == null ? void 0 : _c.filters) == null ? void 0 : _d.repoSlug) && !this.config.filters.repoSlug.test(repository.slug)) {
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
for await (const entity of this.parser({
|
|
272
|
+
client,
|
|
273
|
+
logger: this.logger,
|
|
274
|
+
location: {
|
|
275
|
+
type: "url",
|
|
276
|
+
target: `${repository.links.self[0].href}${this.config.catalogPath}`,
|
|
277
|
+
presence: "optional"
|
|
278
|
+
}
|
|
279
|
+
})) {
|
|
280
|
+
result.push(entity);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const bitbucketServerEntityProviderCatalogModule = backendPluginApi.createBackendModule({
|
|
289
|
+
pluginId: "catalog",
|
|
290
|
+
moduleId: "bitbucketServerEntityProvider",
|
|
291
|
+
register(env) {
|
|
292
|
+
env.registerInit({
|
|
293
|
+
deps: {
|
|
294
|
+
catalog: alpha.catalogProcessingExtensionPoint,
|
|
295
|
+
config: backendPluginApi.coreServices.config,
|
|
296
|
+
logger: backendPluginApi.coreServices.logger,
|
|
297
|
+
scheduler: backendPluginApi.coreServices.scheduler
|
|
298
|
+
},
|
|
299
|
+
async init({ catalog, config, logger, scheduler }) {
|
|
300
|
+
const winstonLogger = backendCommon.loggerToWinstonLogger(logger);
|
|
301
|
+
const providers = BitbucketServerEntityProvider.fromConfig(config, {
|
|
302
|
+
logger: winstonLogger,
|
|
303
|
+
scheduler
|
|
304
|
+
});
|
|
305
|
+
catalog.addEntityProvider(providers);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
exports.bitbucketServerEntityProviderCatalogModule = bitbucketServerEntityProviderCatalogModule;
|
|
312
|
+
//# sourceMappingURL=alpha.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alpha.cjs.js","sources":["../src/lib/BitbucketServerClient.ts","../src/providers/BitbucketServerEntityProviderConfig.ts","../src/providers/BitbucketServerLocationParser.ts","../src/providers/BitbucketServerEntityProvider.ts","../src/service/BitbucketServerEntityProviderCatalogModule.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 fetch, { Request, Response } from 'node-fetch';\nimport {\n BitbucketServerIntegrationConfig,\n getBitbucketServerRequestOptions,\n} from '@backstage/integration';\nimport { BitbucketServerProject, BitbucketServerRepository } from './types';\n\n/**\n * A client for interacting with a Bitbucket Server instance\n *\n * @public\n */\nexport class BitbucketServerClient {\n private readonly config: BitbucketServerIntegrationConfig;\n\n static fromConfig(options: {\n config: BitbucketServerIntegrationConfig;\n }): BitbucketServerClient {\n return new BitbucketServerClient(options);\n }\n\n constructor(options: { config: BitbucketServerIntegrationConfig }) {\n this.config = options.config;\n }\n\n async listProjects(options: {\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerProject>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects`,\n options.listOptions,\n );\n }\n\n async listRepositories(options: {\n projectKey: string;\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerRepository>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects/${encodeURIComponent(\n options.projectKey,\n )}/repos`,\n options.listOptions,\n );\n }\n\n async getFile(options: {\n projectKey: string;\n repo: string;\n path: string;\n }): Promise<Response> {\n const base = new URL(this.config.apiBaseUrl);\n return fetch(\n `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,\n getBitbucketServerRequestOptions(this.config),\n );\n }\n\n async getRepository(options: {\n projectKey: string;\n repo: string;\n }): Promise<BitbucketServerRepository> {\n const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;\n const response = await fetch(\n request,\n getBitbucketServerRequestOptions(this.config),\n );\n return response.json();\n }\n\n resolvePath(options: { projectKey: string; repo: string; path: string }): {\n path: string;\n } {\n const base = new URL(this.config.apiBaseUrl || '');\n\n return {\n path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`,\n };\n }\n\n private async pagedRequest(\n endpoint: string,\n options?: BitbucketServerListOptions,\n ): Promise<BitbucketServerPagedResponse<any>> {\n const request = new URL(endpoint);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n return this.getTypeMapped(request);\n }\n\n private async getTypeMapped<T = any>(url: URL): Promise<T> {\n return this.get(url).then((response: Response) => {\n return response.json() as Promise<T>;\n });\n }\n\n private async get(url: URL): Promise<Response> {\n return this.request(new Request(url.toString(), { method: 'GET' }));\n }\n\n private async request(req: Request): Promise<Response> {\n return fetch(req, getBitbucketServerRequestOptions(this.config)).then(\n (response: Response) => {\n if (!response.ok) {\n throw new Error(\n `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`,\n );\n }\n return response;\n },\n );\n }\n}\n\n/**\n * @public\n */\nexport type BitbucketServerListOptions = {\n [key: string]: number | undefined;\n limit?: number | undefined;\n start?: number | undefined;\n};\n\n/**\n * @public\n */\nexport type BitbucketServerPagedResponse<T> = {\n size: number;\n limit: number;\n start: number;\n isLastPage: boolean;\n values: T[];\n nextPageStart: number;\n};\n\nexport async function* paginated(\n request: (\n options: BitbucketServerListOptions,\n ) => Promise<BitbucketServerPagedResponse<any>>,\n options?: BitbucketServerListOptions,\n) {\n const opts = options || { start: 0 };\n let res;\n do {\n res = await request(opts);\n opts.start = res.nextPageStart;\n for (const item of res.values) {\n yield item;\n }\n } while (!res.isLastPage);\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 readTaskScheduleDefinitionFromConfig,\n TaskScheduleDefinition,\n} from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\n\nconst DEFAULT_CATALOG_PATH = '/catalog-info.yaml';\nconst DEFAULT_PROVIDER_ID = 'default';\n\nexport type BitbucketServerEntityProviderConfig = {\n id: string;\n host: string;\n catalogPath: string;\n filters?: {\n projectKey?: RegExp;\n repoSlug?: RegExp;\n };\n schedule?: TaskScheduleDefinition;\n};\n\nexport function readProviderConfigs(\n config: Config,\n): BitbucketServerEntityProviderConfig[] {\n const providersConfig = config.getOptionalConfig(\n 'catalog.providers.bitbucketServer',\n );\n if (!providersConfig) {\n return [];\n }\n if (providersConfig.has('host')) {\n // simple/single config variant\n return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];\n }\n\n return providersConfig.keys().map(id => {\n const providerConfig = providersConfig.getConfig(id);\n\n return readProviderConfig(id, providerConfig);\n });\n}\n\nfunction readProviderConfig(\n id: string,\n config: Config,\n): BitbucketServerEntityProviderConfig {\n const host = config.getString('host');\n const catalogPath =\n config.getOptionalString('catalogPath') ?? DEFAULT_CATALOG_PATH;\n const projectKeyPattern = config.getOptionalString('filters.projectKey');\n const repoSlugPattern = config.getOptionalString('filters.repoSlug');\n\n const schedule = config.has('schedule')\n ? readTaskScheduleDefinitionFromConfig(config.getConfig('schedule'))\n : undefined;\n\n return {\n id,\n host,\n catalogPath,\n filters: {\n projectKey: projectKeyPattern ? new RegExp(projectKeyPattern) : undefined,\n repoSlug: repoSlugPattern ? new RegExp(repoSlugPattern) : undefined,\n },\n schedule,\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 LocationSpec,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-backend';\nimport { Entity } from '@backstage/catalog-model';\nimport { Logger } from 'winston';\nimport { BitbucketServerClient } from '../lib';\n\n/**\n * A custom callback that reacts to finding a location by yielding entities.\n * Can be used for custom location/repository parsing logic.\n *\n * @public\n */\nexport type BitbucketServerLocationParser = (options: {\n client: BitbucketServerClient;\n location: LocationSpec;\n logger: Logger;\n}) => AsyncIterable<Entity>;\n\nexport const defaultBitbucketServerLocationParser =\n async function* defaultBitbucketServerLocationParser(options: {\n location: LocationSpec;\n }) {\n yield locationSpecToLocationEntity({ location: options.location });\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 { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport { Entity } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\nimport {\n BitbucketServerIntegration,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-backend';\nimport { Logger } from 'winston';\nimport * as uuid from 'uuid';\nimport { BitbucketServerClient, paginated } from '../lib';\nimport {\n BitbucketServerEntityProviderConfig,\n readProviderConfigs,\n} from './BitbucketServerEntityProviderConfig';\nimport {\n BitbucketServerLocationParser,\n defaultBitbucketServerLocationParser,\n} from './BitbucketServerLocationParser';\n\n/**\n * Discovers catalog files located in Bitbucket Server.\n * The provider will search your Bitbucket Server instance and register catalog files matching the configured path\n * as Location entity and via following processing steps add all contained catalog entities.\n * This can be useful as an alternative to static locations or manually adding things to the catalog.\n *\n * @public\n */\nexport class BitbucketServerEntityProvider implements EntityProvider {\n private readonly integration: BitbucketServerIntegration;\n private readonly config: BitbucketServerEntityProviderConfig;\n private readonly parser: BitbucketServerLocationParser;\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 parser?: BitbucketServerLocationParser;\n schedule?: TaskRunner;\n scheduler?: PluginTaskScheduler;\n },\n ): BitbucketServerEntityProvider[] {\n const integrations = ScmIntegrations.fromConfig(config);\n\n if (!options.schedule && !options.scheduler) {\n throw new Error('Either schedule or scheduler must be provided.');\n }\n\n return readProviderConfigs(config).map(providerConfig => {\n const integration = integrations.bitbucketServer.byHost(\n providerConfig.host,\n );\n if (!integration) {\n throw new InputError(\n `No BitbucketServer 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 bitbucketServer-provider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n return new BitbucketServerEntityProvider(\n providerConfig,\n integration,\n options.logger,\n taskRunner,\n options.parser,\n );\n });\n }\n\n private constructor(\n config: BitbucketServerEntityProviderConfig,\n integration: BitbucketServerIntegration,\n logger: Logger,\n taskRunner: TaskRunner,\n parser?: BitbucketServerLocationParser,\n ) {\n this.integration = integration;\n this.config = config;\n this.parser = parser || defaultBitbucketServerLocationParser;\n this.logger = logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(taskRunner);\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: BitbucketServerEntityProvider.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 /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */\n getProviderName(): string {\n return `bitbucketServer-provider:${this.config.id}`;\n }\n\n /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n async refresh(logger: Logger) {\n if (!this.connection) {\n throw new Error('Not initialized');\n }\n\n logger.info('Discovering catalog files in Bitbucket Server repositories');\n\n const entities = await this.findEntities();\n\n await this.connection.applyMutation({\n type: 'full',\n entities: entities.map(entity => ({\n locationKey: this.getProviderName(),\n entity: entity,\n })),\n });\n\n logger.info(\n `Committed ${entities.length} entities for Bitbucket Server repositories`,\n );\n }\n\n private async findEntities(): Promise<Entity[]> {\n const client = BitbucketServerClient.fromConfig({\n config: this.integration.config,\n });\n const projects = paginated(options =>\n client.listProjects({ listOptions: options }),\n );\n const result: Entity[] = [];\n for await (const project of projects) {\n if (\n this.config?.filters?.projectKey &&\n !this.config.filters.projectKey.test(project.key)\n ) {\n continue;\n }\n const repositories = paginated(options =>\n client.listRepositories({\n projectKey: project.key,\n listOptions: options,\n }),\n );\n for await (const repository of repositories) {\n if (\n this.config?.filters?.repoSlug &&\n !this.config.filters.repoSlug.test(repository.slug)\n ) {\n continue;\n }\n for await (const entity of this.parser({\n client,\n logger: this.logger,\n location: {\n type: 'url',\n target: `${repository.links.self[0].href}${this.config.catalogPath}`,\n presence: 'optional',\n },\n })) {\n result.push(entity);\n }\n }\n }\n return result;\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 { loggerToWinstonLogger } from '@backstage/backend-common';\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\nimport { BitbucketServerEntityProvider } from '../providers';\n\n/**\n * @alpha\n */\nexport const bitbucketServerEntityProviderCatalogModule = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'bitbucketServerEntityProvider',\n register(env) {\n env.registerInit({\n deps: {\n catalog: catalogProcessingExtensionPoint,\n config: coreServices.config,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({ catalog, config, logger, scheduler }) {\n const winstonLogger = loggerToWinstonLogger(logger);\n const providers = BitbucketServerEntityProvider.fromConfig(config, {\n logger: winstonLogger,\n scheduler,\n });\n\n catalog.addEntityProvider(providers);\n },\n });\n },\n});\n"],"names":["fetch","getBitbucketServerRequestOptions","Request","readTaskScheduleDefinitionFromConfig","defaultBitbucketServerLocationParser","locationSpecToLocationEntity","ScmIntegrations","InputError","uuid","createBackendModule","catalogProcessingExtensionPoint","coreServices","loggerToWinstonLogger"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,MAAM,qBAAsB,CAAA;AAAA,EAGjC,OAAO,WAAW,OAEQ,EAAA;AACxB,IAAO,OAAA,IAAI,sBAAsB,OAAO,CAAA,CAAA;AAAA,GAC1C;AAAA,EAEA,YAAY,OAAuD,EAAA;AACjE,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AAAA,GACxB;AAAA,EAEA,MAAM,aAAa,OAE+C,EAAA;AAChE,IAAA,OAAO,IAAK,CAAA,YAAA;AAAA,MACV,CAAA,EAAG,KAAK,MAAO,CAAA,UAAA,CAAA,SAAA,CAAA;AAAA,MACf,OAAQ,CAAA,WAAA;AAAA,KACV,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,iBAAiB,OAG8C,EAAA;AACnE,IAAA,OAAO,IAAK,CAAA,YAAA;AAAA,MACV,CAAA,EAAG,IAAK,CAAA,MAAA,CAAO,UAAuB,CAAA,UAAA,EAAA,kBAAA;AAAA,QACpC,OAAQ,CAAA,UAAA;AAAA,OACV,CAAA,MAAA,CAAA;AAAA,MACA,OAAQ,CAAA,WAAA;AAAA,KACV,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,QAAQ,OAIQ,EAAA;AACpB,IAAA,MAAM,IAAO,GAAA,IAAI,GAAI,CAAA,IAAA,CAAK,OAAO,UAAU,CAAA,CAAA;AAC3C,IAAO,OAAAA,yBAAA;AAAA,MACL,CAAA,EAAG,KAAK,QAAa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AA,UAAA,CAAW,MAAQ,EAAA;AAAA,UACjE,MAAQ,EAAA,aAAA;AAAA,UACR,SAAA;AAAA,SACD,CAAA,CAAA;AAED,QAAA,OAAA,CAAQ,kBAAkB,SAAS,CAAA,CAAA;AAAA,OACrC;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
|
package/dist/alpha.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @alpha
|
|
5
|
+
*/
|
|
6
|
+
declare const bitbucketServerEntityProviderCatalogModule: () => _backstage_backend_plugin_api.BackendFeature;
|
|
7
|
+
|
|
8
|
+
export { bitbucketServerEntityProviderCatalogModule };
|
package/dist/index.cjs.js
CHANGED
|
@@ -8,9 +8,6 @@ var errors = require('@backstage/errors');
|
|
|
8
8
|
var uuid = require('uuid');
|
|
9
9
|
var backendTasks = require('@backstage/backend-tasks');
|
|
10
10
|
var pluginCatalogBackend = require('@backstage/plugin-catalog-backend');
|
|
11
|
-
var backendCommon = require('@backstage/backend-common');
|
|
12
|
-
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
13
|
-
var pluginCatalogNode = require('@backstage/plugin-catalog-node');
|
|
14
11
|
|
|
15
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
13
|
|
|
@@ -285,30 +282,6 @@ class BitbucketServerEntityProvider {
|
|
|
285
282
|
}
|
|
286
283
|
}
|
|
287
284
|
|
|
288
|
-
const bitbucketServerEntityProviderCatalogModule = backendPluginApi.createBackendModule({
|
|
289
|
-
pluginId: "catalog",
|
|
290
|
-
moduleId: "bitbucketServerEntityProvider",
|
|
291
|
-
register(env) {
|
|
292
|
-
env.registerInit({
|
|
293
|
-
deps: {
|
|
294
|
-
catalog: pluginCatalogNode.catalogProcessingExtensionPoint,
|
|
295
|
-
config: backendPluginApi.coreServices.config,
|
|
296
|
-
logger: backendPluginApi.coreServices.logger,
|
|
297
|
-
scheduler: backendPluginApi.coreServices.scheduler
|
|
298
|
-
},
|
|
299
|
-
async init({ catalog, config, logger, scheduler }) {
|
|
300
|
-
const winstonLogger = backendCommon.loggerToWinstonLogger(logger);
|
|
301
|
-
const providers = BitbucketServerEntityProvider.fromConfig(config, {
|
|
302
|
-
logger: winstonLogger,
|
|
303
|
-
scheduler
|
|
304
|
-
});
|
|
305
|
-
catalog.addEntityProvider(providers);
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
|
|
311
285
|
exports.BitbucketServerClient = BitbucketServerClient;
|
|
312
286
|
exports.BitbucketServerEntityProvider = BitbucketServerEntityProvider;
|
|
313
|
-
exports.bitbucketServerEntityProviderCatalogModule = bitbucketServerEntityProviderCatalogModule;
|
|
314
287
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/lib/BitbucketServerClient.ts","../src/providers/BitbucketServerEntityProviderConfig.ts","../src/providers/BitbucketServerLocationParser.ts","../src/providers/BitbucketServerEntityProvider.ts","../src/service/BitbucketServerEntityProviderCatalogModule.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 fetch, { Request, Response } from 'node-fetch';\nimport {\n BitbucketServerIntegrationConfig,\n getBitbucketServerRequestOptions,\n} from '@backstage/integration';\nimport { BitbucketServerProject, BitbucketServerRepository } from './types';\n\n/**\n * A client for interacting with a Bitbucket Server instance\n *\n * @public\n */\nexport class BitbucketServerClient {\n private readonly config: BitbucketServerIntegrationConfig;\n\n static fromConfig(options: {\n config: BitbucketServerIntegrationConfig;\n }): BitbucketServerClient {\n return new BitbucketServerClient(options);\n }\n\n constructor(options: { config: BitbucketServerIntegrationConfig }) {\n this.config = options.config;\n }\n\n async listProjects(options: {\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerProject>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects`,\n options.listOptions,\n );\n }\n\n async listRepositories(options: {\n projectKey: string;\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerRepository>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects/${encodeURIComponent(\n options.projectKey,\n )}/repos`,\n options.listOptions,\n );\n }\n\n async getFile(options: {\n projectKey: string;\n repo: string;\n path: string;\n }): Promise<Response> {\n const base = new URL(this.config.apiBaseUrl);\n return fetch(\n `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,\n getBitbucketServerRequestOptions(this.config),\n );\n }\n\n async getRepository(options: {\n projectKey: string;\n repo: string;\n }): Promise<BitbucketServerRepository> {\n const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;\n const response = await fetch(\n request,\n getBitbucketServerRequestOptions(this.config),\n );\n return response.json();\n }\n\n resolvePath(options: { projectKey: string; repo: string; path: string }): {\n path: string;\n } {\n const base = new URL(this.config.apiBaseUrl || '');\n\n return {\n path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`,\n };\n }\n\n private async pagedRequest(\n endpoint: string,\n options?: BitbucketServerListOptions,\n ): Promise<BitbucketServerPagedResponse<any>> {\n const request = new URL(endpoint);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n return this.getTypeMapped(request);\n }\n\n private async getTypeMapped<T = any>(url: URL): Promise<T> {\n return this.get(url).then((response: Response) => {\n return response.json() as Promise<T>;\n });\n }\n\n private async get(url: URL): Promise<Response> {\n return this.request(new Request(url.toString(), { method: 'GET' }));\n }\n\n private async request(req: Request): Promise<Response> {\n return fetch(req, getBitbucketServerRequestOptions(this.config)).then(\n (response: Response) => {\n if (!response.ok) {\n throw new Error(\n `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`,\n );\n }\n return response;\n },\n );\n }\n}\n\n/**\n * @public\n */\nexport type BitbucketServerListOptions = {\n [key: string]: number | undefined;\n limit?: number | undefined;\n start?: number | undefined;\n};\n\n/**\n * @public\n */\nexport type BitbucketServerPagedResponse<T> = {\n size: number;\n limit: number;\n start: number;\n isLastPage: boolean;\n values: T[];\n nextPageStart: number;\n};\n\nexport async function* paginated(\n request: (\n options: BitbucketServerListOptions,\n ) => Promise<BitbucketServerPagedResponse<any>>,\n options?: BitbucketServerListOptions,\n) {\n const opts = options || { start: 0 };\n let res;\n do {\n res = await request(opts);\n opts.start = res.nextPageStart;\n for (const item of res.values) {\n yield item;\n }\n } while (!res.isLastPage);\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 readTaskScheduleDefinitionFromConfig,\n TaskScheduleDefinition,\n} from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\n\nconst DEFAULT_CATALOG_PATH = '/catalog-info.yaml';\nconst DEFAULT_PROVIDER_ID = 'default';\n\nexport type BitbucketServerEntityProviderConfig = {\n id: string;\n host: string;\n catalogPath: string;\n filters?: {\n projectKey?: RegExp;\n repoSlug?: RegExp;\n };\n schedule?: TaskScheduleDefinition;\n};\n\nexport function readProviderConfigs(\n config: Config,\n): BitbucketServerEntityProviderConfig[] {\n const providersConfig = config.getOptionalConfig(\n 'catalog.providers.bitbucketServer',\n );\n if (!providersConfig) {\n return [];\n }\n if (providersConfig.has('host')) {\n // simple/single config variant\n return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];\n }\n\n return providersConfig.keys().map(id => {\n const providerConfig = providersConfig.getConfig(id);\n\n return readProviderConfig(id, providerConfig);\n });\n}\n\nfunction readProviderConfig(\n id: string,\n config: Config,\n): BitbucketServerEntityProviderConfig {\n const host = config.getString('host');\n const catalogPath =\n config.getOptionalString('catalogPath') ?? DEFAULT_CATALOG_PATH;\n const projectKeyPattern = config.getOptionalString('filters.projectKey');\n const repoSlugPattern = config.getOptionalString('filters.repoSlug');\n\n const schedule = config.has('schedule')\n ? readTaskScheduleDefinitionFromConfig(config.getConfig('schedule'))\n : undefined;\n\n return {\n id,\n host,\n catalogPath,\n filters: {\n projectKey: projectKeyPattern ? new RegExp(projectKeyPattern) : undefined,\n repoSlug: repoSlugPattern ? new RegExp(repoSlugPattern) : undefined,\n },\n schedule,\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 LocationSpec,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-backend';\nimport { Entity } from '@backstage/catalog-model';\nimport { Logger } from 'winston';\nimport { BitbucketServerClient } from '../lib';\n\n/**\n * A custom callback that reacts to finding a location by yielding entities.\n * Can be used for custom location/repository parsing logic.\n *\n * @public\n */\nexport type BitbucketServerLocationParser = (options: {\n client: BitbucketServerClient;\n location: LocationSpec;\n logger: Logger;\n}) => AsyncIterable<Entity>;\n\nexport const defaultBitbucketServerLocationParser =\n async function* defaultBitbucketServerLocationParser(options: {\n location: LocationSpec;\n }) {\n yield locationSpecToLocationEntity({ location: options.location });\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 { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport { Entity } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\nimport {\n BitbucketServerIntegration,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-backend';\nimport { Logger } from 'winston';\nimport * as uuid from 'uuid';\nimport { BitbucketServerClient, paginated } from '../lib';\nimport {\n BitbucketServerEntityProviderConfig,\n readProviderConfigs,\n} from './BitbucketServerEntityProviderConfig';\nimport {\n BitbucketServerLocationParser,\n defaultBitbucketServerLocationParser,\n} from './BitbucketServerLocationParser';\n\n/**\n * Discovers catalog files located in Bitbucket Server.\n * The provider will search your Bitbucket Server instance and register catalog files matching the configured path\n * as Location entity and via following processing steps add all contained catalog entities.\n * This can be useful as an alternative to static locations or manually adding things to the catalog.\n *\n * @public\n */\nexport class BitbucketServerEntityProvider implements EntityProvider {\n private readonly integration: BitbucketServerIntegration;\n private readonly config: BitbucketServerEntityProviderConfig;\n private readonly parser: BitbucketServerLocationParser;\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 parser?: BitbucketServerLocationParser;\n schedule?: TaskRunner;\n scheduler?: PluginTaskScheduler;\n },\n ): BitbucketServerEntityProvider[] {\n const integrations = ScmIntegrations.fromConfig(config);\n\n if (!options.schedule && !options.scheduler) {\n throw new Error('Either schedule or scheduler must be provided.');\n }\n\n return readProviderConfigs(config).map(providerConfig => {\n const integration = integrations.bitbucketServer.byHost(\n providerConfig.host,\n );\n if (!integration) {\n throw new InputError(\n `No BitbucketServer 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 bitbucketServer-provider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n return new BitbucketServerEntityProvider(\n providerConfig,\n integration,\n options.logger,\n taskRunner,\n options.parser,\n );\n });\n }\n\n private constructor(\n config: BitbucketServerEntityProviderConfig,\n integration: BitbucketServerIntegration,\n logger: Logger,\n taskRunner: TaskRunner,\n parser?: BitbucketServerLocationParser,\n ) {\n this.integration = integration;\n this.config = config;\n this.parser = parser || defaultBitbucketServerLocationParser;\n this.logger = logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(taskRunner);\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: BitbucketServerEntityProvider.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 /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */\n getProviderName(): string {\n return `bitbucketServer-provider:${this.config.id}`;\n }\n\n /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n async refresh(logger: Logger) {\n if (!this.connection) {\n throw new Error('Not initialized');\n }\n\n logger.info('Discovering catalog files in Bitbucket Server repositories');\n\n const entities = await this.findEntities();\n\n await this.connection.applyMutation({\n type: 'full',\n entities: entities.map(entity => ({\n locationKey: this.getProviderName(),\n entity: entity,\n })),\n });\n\n logger.info(\n `Committed ${entities.length} entities for Bitbucket Server repositories`,\n );\n }\n\n private async findEntities(): Promise<Entity[]> {\n const client = BitbucketServerClient.fromConfig({\n config: this.integration.config,\n });\n const projects = paginated(options =>\n client.listProjects({ listOptions: options }),\n );\n const result: Entity[] = [];\n for await (const project of projects) {\n if (\n this.config?.filters?.projectKey &&\n !this.config.filters.projectKey.test(project.key)\n ) {\n continue;\n }\n const repositories = paginated(options =>\n client.listRepositories({\n projectKey: project.key,\n listOptions: options,\n }),\n );\n for await (const repository of repositories) {\n if (\n this.config?.filters?.repoSlug &&\n !this.config.filters.repoSlug.test(repository.slug)\n ) {\n continue;\n }\n for await (const entity of this.parser({\n client,\n logger: this.logger,\n location: {\n type: 'url',\n target: `${repository.links.self[0].href}${this.config.catalogPath}`,\n presence: 'optional',\n },\n })) {\n result.push(entity);\n }\n }\n }\n return result;\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 { loggerToWinstonLogger } from '@backstage/backend-common';\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node';\nimport { BitbucketServerEntityProvider } from '../providers';\n\n/**\n * @alpha\n */\nexport const bitbucketServerEntityProviderCatalogModule = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'bitbucketServerEntityProvider',\n register(env) {\n env.registerInit({\n deps: {\n catalog: catalogProcessingExtensionPoint,\n config: coreServices.config,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({ catalog, config, logger, scheduler }) {\n const winstonLogger = loggerToWinstonLogger(logger);\n const providers = BitbucketServerEntityProvider.fromConfig(config, {\n logger: winstonLogger,\n scheduler,\n });\n\n catalog.addEntityProvider(providers);\n },\n });\n },\n});\n"],"names":["fetch","getBitbucketServerRequestOptions","Request","readTaskScheduleDefinitionFromConfig","defaultBitbucketServerLocationParser","locationSpecToLocationEntity","ScmIntegrations","InputError","uuid","createBackendModule","catalogProcessingExtensionPoint","coreServices","loggerToWinstonLogger"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,MAAM,qBAAsB,CAAA;AAAA,EAGjC,OAAO,WAAW,OAEQ,EAAA;AACxB,IAAO,OAAA,IAAI,sBAAsB,OAAO,CAAA,CAAA;AAAA,GAC1C;AAAA,EAEA,YAAY,OAAuD,EAAA;AACjE,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AAAA,GACxB;AAAA,EAEA,MAAM,aAAa,OAE+C,EAAA;AAChE,IAAA,OAAO,IAAK,CAAA,YAAA;AAAA,MACV,CAAA,EAAG,KAAK,MAAO,CAAA,UAAA,CAAA,SAAA,CAAA;AAAA,MACf,OAAQ,CAAA,WAAA;AAAA,KACV,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,iBAAiB,OAG8C,EAAA;AACnE,IAAA,OAAO,IAAK,CAAA,YAAA;AAAA,MACV,CAAA,EAAG,IAAK,CAAA,MAAA,CAAO,UAAuB,CAAA,UAAA,E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iDAAA;AAAA,QACT,QAAQC,6BAAa,CAAA,MAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,OAC1B;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,SAAS,MAAQ,EAAA,MAAA,EAAQ,WAAa,EAAA;AACjD,QAAM,MAAA,aAAA,GAAgBC,oCAAsB,MAAM,CAAA,CAAA;AAClD,QAAM,MAAA,SAAA,GAAY,6BAA8B,CAAA,UAAA,CAAW,MAAQ,EAAA;AAAA,UACjE,MAAQ,EAAA,aAAA;AAAA,UACR,SAAA;AAAA,SACD,CAAA,CAAA;AAED,QAAA,OAAA,CAAQ,kBAAkB,SAAS,CAAA,CAAA;AAAA,OACrC;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/lib/BitbucketServerClient.ts","../src/providers/BitbucketServerEntityProviderConfig.ts","../src/providers/BitbucketServerLocationParser.ts","../src/providers/BitbucketServerEntityProvider.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 fetch, { Request, Response } from 'node-fetch';\nimport {\n BitbucketServerIntegrationConfig,\n getBitbucketServerRequestOptions,\n} from '@backstage/integration';\nimport { BitbucketServerProject, BitbucketServerRepository } from './types';\n\n/**\n * A client for interacting with a Bitbucket Server instance\n *\n * @public\n */\nexport class BitbucketServerClient {\n private readonly config: BitbucketServerIntegrationConfig;\n\n static fromConfig(options: {\n config: BitbucketServerIntegrationConfig;\n }): BitbucketServerClient {\n return new BitbucketServerClient(options);\n }\n\n constructor(options: { config: BitbucketServerIntegrationConfig }) {\n this.config = options.config;\n }\n\n async listProjects(options: {\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerProject>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects`,\n options.listOptions,\n );\n }\n\n async listRepositories(options: {\n projectKey: string;\n listOptions?: BitbucketServerListOptions;\n }): Promise<BitbucketServerPagedResponse<BitbucketServerRepository>> {\n return this.pagedRequest(\n `${this.config.apiBaseUrl}/projects/${encodeURIComponent(\n options.projectKey,\n )}/repos`,\n options.listOptions,\n );\n }\n\n async getFile(options: {\n projectKey: string;\n repo: string;\n path: string;\n }): Promise<Response> {\n const base = new URL(this.config.apiBaseUrl);\n return fetch(\n `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,\n getBitbucketServerRequestOptions(this.config),\n );\n }\n\n async getRepository(options: {\n projectKey: string;\n repo: string;\n }): Promise<BitbucketServerRepository> {\n const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;\n const response = await fetch(\n request,\n getBitbucketServerRequestOptions(this.config),\n );\n return response.json();\n }\n\n resolvePath(options: { projectKey: string; repo: string; path: string }): {\n path: string;\n } {\n const base = new URL(this.config.apiBaseUrl || '');\n\n return {\n path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`,\n };\n }\n\n private async pagedRequest(\n endpoint: string,\n options?: BitbucketServerListOptions,\n ): Promise<BitbucketServerPagedResponse<any>> {\n const request = new URL(endpoint);\n for (const key in options) {\n if (options[key]) {\n request.searchParams.append(key, options[key]!.toString());\n }\n }\n return this.getTypeMapped(request);\n }\n\n private async getTypeMapped<T = any>(url: URL): Promise<T> {\n return this.get(url).then((response: Response) => {\n return response.json() as Promise<T>;\n });\n }\n\n private async get(url: URL): Promise<Response> {\n return this.request(new Request(url.toString(), { method: 'GET' }));\n }\n\n private async request(req: Request): Promise<Response> {\n return fetch(req, getBitbucketServerRequestOptions(this.config)).then(\n (response: Response) => {\n if (!response.ok) {\n throw new Error(\n `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`,\n );\n }\n return response;\n },\n );\n }\n}\n\n/**\n * @public\n */\nexport type BitbucketServerListOptions = {\n [key: string]: number | undefined;\n limit?: number | undefined;\n start?: number | undefined;\n};\n\n/**\n * @public\n */\nexport type BitbucketServerPagedResponse<T> = {\n size: number;\n limit: number;\n start: number;\n isLastPage: boolean;\n values: T[];\n nextPageStart: number;\n};\n\nexport async function* paginated(\n request: (\n options: BitbucketServerListOptions,\n ) => Promise<BitbucketServerPagedResponse<any>>,\n options?: BitbucketServerListOptions,\n) {\n const opts = options || { start: 0 };\n let res;\n do {\n res = await request(opts);\n opts.start = res.nextPageStart;\n for (const item of res.values) {\n yield item;\n }\n } while (!res.isLastPage);\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 readTaskScheduleDefinitionFromConfig,\n TaskScheduleDefinition,\n} from '@backstage/backend-tasks';\nimport { Config } from '@backstage/config';\n\nconst DEFAULT_CATALOG_PATH = '/catalog-info.yaml';\nconst DEFAULT_PROVIDER_ID = 'default';\n\nexport type BitbucketServerEntityProviderConfig = {\n id: string;\n host: string;\n catalogPath: string;\n filters?: {\n projectKey?: RegExp;\n repoSlug?: RegExp;\n };\n schedule?: TaskScheduleDefinition;\n};\n\nexport function readProviderConfigs(\n config: Config,\n): BitbucketServerEntityProviderConfig[] {\n const providersConfig = config.getOptionalConfig(\n 'catalog.providers.bitbucketServer',\n );\n if (!providersConfig) {\n return [];\n }\n if (providersConfig.has('host')) {\n // simple/single config variant\n return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];\n }\n\n return providersConfig.keys().map(id => {\n const providerConfig = providersConfig.getConfig(id);\n\n return readProviderConfig(id, providerConfig);\n });\n}\n\nfunction readProviderConfig(\n id: string,\n config: Config,\n): BitbucketServerEntityProviderConfig {\n const host = config.getString('host');\n const catalogPath =\n config.getOptionalString('catalogPath') ?? DEFAULT_CATALOG_PATH;\n const projectKeyPattern = config.getOptionalString('filters.projectKey');\n const repoSlugPattern = config.getOptionalString('filters.repoSlug');\n\n const schedule = config.has('schedule')\n ? readTaskScheduleDefinitionFromConfig(config.getConfig('schedule'))\n : undefined;\n\n return {\n id,\n host,\n catalogPath,\n filters: {\n projectKey: projectKeyPattern ? new RegExp(projectKeyPattern) : undefined,\n repoSlug: repoSlugPattern ? new RegExp(repoSlugPattern) : undefined,\n },\n schedule,\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 LocationSpec,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-backend';\nimport { Entity } from '@backstage/catalog-model';\nimport { Logger } from 'winston';\nimport { BitbucketServerClient } from '../lib';\n\n/**\n * A custom callback that reacts to finding a location by yielding entities.\n * Can be used for custom location/repository parsing logic.\n *\n * @public\n */\nexport type BitbucketServerLocationParser = (options: {\n client: BitbucketServerClient;\n location: LocationSpec;\n logger: Logger;\n}) => AsyncIterable<Entity>;\n\nexport const defaultBitbucketServerLocationParser =\n async function* defaultBitbucketServerLocationParser(options: {\n location: LocationSpec;\n }) {\n yield locationSpecToLocationEntity({ location: options.location });\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 { PluginTaskScheduler, TaskRunner } from '@backstage/backend-tasks';\nimport { Entity } from '@backstage/catalog-model';\nimport { Config } from '@backstage/config';\nimport { InputError } from '@backstage/errors';\nimport {\n BitbucketServerIntegration,\n ScmIntegrations,\n} from '@backstage/integration';\nimport {\n EntityProvider,\n EntityProviderConnection,\n} from '@backstage/plugin-catalog-backend';\nimport { Logger } from 'winston';\nimport * as uuid from 'uuid';\nimport { BitbucketServerClient, paginated } from '../lib';\nimport {\n BitbucketServerEntityProviderConfig,\n readProviderConfigs,\n} from './BitbucketServerEntityProviderConfig';\nimport {\n BitbucketServerLocationParser,\n defaultBitbucketServerLocationParser,\n} from './BitbucketServerLocationParser';\n\n/**\n * Discovers catalog files located in Bitbucket Server.\n * The provider will search your Bitbucket Server instance and register catalog files matching the configured path\n * as Location entity and via following processing steps add all contained catalog entities.\n * This can be useful as an alternative to static locations or manually adding things to the catalog.\n *\n * @public\n */\nexport class BitbucketServerEntityProvider implements EntityProvider {\n private readonly integration: BitbucketServerIntegration;\n private readonly config: BitbucketServerEntityProviderConfig;\n private readonly parser: BitbucketServerLocationParser;\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 parser?: BitbucketServerLocationParser;\n schedule?: TaskRunner;\n scheduler?: PluginTaskScheduler;\n },\n ): BitbucketServerEntityProvider[] {\n const integrations = ScmIntegrations.fromConfig(config);\n\n if (!options.schedule && !options.scheduler) {\n throw new Error('Either schedule or scheduler must be provided.');\n }\n\n return readProviderConfigs(config).map(providerConfig => {\n const integration = integrations.bitbucketServer.byHost(\n providerConfig.host,\n );\n if (!integration) {\n throw new InputError(\n `No BitbucketServer 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 bitbucketServer-provider:${providerConfig.id}.`,\n );\n }\n\n const taskRunner =\n options.schedule ??\n options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);\n\n return new BitbucketServerEntityProvider(\n providerConfig,\n integration,\n options.logger,\n taskRunner,\n options.parser,\n );\n });\n }\n\n private constructor(\n config: BitbucketServerEntityProviderConfig,\n integration: BitbucketServerIntegration,\n logger: Logger,\n taskRunner: TaskRunner,\n parser?: BitbucketServerLocationParser,\n ) {\n this.integration = integration;\n this.config = config;\n this.parser = parser || defaultBitbucketServerLocationParser;\n this.logger = logger.child({\n target: this.getProviderName(),\n });\n this.scheduleFn = this.createScheduleFn(taskRunner);\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: BitbucketServerEntityProvider.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 /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */\n getProviderName(): string {\n return `bitbucketServer-provider:${this.config.id}`;\n }\n\n /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */\n async connect(connection: EntityProviderConnection): Promise<void> {\n this.connection = connection;\n await this.scheduleFn();\n }\n\n async refresh(logger: Logger) {\n if (!this.connection) {\n throw new Error('Not initialized');\n }\n\n logger.info('Discovering catalog files in Bitbucket Server repositories');\n\n const entities = await this.findEntities();\n\n await this.connection.applyMutation({\n type: 'full',\n entities: entities.map(entity => ({\n locationKey: this.getProviderName(),\n entity: entity,\n })),\n });\n\n logger.info(\n `Committed ${entities.length} entities for Bitbucket Server repositories`,\n );\n }\n\n private async findEntities(): Promise<Entity[]> {\n const client = BitbucketServerClient.fromConfig({\n config: this.integration.config,\n });\n const projects = paginated(options =>\n client.listProjects({ listOptions: options }),\n );\n const result: Entity[] = [];\n for await (const project of projects) {\n if (\n this.config?.filters?.projectKey &&\n !this.config.filters.projectKey.test(project.key)\n ) {\n continue;\n }\n const repositories = paginated(options =>\n client.listRepositories({\n projectKey: project.key,\n listOptions: options,\n }),\n );\n for await (const repository of repositories) {\n if (\n this.config?.filters?.repoSlug &&\n !this.config.filters.repoSlug.test(repository.slug)\n ) {\n continue;\n }\n for await (const entity of this.parser({\n client,\n logger: this.logger,\n location: {\n type: 'url',\n target: `${repository.links.self[0].href}${this.config.catalogPath}`,\n presence: 'optional',\n },\n })) {\n result.push(entity);\n }\n }\n }\n return result;\n }\n}\n"],"names":["fetch","getBitbucketServerRequestOptions","Request","readTaskScheduleDefinitionFromConfig","defaultBitbucketServerLocationParser","locationSpecToLocationEntity","ScmIntegrations","InputError","uuid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,MAAM,qBAAsB,CAAA;AAAA,EAGjC,OAAO,WAAW,OAEQ,EAAA;AACxB,IAAO,OAAA,IAAI,sBAAsB,OAAO,CAAA,CAAA;AAAA,GAC1C;AAAA,EAEA,YAAY,OAAuD,EAAA;AACjE,IAAA,IAAA,CAAK,SAAS,OAAQ,CAAA,MAAA,CAAA;AAAA,GACxB;AAAA,EAEA,MAAM,aAAa,OAE+C,EAAA;AAChE,IAAA,OAAO,IAAK,CAAA,YAAA;AAAA,MACV,CAAA,EAAG,KAAK,MAA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AAA;AAAA,GACT;AACF;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
* A Backstage catalog backend module that helps integrate towards Bitbucket Server
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { BackendFeature } from '@backstage/backend-plugin-api';
|
|
1
|
+
import { Response } from 'node-fetch';
|
|
8
2
|
import { BitbucketServerIntegrationConfig } from '@backstage/integration';
|
|
3
|
+
import { TaskRunner, PluginTaskScheduler } from '@backstage/backend-tasks';
|
|
9
4
|
import { Config } from '@backstage/config';
|
|
10
|
-
import {
|
|
11
|
-
import { EntityProvider } from '@backstage/plugin-catalog-backend';
|
|
12
|
-
import { EntityProviderConnection } from '@backstage/plugin-catalog-backend';
|
|
13
|
-
import { LocationSpec } from '@backstage/plugin-catalog-backend';
|
|
5
|
+
import { LocationSpec, EntityProvider, EntityProviderConnection } from '@backstage/plugin-catalog-backend';
|
|
14
6
|
import { Logger } from 'winston';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
import { Entity } from '@backstage/catalog-model';
|
|
8
|
+
|
|
9
|
+
/** @public */
|
|
10
|
+
declare type BitbucketServerRepository = {
|
|
11
|
+
project: {
|
|
12
|
+
key: string;
|
|
13
|
+
};
|
|
14
|
+
slug: string;
|
|
15
|
+
description: string;
|
|
16
|
+
links: Record<string, {
|
|
17
|
+
href: string;
|
|
18
|
+
}[]>;
|
|
19
|
+
};
|
|
20
|
+
/** @public */
|
|
21
|
+
declare type BitbucketServerProject = {
|
|
22
|
+
key: string;
|
|
23
|
+
};
|
|
18
24
|
|
|
19
25
|
/**
|
|
20
26
|
* A client for interacting with a Bitbucket Server instance
|
|
21
27
|
*
|
|
22
28
|
* @public
|
|
23
29
|
*/
|
|
24
|
-
|
|
30
|
+
declare class BitbucketServerClient {
|
|
25
31
|
private readonly config;
|
|
26
32
|
static fromConfig(options: {
|
|
27
33
|
config: BitbucketServerIntegrationConfig;
|
|
@@ -40,7 +46,7 @@ export declare class BitbucketServerClient {
|
|
|
40
46
|
projectKey: string;
|
|
41
47
|
repo: string;
|
|
42
48
|
path: string;
|
|
43
|
-
}): Promise<
|
|
49
|
+
}): Promise<Response>;
|
|
44
50
|
getRepository(options: {
|
|
45
51
|
projectKey: string;
|
|
46
52
|
repo: string;
|
|
@@ -57,6 +63,37 @@ export declare class BitbucketServerClient {
|
|
|
57
63
|
private get;
|
|
58
64
|
private request;
|
|
59
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
declare type BitbucketServerListOptions = {
|
|
70
|
+
[key: string]: number | undefined;
|
|
71
|
+
limit?: number | undefined;
|
|
72
|
+
start?: number | undefined;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
declare type BitbucketServerPagedResponse<T> = {
|
|
78
|
+
size: number;
|
|
79
|
+
limit: number;
|
|
80
|
+
start: number;
|
|
81
|
+
isLastPage: boolean;
|
|
82
|
+
values: T[];
|
|
83
|
+
nextPageStart: number;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A custom callback that reacts to finding a location by yielding entities.
|
|
88
|
+
* Can be used for custom location/repository parsing logic.
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
declare type BitbucketServerLocationParser = (options: {
|
|
93
|
+
client: BitbucketServerClient;
|
|
94
|
+
location: LocationSpec;
|
|
95
|
+
logger: Logger;
|
|
96
|
+
}) => AsyncIterable<Entity>;
|
|
60
97
|
|
|
61
98
|
/**
|
|
62
99
|
* Discovers catalog files located in Bitbucket Server.
|
|
@@ -66,7 +103,7 @@ export declare class BitbucketServerClient {
|
|
|
66
103
|
*
|
|
67
104
|
* @public
|
|
68
105
|
*/
|
|
69
|
-
|
|
106
|
+
declare class BitbucketServerEntityProvider implements EntityProvider {
|
|
70
107
|
private readonly integration;
|
|
71
108
|
private readonly config;
|
|
72
109
|
private readonly parser;
|
|
@@ -89,56 +126,4 @@ export declare class BitbucketServerEntityProvider implements EntityProvider {
|
|
|
89
126
|
private findEntities;
|
|
90
127
|
}
|
|
91
128
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @public
|
|
96
|
-
*/
|
|
97
|
-
export declare type BitbucketServerListOptions = {
|
|
98
|
-
[key: string]: number | undefined;
|
|
99
|
-
limit?: number | undefined;
|
|
100
|
-
start?: number | undefined;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* A custom callback that reacts to finding a location by yielding entities.
|
|
105
|
-
* Can be used for custom location/repository parsing logic.
|
|
106
|
-
*
|
|
107
|
-
* @public
|
|
108
|
-
*/
|
|
109
|
-
export declare type BitbucketServerLocationParser = (options: {
|
|
110
|
-
client: BitbucketServerClient;
|
|
111
|
-
location: LocationSpec;
|
|
112
|
-
logger: Logger;
|
|
113
|
-
}) => AsyncIterable<Entity>;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @public
|
|
117
|
-
*/
|
|
118
|
-
export declare type BitbucketServerPagedResponse<T> = {
|
|
119
|
-
size: number;
|
|
120
|
-
limit: number;
|
|
121
|
-
start: number;
|
|
122
|
-
isLastPage: boolean;
|
|
123
|
-
values: T[];
|
|
124
|
-
nextPageStart: number;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/** @public */
|
|
128
|
-
export declare type BitbucketServerProject = {
|
|
129
|
-
key: string;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/** @public */
|
|
133
|
-
export declare type BitbucketServerRepository = {
|
|
134
|
-
project: {
|
|
135
|
-
key: string;
|
|
136
|
-
};
|
|
137
|
-
slug: string;
|
|
138
|
-
description: string;
|
|
139
|
-
links: Record<string, {
|
|
140
|
-
href: string;
|
|
141
|
-
}[]>;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
export { }
|
|
129
|
+
export { BitbucketServerClient, BitbucketServerEntityProvider, BitbucketServerListOptions, BitbucketServerLocationParser, BitbucketServerPagedResponse, BitbucketServerProject, BitbucketServerRepository };
|
package/package.json
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-backend-module-bitbucket-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"main": "dist/index.cjs.js",
|
|
5
|
-
"types": "dist/index.d.ts",
|
|
3
|
+
"version": "0.1.8-next.1",
|
|
4
|
+
"main": "./dist/index.cjs.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"require": "./dist/index.cjs.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.cjs.js"
|
|
15
|
+
},
|
|
16
|
+
"./alpha": {
|
|
17
|
+
"require": "./dist/alpha.cjs.js",
|
|
18
|
+
"types": "./dist/alpha.d.ts",
|
|
19
|
+
"default": "./dist/alpha.cjs.js"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
12
22
|
},
|
|
13
23
|
"backstage": {
|
|
14
24
|
"role": "backend-plugin-module"
|
|
@@ -24,7 +34,7 @@
|
|
|
24
34
|
],
|
|
25
35
|
"scripts": {
|
|
26
36
|
"start": "backstage-cli package start",
|
|
27
|
-
"build": "backstage-cli package build
|
|
37
|
+
"build": "backstage-cli package build",
|
|
28
38
|
"lint": "backstage-cli package lint",
|
|
29
39
|
"test": "backstage-cli package test",
|
|
30
40
|
"prepack": "backstage-cli package prepack",
|
|
@@ -32,30 +42,30 @@
|
|
|
32
42
|
"clean": "backstage-cli package clean"
|
|
33
43
|
},
|
|
34
44
|
"dependencies": {
|
|
35
|
-
"@backstage/backend-common": "^0.18.
|
|
36
|
-
"@backstage/backend-plugin-api": "^0.4.
|
|
37
|
-
"@backstage/backend-tasks": "^0.4.
|
|
38
|
-
"@backstage/catalog-model": "^1.2.
|
|
39
|
-
"@backstage/config": "^1.0.
|
|
40
|
-
"@backstage/errors": "^1.1.
|
|
41
|
-
"@backstage/integration": "^1.4.
|
|
42
|
-
"@backstage/plugin-catalog-backend": "^1.
|
|
43
|
-
"@backstage/plugin-catalog-node": "^1.3.
|
|
45
|
+
"@backstage/backend-common": "^0.18.3-next.1",
|
|
46
|
+
"@backstage/backend-plugin-api": "^0.4.1-next.1",
|
|
47
|
+
"@backstage/backend-tasks": "^0.4.4-next.1",
|
|
48
|
+
"@backstage/catalog-model": "^1.2.1-next.1",
|
|
49
|
+
"@backstage/config": "^1.0.7-next.0",
|
|
50
|
+
"@backstage/errors": "^1.1.5-next.0",
|
|
51
|
+
"@backstage/integration": "^1.4.3-next.0",
|
|
52
|
+
"@backstage/plugin-catalog-backend": "^1.8.0-next.1",
|
|
53
|
+
"@backstage/plugin-catalog-node": "^1.3.4-next.1",
|
|
44
54
|
"@types/node-fetch": "^2.5.12",
|
|
45
55
|
"node-fetch": "^2.6.7",
|
|
46
56
|
"uuid": "^8.0.0",
|
|
47
57
|
"winston": "^3.2.1"
|
|
48
58
|
},
|
|
49
59
|
"devDependencies": {
|
|
50
|
-
"@backstage/backend-test-utils": "^0.1.
|
|
51
|
-
"@backstage/cli": "^0.22.
|
|
60
|
+
"@backstage/backend-test-utils": "^0.1.35-next.1",
|
|
61
|
+
"@backstage/cli": "^0.22.4-next.1",
|
|
52
62
|
"luxon": "^3.0.0",
|
|
53
|
-
"msw": "^0.
|
|
63
|
+
"msw": "^1.0.0"
|
|
54
64
|
},
|
|
55
65
|
"files": [
|
|
56
|
-
"alpha",
|
|
57
66
|
"config.d.ts",
|
|
58
|
-
"dist"
|
|
67
|
+
"dist",
|
|
68
|
+
"alpha"
|
|
59
69
|
],
|
|
60
70
|
"configSchema": "config.d.ts"
|
|
61
71
|
}
|
package/dist/index.alpha.d.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A Backstage catalog backend module that helps integrate towards Bitbucket Server
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { BackendFeature } from '@backstage/backend-plugin-api';
|
|
8
|
-
import { BitbucketServerIntegrationConfig } from '@backstage/integration';
|
|
9
|
-
import { Config } from '@backstage/config';
|
|
10
|
-
import { Entity } from '@backstage/catalog-model';
|
|
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 { Response as Response_2 } from 'node-fetch';
|
|
17
|
-
import { TaskRunner } from '@backstage/backend-tasks';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A client for interacting with a Bitbucket Server instance
|
|
21
|
-
*
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export declare class BitbucketServerClient {
|
|
25
|
-
private readonly config;
|
|
26
|
-
static fromConfig(options: {
|
|
27
|
-
config: BitbucketServerIntegrationConfig;
|
|
28
|
-
}): BitbucketServerClient;
|
|
29
|
-
constructor(options: {
|
|
30
|
-
config: BitbucketServerIntegrationConfig;
|
|
31
|
-
});
|
|
32
|
-
listProjects(options: {
|
|
33
|
-
listOptions?: BitbucketServerListOptions;
|
|
34
|
-
}): Promise<BitbucketServerPagedResponse<BitbucketServerProject>>;
|
|
35
|
-
listRepositories(options: {
|
|
36
|
-
projectKey: string;
|
|
37
|
-
listOptions?: BitbucketServerListOptions;
|
|
38
|
-
}): Promise<BitbucketServerPagedResponse<BitbucketServerRepository>>;
|
|
39
|
-
getFile(options: {
|
|
40
|
-
projectKey: string;
|
|
41
|
-
repo: string;
|
|
42
|
-
path: string;
|
|
43
|
-
}): Promise<Response_2>;
|
|
44
|
-
getRepository(options: {
|
|
45
|
-
projectKey: string;
|
|
46
|
-
repo: string;
|
|
47
|
-
}): Promise<BitbucketServerRepository>;
|
|
48
|
-
resolvePath(options: {
|
|
49
|
-
projectKey: string;
|
|
50
|
-
repo: string;
|
|
51
|
-
path: string;
|
|
52
|
-
}): {
|
|
53
|
-
path: string;
|
|
54
|
-
};
|
|
55
|
-
private pagedRequest;
|
|
56
|
-
private getTypeMapped;
|
|
57
|
-
private get;
|
|
58
|
-
private request;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Discovers catalog files located in Bitbucket Server.
|
|
63
|
-
* The provider will search your Bitbucket Server instance and register catalog files matching the configured path
|
|
64
|
-
* as Location entity and via following processing steps add all contained catalog entities.
|
|
65
|
-
* This can be useful as an alternative to static locations or manually adding things to the catalog.
|
|
66
|
-
*
|
|
67
|
-
* @public
|
|
68
|
-
*/
|
|
69
|
-
export declare class BitbucketServerEntityProvider implements EntityProvider {
|
|
70
|
-
private readonly integration;
|
|
71
|
-
private readonly config;
|
|
72
|
-
private readonly parser;
|
|
73
|
-
private readonly logger;
|
|
74
|
-
private readonly scheduleFn;
|
|
75
|
-
private connection?;
|
|
76
|
-
static fromConfig(config: Config, options: {
|
|
77
|
-
logger: Logger;
|
|
78
|
-
parser?: BitbucketServerLocationParser;
|
|
79
|
-
schedule?: TaskRunner;
|
|
80
|
-
scheduler?: PluginTaskScheduler;
|
|
81
|
-
}): BitbucketServerEntityProvider[];
|
|
82
|
-
private constructor();
|
|
83
|
-
private createScheduleFn;
|
|
84
|
-
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
|
|
85
|
-
getProviderName(): string;
|
|
86
|
-
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
|
|
87
|
-
connect(connection: EntityProviderConnection): Promise<void>;
|
|
88
|
-
refresh(logger: Logger): Promise<void>;
|
|
89
|
-
private findEntities;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @alpha
|
|
94
|
-
*/
|
|
95
|
-
export declare const bitbucketServerEntityProviderCatalogModule: () => BackendFeature;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @public
|
|
99
|
-
*/
|
|
100
|
-
export declare type BitbucketServerListOptions = {
|
|
101
|
-
[key: string]: number | undefined;
|
|
102
|
-
limit?: number | undefined;
|
|
103
|
-
start?: number | undefined;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* A custom callback that reacts to finding a location by yielding entities.
|
|
108
|
-
* Can be used for custom location/repository parsing logic.
|
|
109
|
-
*
|
|
110
|
-
* @public
|
|
111
|
-
*/
|
|
112
|
-
export declare type BitbucketServerLocationParser = (options: {
|
|
113
|
-
client: BitbucketServerClient;
|
|
114
|
-
location: LocationSpec;
|
|
115
|
-
logger: Logger;
|
|
116
|
-
}) => AsyncIterable<Entity>;
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* @public
|
|
120
|
-
*/
|
|
121
|
-
export declare type BitbucketServerPagedResponse<T> = {
|
|
122
|
-
size: number;
|
|
123
|
-
limit: number;
|
|
124
|
-
start: number;
|
|
125
|
-
isLastPage: boolean;
|
|
126
|
-
values: T[];
|
|
127
|
-
nextPageStart: number;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/** @public */
|
|
131
|
-
export declare type BitbucketServerProject = {
|
|
132
|
-
key: string;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
/** @public */
|
|
136
|
-
export declare type BitbucketServerRepository = {
|
|
137
|
-
project: {
|
|
138
|
-
key: string;
|
|
139
|
-
};
|
|
140
|
-
slug: string;
|
|
141
|
-
description: string;
|
|
142
|
-
links: Record<string, {
|
|
143
|
-
href: string;
|
|
144
|
-
}[]>;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export { }
|
package/dist/index.beta.d.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A Backstage catalog backend module that helps integrate towards Bitbucket Server
|
|
3
|
-
*
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { BackendFeature } from '@backstage/backend-plugin-api';
|
|
8
|
-
import { BitbucketServerIntegrationConfig } from '@backstage/integration';
|
|
9
|
-
import { Config } from '@backstage/config';
|
|
10
|
-
import { Entity } from '@backstage/catalog-model';
|
|
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 { Response as Response_2 } from 'node-fetch';
|
|
17
|
-
import { TaskRunner } from '@backstage/backend-tasks';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A client for interacting with a Bitbucket Server instance
|
|
21
|
-
*
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export declare class BitbucketServerClient {
|
|
25
|
-
private readonly config;
|
|
26
|
-
static fromConfig(options: {
|
|
27
|
-
config: BitbucketServerIntegrationConfig;
|
|
28
|
-
}): BitbucketServerClient;
|
|
29
|
-
constructor(options: {
|
|
30
|
-
config: BitbucketServerIntegrationConfig;
|
|
31
|
-
});
|
|
32
|
-
listProjects(options: {
|
|
33
|
-
listOptions?: BitbucketServerListOptions;
|
|
34
|
-
}): Promise<BitbucketServerPagedResponse<BitbucketServerProject>>;
|
|
35
|
-
listRepositories(options: {
|
|
36
|
-
projectKey: string;
|
|
37
|
-
listOptions?: BitbucketServerListOptions;
|
|
38
|
-
}): Promise<BitbucketServerPagedResponse<BitbucketServerRepository>>;
|
|
39
|
-
getFile(options: {
|
|
40
|
-
projectKey: string;
|
|
41
|
-
repo: string;
|
|
42
|
-
path: string;
|
|
43
|
-
}): Promise<Response_2>;
|
|
44
|
-
getRepository(options: {
|
|
45
|
-
projectKey: string;
|
|
46
|
-
repo: string;
|
|
47
|
-
}): Promise<BitbucketServerRepository>;
|
|
48
|
-
resolvePath(options: {
|
|
49
|
-
projectKey: string;
|
|
50
|
-
repo: string;
|
|
51
|
-
path: string;
|
|
52
|
-
}): {
|
|
53
|
-
path: string;
|
|
54
|
-
};
|
|
55
|
-
private pagedRequest;
|
|
56
|
-
private getTypeMapped;
|
|
57
|
-
private get;
|
|
58
|
-
private request;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Discovers catalog files located in Bitbucket Server.
|
|
63
|
-
* The provider will search your Bitbucket Server instance and register catalog files matching the configured path
|
|
64
|
-
* as Location entity and via following processing steps add all contained catalog entities.
|
|
65
|
-
* This can be useful as an alternative to static locations or manually adding things to the catalog.
|
|
66
|
-
*
|
|
67
|
-
* @public
|
|
68
|
-
*/
|
|
69
|
-
export declare class BitbucketServerEntityProvider implements EntityProvider {
|
|
70
|
-
private readonly integration;
|
|
71
|
-
private readonly config;
|
|
72
|
-
private readonly parser;
|
|
73
|
-
private readonly logger;
|
|
74
|
-
private readonly scheduleFn;
|
|
75
|
-
private connection?;
|
|
76
|
-
static fromConfig(config: Config, options: {
|
|
77
|
-
logger: Logger;
|
|
78
|
-
parser?: BitbucketServerLocationParser;
|
|
79
|
-
schedule?: TaskRunner;
|
|
80
|
-
scheduler?: PluginTaskScheduler;
|
|
81
|
-
}): BitbucketServerEntityProvider[];
|
|
82
|
-
private constructor();
|
|
83
|
-
private createScheduleFn;
|
|
84
|
-
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
|
|
85
|
-
getProviderName(): string;
|
|
86
|
-
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
|
|
87
|
-
connect(connection: EntityProviderConnection): Promise<void>;
|
|
88
|
-
refresh(logger: Logger): Promise<void>;
|
|
89
|
-
private findEntities;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/* Excluded from this release type: bitbucketServerEntityProviderCatalogModule */
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @public
|
|
96
|
-
*/
|
|
97
|
-
export declare type BitbucketServerListOptions = {
|
|
98
|
-
[key: string]: number | undefined;
|
|
99
|
-
limit?: number | undefined;
|
|
100
|
-
start?: number | undefined;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* A custom callback that reacts to finding a location by yielding entities.
|
|
105
|
-
* Can be used for custom location/repository parsing logic.
|
|
106
|
-
*
|
|
107
|
-
* @public
|
|
108
|
-
*/
|
|
109
|
-
export declare type BitbucketServerLocationParser = (options: {
|
|
110
|
-
client: BitbucketServerClient;
|
|
111
|
-
location: LocationSpec;
|
|
112
|
-
logger: Logger;
|
|
113
|
-
}) => AsyncIterable<Entity>;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @public
|
|
117
|
-
*/
|
|
118
|
-
export declare type BitbucketServerPagedResponse<T> = {
|
|
119
|
-
size: number;
|
|
120
|
-
limit: number;
|
|
121
|
-
start: number;
|
|
122
|
-
isLastPage: boolean;
|
|
123
|
-
values: T[];
|
|
124
|
-
nextPageStart: number;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/** @public */
|
|
128
|
-
export declare type BitbucketServerProject = {
|
|
129
|
-
key: string;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/** @public */
|
|
133
|
-
export declare type BitbucketServerRepository = {
|
|
134
|
-
project: {
|
|
135
|
-
key: string;
|
|
136
|
-
};
|
|
137
|
-
slug: string;
|
|
138
|
-
description: string;
|
|
139
|
-
links: Record<string, {
|
|
140
|
-
href: string;
|
|
141
|
-
}[]>;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
export { }
|