@backstage/plugin-catalog-backend-module-bitbucket-server 0.1.9-next.0 → 0.1.9-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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @backstage/plugin-catalog-backend-module-bitbucket-server
2
2
 
3
+ ## 0.1.9-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/plugin-catalog-node@1.3.5-next.1
16
+
3
17
  ## 0.1.9-next.0
4
18
 
5
19
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend-module-bitbucket-server",
3
- "version": "0.1.9-next.0",
3
+ "version": "0.1.9-next.1",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/alpha.cjs.js CHANGED
@@ -5,285 +5,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var backendCommon = require('@backstage/backend-common');
6
6
  var backendPluginApi = require('@backstage/backend-plugin-api');
7
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 pluginCatalogNode = require('@backstage/plugin-catalog-node');
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 pluginCatalogNode.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
- }
8
+ var BitbucketServerEntityProvider = require('./cjs/BitbucketServerEntityProvider-21f99836.cjs.js');
9
+ require('@backstage/errors');
10
+ require('@backstage/integration');
11
+ require('uuid');
12
+ require('node-fetch');
13
+ require('@backstage/backend-tasks');
14
+ require('@backstage/plugin-catalog-node');
287
15
 
288
16
  const catalogModuleBitbucketServerEntityProvider = backendPluginApi.createBackendModule({
289
17
  pluginId: "catalog",
@@ -298,7 +26,7 @@ const catalogModuleBitbucketServerEntityProvider = backendPluginApi.createBacken
298
26
  },
299
27
  async init({ catalog, config, logger, scheduler }) {
300
28
  const winstonLogger = backendCommon.loggerToWinstonLogger(logger);
301
- const providers = BitbucketServerEntityProvider.fromConfig(config, {
29
+ const providers = BitbucketServerEntityProvider.BitbucketServerEntityProvider.fromConfig(config, {
302
30
  logger: winstonLogger,
303
31
  scheduler
304
32
  });
@@ -1 +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/module/catalogModuleBitbucketServerEntityProvider.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-node';\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-node';\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 catalogModuleBitbucketServerEntityProvider = 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,CAAA,EAAA,EAAA,IAAA,C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A;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":"alpha.cjs.js","sources":["../src/module/catalogModuleBitbucketServerEntityProvider.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 { 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 catalogModuleBitbucketServerEntityProvider = 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":["createBackendModule","catalogProcessingExtensionPoint","coreServices","loggerToWinstonLogger","BitbucketServerEntityProvider"],"mappings":";;;;;;;;;;;;;;;AA2BO,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,OAAS,EAAAC,qCAAA;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,GAAYC,2DAA8B,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;;;;"}
@@ -0,0 +1,285 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+ var integration = require('@backstage/integration');
5
+ var uuid = require('uuid');
6
+ var fetch = require('node-fetch');
7
+ var backendTasks = require('@backstage/backend-tasks');
8
+ var pluginCatalogNode = require('@backstage/plugin-catalog-node');
9
+
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n["default"] = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
31
+ var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
32
+
33
+ class BitbucketServerClient {
34
+ static fromConfig(options) {
35
+ return new BitbucketServerClient(options);
36
+ }
37
+ constructor(options) {
38
+ this.config = options.config;
39
+ }
40
+ async listProjects(options) {
41
+ return this.pagedRequest(
42
+ `${this.config.apiBaseUrl}/projects`,
43
+ options.listOptions
44
+ );
45
+ }
46
+ async listRepositories(options) {
47
+ return this.pagedRequest(
48
+ `${this.config.apiBaseUrl}/projects/${encodeURIComponent(
49
+ options.projectKey
50
+ )}/repos`,
51
+ options.listOptions
52
+ );
53
+ }
54
+ async getFile(options) {
55
+ const base = new URL(this.config.apiBaseUrl);
56
+ return fetch__default["default"](
57
+ `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,
58
+ integration.getBitbucketServerRequestOptions(this.config)
59
+ );
60
+ }
61
+ async getRepository(options) {
62
+ const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;
63
+ const response = await fetch__default["default"](
64
+ request,
65
+ integration.getBitbucketServerRequestOptions(this.config)
66
+ );
67
+ return response.json();
68
+ }
69
+ resolvePath(options) {
70
+ const base = new URL(this.config.apiBaseUrl || "");
71
+ return {
72
+ path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`
73
+ };
74
+ }
75
+ async pagedRequest(endpoint, options) {
76
+ const request = new URL(endpoint);
77
+ for (const key in options) {
78
+ if (options[key]) {
79
+ request.searchParams.append(key, options[key].toString());
80
+ }
81
+ }
82
+ return this.getTypeMapped(request);
83
+ }
84
+ async getTypeMapped(url) {
85
+ return this.get(url).then((response) => {
86
+ return response.json();
87
+ });
88
+ }
89
+ async get(url) {
90
+ return this.request(new fetch.Request(url.toString(), { method: "GET" }));
91
+ }
92
+ async request(req) {
93
+ return fetch__default["default"](req, integration.getBitbucketServerRequestOptions(this.config)).then(
94
+ (response) => {
95
+ if (!response.ok) {
96
+ throw new Error(
97
+ `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`
98
+ );
99
+ }
100
+ return response;
101
+ }
102
+ );
103
+ }
104
+ }
105
+ async function* paginated(request, options) {
106
+ const opts = options || { start: 0 };
107
+ let res;
108
+ do {
109
+ res = await request(opts);
110
+ opts.start = res.nextPageStart;
111
+ for (const item of res.values) {
112
+ yield item;
113
+ }
114
+ } while (!res.isLastPage);
115
+ }
116
+
117
+ const DEFAULT_CATALOG_PATH = "/catalog-info.yaml";
118
+ const DEFAULT_PROVIDER_ID = "default";
119
+ function readProviderConfigs(config) {
120
+ const providersConfig = config.getOptionalConfig(
121
+ "catalog.providers.bitbucketServer"
122
+ );
123
+ if (!providersConfig) {
124
+ return [];
125
+ }
126
+ if (providersConfig.has("host")) {
127
+ return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];
128
+ }
129
+ return providersConfig.keys().map((id) => {
130
+ const providerConfig = providersConfig.getConfig(id);
131
+ return readProviderConfig(id, providerConfig);
132
+ });
133
+ }
134
+ function readProviderConfig(id, config) {
135
+ var _a;
136
+ const host = config.getString("host");
137
+ const catalogPath = (_a = config.getOptionalString("catalogPath")) != null ? _a : DEFAULT_CATALOG_PATH;
138
+ const projectKeyPattern = config.getOptionalString("filters.projectKey");
139
+ const repoSlugPattern = config.getOptionalString("filters.repoSlug");
140
+ const schedule = config.has("schedule") ? backendTasks.readTaskScheduleDefinitionFromConfig(config.getConfig("schedule")) : void 0;
141
+ return {
142
+ id,
143
+ host,
144
+ catalogPath,
145
+ filters: {
146
+ projectKey: projectKeyPattern ? new RegExp(projectKeyPattern) : void 0,
147
+ repoSlug: repoSlugPattern ? new RegExp(repoSlugPattern) : void 0
148
+ },
149
+ schedule
150
+ };
151
+ }
152
+
153
+ const defaultBitbucketServerLocationParser = async function* defaultBitbucketServerLocationParser2(options) {
154
+ yield pluginCatalogNode.locationSpecToLocationEntity({ location: options.location });
155
+ };
156
+
157
+ class BitbucketServerEntityProvider {
158
+ static fromConfig(config, options) {
159
+ const integrations = integration.ScmIntegrations.fromConfig(config);
160
+ if (!options.schedule && !options.scheduler) {
161
+ throw new Error("Either schedule or scheduler must be provided.");
162
+ }
163
+ return readProviderConfigs(config).map((providerConfig) => {
164
+ var _a;
165
+ const integration = integrations.bitbucketServer.byHost(
166
+ providerConfig.host
167
+ );
168
+ if (!integration) {
169
+ throw new errors.InputError(
170
+ `No BitbucketServer integration found that matches host ${providerConfig.host}`
171
+ );
172
+ }
173
+ if (!options.schedule && !providerConfig.schedule) {
174
+ throw new Error(
175
+ `No schedule provided neither via code nor config for bitbucketServer-provider:${providerConfig.id}.`
176
+ );
177
+ }
178
+ const taskRunner = (_a = options.schedule) != null ? _a : options.scheduler.createScheduledTaskRunner(providerConfig.schedule);
179
+ return new BitbucketServerEntityProvider(
180
+ providerConfig,
181
+ integration,
182
+ options.logger,
183
+ taskRunner,
184
+ options.parser
185
+ );
186
+ });
187
+ }
188
+ constructor(config, integration, logger, taskRunner, parser) {
189
+ this.integration = integration;
190
+ this.config = config;
191
+ this.parser = parser || defaultBitbucketServerLocationParser;
192
+ this.logger = logger.child({
193
+ target: this.getProviderName()
194
+ });
195
+ this.scheduleFn = this.createScheduleFn(taskRunner);
196
+ }
197
+ createScheduleFn(taskRunner) {
198
+ return async () => {
199
+ const taskId = `${this.getProviderName()}:refresh`;
200
+ return taskRunner.run({
201
+ id: taskId,
202
+ fn: async () => {
203
+ const logger = this.logger.child({
204
+ class: BitbucketServerEntityProvider.prototype.constructor.name,
205
+ taskId,
206
+ taskInstanceId: uuid__namespace.v4()
207
+ });
208
+ try {
209
+ await this.refresh(logger);
210
+ } catch (error) {
211
+ logger.error(`${this.getProviderName()} refresh failed`, error);
212
+ }
213
+ }
214
+ });
215
+ };
216
+ }
217
+ /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
218
+ getProviderName() {
219
+ return `bitbucketServer-provider:${this.config.id}`;
220
+ }
221
+ /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
222
+ async connect(connection) {
223
+ this.connection = connection;
224
+ await this.scheduleFn();
225
+ }
226
+ async refresh(logger) {
227
+ if (!this.connection) {
228
+ throw new Error("Not initialized");
229
+ }
230
+ logger.info("Discovering catalog files in Bitbucket Server repositories");
231
+ const entities = await this.findEntities();
232
+ await this.connection.applyMutation({
233
+ type: "full",
234
+ entities: entities.map((entity) => ({
235
+ locationKey: this.getProviderName(),
236
+ entity
237
+ }))
238
+ });
239
+ logger.info(
240
+ `Committed ${entities.length} entities for Bitbucket Server repositories`
241
+ );
242
+ }
243
+ async findEntities() {
244
+ var _a, _b, _c, _d;
245
+ const client = BitbucketServerClient.fromConfig({
246
+ config: this.integration.config
247
+ });
248
+ const projects = paginated(
249
+ (options) => client.listProjects({ listOptions: options })
250
+ );
251
+ const result = [];
252
+ for await (const project of projects) {
253
+ if (((_b = (_a = this.config) == null ? void 0 : _a.filters) == null ? void 0 : _b.projectKey) && !this.config.filters.projectKey.test(project.key)) {
254
+ continue;
255
+ }
256
+ const repositories = paginated(
257
+ (options) => client.listRepositories({
258
+ projectKey: project.key,
259
+ listOptions: options
260
+ })
261
+ );
262
+ for await (const repository of repositories) {
263
+ if (((_d = (_c = this.config) == null ? void 0 : _c.filters) == null ? void 0 : _d.repoSlug) && !this.config.filters.repoSlug.test(repository.slug)) {
264
+ continue;
265
+ }
266
+ for await (const entity of this.parser({
267
+ client,
268
+ logger: this.logger,
269
+ location: {
270
+ type: "url",
271
+ target: `${repository.links.self[0].href}${this.config.catalogPath}`,
272
+ presence: "optional"
273
+ }
274
+ })) {
275
+ result.push(entity);
276
+ }
277
+ }
278
+ }
279
+ return result;
280
+ }
281
+ }
282
+
283
+ exports.BitbucketServerClient = BitbucketServerClient;
284
+ exports.BitbucketServerEntityProvider = BitbucketServerEntityProvider;
285
+ //# sourceMappingURL=BitbucketServerEntityProvider-21f99836.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitbucketServerEntityProvider-21f99836.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-node';\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-node';\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,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;AAC3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A,IAAA,CAAA,CACE,EAAK,GAAA,CAAA,EAAA,GAAA,IAAA,CAAA,MAAA,KAAL,IAAa,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAA,KAAb,mBAAsB,QACtB,KAAA,CAAC,IAAK,CAAA,MAAA,CAAO,OAAQ,CAAA,QAAA,CAAS,IAAK,CAAA,UAAA,CAAW,IAAI,CAClD,EAAA;AACA,UAAA,SAAA;AAAA,SACF;AACA,QAAiB,WAAA,MAAA,MAAA,IAAU,KAAK,MAAO,CAAA;AAAA,UACrC,MAAA;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,UACb,QAAU,EAAA;AAAA,YACR,IAAM,EAAA,KAAA;AAAA,YACN,MAAA,EAAQ,GAAG,UAAW,CAAA,KAAA,CAAM,KAAK,CAAC,CAAA,CAAE,IAAO,CAAA,EAAA,IAAA,CAAK,MAAO,CAAA,WAAA,CAAA,CAAA;AAAA,YACvD,QAAU,EAAA,UAAA;AAAA,WACZ;AAAA,SACD,CAAG,EAAA;AACF,UAAA,MAAA,CAAO,KAAK,MAAM,CAAA,CAAA;AAAA,SACpB;AAAA,OACF;AAAA,KACF;AACA,IAAO,OAAA,MAAA,CAAA;AAAA,GACT;AACF;;;;;"}
package/dist/index.cjs.js CHANGED
@@ -2,286 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var fetch = require('node-fetch');
6
- var integration = require('@backstage/integration');
7
- var errors = require('@backstage/errors');
8
- var uuid = require('uuid');
9
- var backendTasks = require('@backstage/backend-tasks');
10
- var pluginCatalogNode = require('@backstage/plugin-catalog-node');
5
+ var BitbucketServerEntityProvider = require('./cjs/BitbucketServerEntityProvider-21f99836.cjs.js');
6
+ require('@backstage/errors');
7
+ require('@backstage/integration');
8
+ require('uuid');
9
+ require('node-fetch');
10
+ require('@backstage/backend-tasks');
11
+ require('@backstage/plugin-catalog-node');
11
12
 
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
13
 
14
- function _interopNamespace(e) {
15
- if (e && e.__esModule) return e;
16
- var n = Object.create(null);
17
- if (e) {
18
- Object.keys(e).forEach(function (k) {
19
- if (k !== 'default') {
20
- var d = Object.getOwnPropertyDescriptor(e, k);
21
- Object.defineProperty(n, k, d.get ? d : {
22
- enumerable: true,
23
- get: function () { return e[k]; }
24
- });
25
- }
26
- });
27
- }
28
- n["default"] = e;
29
- return Object.freeze(n);
30
- }
31
14
 
32
- var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
33
- var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
34
-
35
- class BitbucketServerClient {
36
- static fromConfig(options) {
37
- return new BitbucketServerClient(options);
38
- }
39
- constructor(options) {
40
- this.config = options.config;
41
- }
42
- async listProjects(options) {
43
- return this.pagedRequest(
44
- `${this.config.apiBaseUrl}/projects`,
45
- options.listOptions
46
- );
47
- }
48
- async listRepositories(options) {
49
- return this.pagedRequest(
50
- `${this.config.apiBaseUrl}/projects/${encodeURIComponent(
51
- options.projectKey
52
- )}/repos`,
53
- options.listOptions
54
- );
55
- }
56
- async getFile(options) {
57
- const base = new URL(this.config.apiBaseUrl);
58
- return fetch__default["default"](
59
- `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,
60
- integration.getBitbucketServerRequestOptions(this.config)
61
- );
62
- }
63
- async getRepository(options) {
64
- const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;
65
- const response = await fetch__default["default"](
66
- request,
67
- integration.getBitbucketServerRequestOptions(this.config)
68
- );
69
- return response.json();
70
- }
71
- resolvePath(options) {
72
- const base = new URL(this.config.apiBaseUrl || "");
73
- return {
74
- path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`
75
- };
76
- }
77
- async pagedRequest(endpoint, options) {
78
- const request = new URL(endpoint);
79
- for (const key in options) {
80
- if (options[key]) {
81
- request.searchParams.append(key, options[key].toString());
82
- }
83
- }
84
- return this.getTypeMapped(request);
85
- }
86
- async getTypeMapped(url) {
87
- return this.get(url).then((response) => {
88
- return response.json();
89
- });
90
- }
91
- async get(url) {
92
- return this.request(new fetch.Request(url.toString(), { method: "GET" }));
93
- }
94
- async request(req) {
95
- return fetch__default["default"](req, integration.getBitbucketServerRequestOptions(this.config)).then(
96
- (response) => {
97
- if (!response.ok) {
98
- throw new Error(
99
- `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`
100
- );
101
- }
102
- return response;
103
- }
104
- );
105
- }
106
- }
107
- async function* paginated(request, options) {
108
- const opts = options || { start: 0 };
109
- let res;
110
- do {
111
- res = await request(opts);
112
- opts.start = res.nextPageStart;
113
- for (const item of res.values) {
114
- yield item;
115
- }
116
- } while (!res.isLastPage);
117
- }
118
-
119
- const DEFAULT_CATALOG_PATH = "/catalog-info.yaml";
120
- const DEFAULT_PROVIDER_ID = "default";
121
- function readProviderConfigs(config) {
122
- const providersConfig = config.getOptionalConfig(
123
- "catalog.providers.bitbucketServer"
124
- );
125
- if (!providersConfig) {
126
- return [];
127
- }
128
- if (providersConfig.has("host")) {
129
- return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];
130
- }
131
- return providersConfig.keys().map((id) => {
132
- const providerConfig = providersConfig.getConfig(id);
133
- return readProviderConfig(id, providerConfig);
134
- });
135
- }
136
- function readProviderConfig(id, config) {
137
- var _a;
138
- const host = config.getString("host");
139
- const catalogPath = (_a = config.getOptionalString("catalogPath")) != null ? _a : DEFAULT_CATALOG_PATH;
140
- const projectKeyPattern = config.getOptionalString("filters.projectKey");
141
- const repoSlugPattern = config.getOptionalString("filters.repoSlug");
142
- const schedule = config.has("schedule") ? backendTasks.readTaskScheduleDefinitionFromConfig(config.getConfig("schedule")) : void 0;
143
- return {
144
- id,
145
- host,
146
- catalogPath,
147
- filters: {
148
- projectKey: projectKeyPattern ? new RegExp(projectKeyPattern) : void 0,
149
- repoSlug: repoSlugPattern ? new RegExp(repoSlugPattern) : void 0
150
- },
151
- schedule
152
- };
153
- }
154
-
155
- const defaultBitbucketServerLocationParser = async function* defaultBitbucketServerLocationParser2(options) {
156
- yield pluginCatalogNode.locationSpecToLocationEntity({ location: options.location });
157
- };
158
-
159
- class BitbucketServerEntityProvider {
160
- static fromConfig(config, options) {
161
- const integrations = integration.ScmIntegrations.fromConfig(config);
162
- if (!options.schedule && !options.scheduler) {
163
- throw new Error("Either schedule or scheduler must be provided.");
164
- }
165
- return readProviderConfigs(config).map((providerConfig) => {
166
- var _a;
167
- const integration = integrations.bitbucketServer.byHost(
168
- providerConfig.host
169
- );
170
- if (!integration) {
171
- throw new errors.InputError(
172
- `No BitbucketServer integration found that matches host ${providerConfig.host}`
173
- );
174
- }
175
- if (!options.schedule && !providerConfig.schedule) {
176
- throw new Error(
177
- `No schedule provided neither via code nor config for bitbucketServer-provider:${providerConfig.id}.`
178
- );
179
- }
180
- const taskRunner = (_a = options.schedule) != null ? _a : options.scheduler.createScheduledTaskRunner(providerConfig.schedule);
181
- return new BitbucketServerEntityProvider(
182
- providerConfig,
183
- integration,
184
- options.logger,
185
- taskRunner,
186
- options.parser
187
- );
188
- });
189
- }
190
- constructor(config, integration, logger, taskRunner, parser) {
191
- this.integration = integration;
192
- this.config = config;
193
- this.parser = parser || defaultBitbucketServerLocationParser;
194
- this.logger = logger.child({
195
- target: this.getProviderName()
196
- });
197
- this.scheduleFn = this.createScheduleFn(taskRunner);
198
- }
199
- createScheduleFn(taskRunner) {
200
- return async () => {
201
- const taskId = `${this.getProviderName()}:refresh`;
202
- return taskRunner.run({
203
- id: taskId,
204
- fn: async () => {
205
- const logger = this.logger.child({
206
- class: BitbucketServerEntityProvider.prototype.constructor.name,
207
- taskId,
208
- taskInstanceId: uuid__namespace.v4()
209
- });
210
- try {
211
- await this.refresh(logger);
212
- } catch (error) {
213
- logger.error(`${this.getProviderName()} refresh failed`, error);
214
- }
215
- }
216
- });
217
- };
218
- }
219
- /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
220
- getProviderName() {
221
- return `bitbucketServer-provider:${this.config.id}`;
222
- }
223
- /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
224
- async connect(connection) {
225
- this.connection = connection;
226
- await this.scheduleFn();
227
- }
228
- async refresh(logger) {
229
- if (!this.connection) {
230
- throw new Error("Not initialized");
231
- }
232
- logger.info("Discovering catalog files in Bitbucket Server repositories");
233
- const entities = await this.findEntities();
234
- await this.connection.applyMutation({
235
- type: "full",
236
- entities: entities.map((entity) => ({
237
- locationKey: this.getProviderName(),
238
- entity
239
- }))
240
- });
241
- logger.info(
242
- `Committed ${entities.length} entities for Bitbucket Server repositories`
243
- );
244
- }
245
- async findEntities() {
246
- var _a, _b, _c, _d;
247
- const client = BitbucketServerClient.fromConfig({
248
- config: this.integration.config
249
- });
250
- const projects = paginated(
251
- (options) => client.listProjects({ listOptions: options })
252
- );
253
- const result = [];
254
- for await (const project of projects) {
255
- if (((_b = (_a = this.config) == null ? void 0 : _a.filters) == null ? void 0 : _b.projectKey) && !this.config.filters.projectKey.test(project.key)) {
256
- continue;
257
- }
258
- const repositories = paginated(
259
- (options) => client.listRepositories({
260
- projectKey: project.key,
261
- listOptions: options
262
- })
263
- );
264
- for await (const repository of repositories) {
265
- if (((_d = (_c = this.config) == null ? void 0 : _c.filters) == null ? void 0 : _d.repoSlug) && !this.config.filters.repoSlug.test(repository.slug)) {
266
- continue;
267
- }
268
- for await (const entity of this.parser({
269
- client,
270
- logger: this.logger,
271
- location: {
272
- type: "url",
273
- target: `${repository.links.self[0].href}${this.config.catalogPath}`,
274
- presence: "optional"
275
- }
276
- })) {
277
- result.push(entity);
278
- }
279
- }
280
- }
281
- return result;
282
- }
283
- }
284
-
285
- exports.BitbucketServerClient = BitbucketServerClient;
286
- exports.BitbucketServerEntityProvider = BitbucketServerEntityProvider;
15
+ exports.BitbucketServerClient = BitbucketServerEntityProvider.BitbucketServerClient;
16
+ exports.BitbucketServerEntityProvider = BitbucketServerEntityProvider.BitbucketServerEntityProvider;
287
17
  //# sourceMappingURL=index.cjs.js.map
@@ -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"],"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-node';\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-node';\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,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,I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AAA;AACA,MAAA,WAAA,MAAiB,cAAc,YAAc,EAAA;AAC3C,QAAA,IAAA,CAAA,CACE,EAAK,GAAA,CAAA,EAAA,GAAA,IAAA,CAAA,MAAA,KAAL,IAAa,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAA,KAAb,mBAAsB,QACtB,KAAA,CAAC,IAAK,CAAA,MAAA,CAAO,OAAQ,CAAA,QAAA,CAAS,IAAK,CAAA,UAAA,CAAW,IAAI,CAClD,EAAA;AACA,UAAA,SAAA;AAAA,SACF;AACA,QAAiB,WAAA,MAAA,MAAA,IAAU,KAAK,MAAO,CAAA;AAAA,UACrC,MAAA;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,UACb,QAAU,EAAA;AAAA,YACR,IAAM,EAAA,KAAA;AAAA,YACN,MAAA,EAAQ,GAAG,UAAW,CAAA,KAAA,CAAM,KAAK,CAAC,CAAA,CAAE,IAAO,CAAA,EAAA,IAAA,CAAK,MAAO,CAAA,WAAA,CAAA,CAAA;AAAA,YACvD,QAAU,EAAA,UAAA;AAAA,WACZ;AAAA,SACD,CAAG,EAAA;AACF,UAAA,MAAA,CAAO,KAAK,MAAM,CAAA,CAAA;AAAA,SACpB;AAAA,OACF;AAAA,KACF;AACA,IAAO,OAAA,MAAA,CAAA;AAAA,GACT;AACF;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend-module-bitbucket-server",
3
- "version": "0.1.9-next.0",
3
+ "version": "0.1.9-next.1",
4
4
  "main": "./dist/index.cjs.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -42,22 +42,22 @@
42
42
  "clean": "backstage-cli package clean"
43
43
  },
44
44
  "dependencies": {
45
- "@backstage/backend-common": "^0.18.4-next.0",
46
- "@backstage/backend-plugin-api": "^0.5.1-next.0",
47
- "@backstage/backend-tasks": "^0.5.1-next.0",
45
+ "@backstage/backend-common": "^0.18.4-next.1",
46
+ "@backstage/backend-plugin-api": "^0.5.1-next.1",
47
+ "@backstage/backend-tasks": "^0.5.1-next.1",
48
48
  "@backstage/catalog-model": "^1.2.1",
49
49
  "@backstage/config": "^1.0.7",
50
50
  "@backstage/errors": "^1.1.5",
51
- "@backstage/integration": "^1.4.3",
52
- "@backstage/plugin-catalog-node": "^1.3.5-next.0",
51
+ "@backstage/integration": "^1.4.4-next.0",
52
+ "@backstage/plugin-catalog-node": "^1.3.5-next.1",
53
53
  "@types/node-fetch": "^2.5.12",
54
54
  "node-fetch": "^2.6.7",
55
55
  "uuid": "^8.0.0",
56
56
  "winston": "^3.2.1"
57
57
  },
58
58
  "devDependencies": {
59
- "@backstage/backend-test-utils": "^0.1.36-next.0",
60
- "@backstage/cli": "^0.22.6-next.0",
59
+ "@backstage/backend-test-utils": "^0.1.36-next.1",
60
+ "@backstage/cli": "^0.22.6-next.1",
61
61
  "luxon": "^3.0.0",
62
62
  "msw": "^1.0.0"
63
63
  },