@backstage/plugin-catalog-backend-module-bitbucket-server 0.2.3-next.1 → 0.2.3

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,30 @@
1
1
  # @backstage/plugin-catalog-backend-module-bitbucket-server
2
2
 
3
+ ## 0.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 3109c24: The export for the new backend system at the `/alpha` export is now also available via the main entry point, which means that you can remove the `/alpha` suffix from the import.
8
+ - Updated dependencies
9
+ - @backstage/plugin-catalog-node@1.13.1
10
+ - @backstage/integration@1.15.1
11
+ - @backstage/backend-plugin-api@1.0.1
12
+ - @backstage/catalog-model@1.7.0
13
+ - @backstage/config@1.2.0
14
+ - @backstage/errors@1.2.4
15
+
16
+ ## 0.2.3-next.2
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies
21
+ - @backstage/plugin-catalog-node@1.13.1-next.1
22
+ - @backstage/integration@1.15.1-next.1
23
+ - @backstage/backend-plugin-api@1.0.1-next.1
24
+ - @backstage/catalog-model@1.7.0
25
+ - @backstage/config@1.2.0
26
+ - @backstage/errors@1.2.4
27
+
3
28
  ## 0.2.3-next.1
4
29
 
5
30
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend-module-bitbucket-server__alpha",
3
- "version": "0.2.3-next.1",
3
+ "version": "0.2.3",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/alpha.cjs.js CHANGED
@@ -2,36 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var backendPluginApi = require('@backstage/backend-plugin-api');
6
- var alpha = require('@backstage/plugin-catalog-node/alpha');
7
- var BitbucketServerEntityProvider = require('./cjs/BitbucketServerEntityProvider-BefRa_fm.cjs.js');
8
- require('@backstage/errors');
9
- require('@backstage/integration');
10
- require('uuid');
11
- require('node-fetch');
12
- require('@backstage/plugin-catalog-node');
5
+ var catalogModuleBitbucketServerEntityProvider = require('./module/catalogModuleBitbucketServerEntityProvider.cjs.js');
13
6
 
14
- const catalogModuleBitbucketServerEntityProvider = backendPluginApi.createBackendModule({
15
- pluginId: "catalog",
16
- moduleId: "bitbucket-server-entity-provider",
17
- register(env) {
18
- env.registerInit({
19
- deps: {
20
- catalog: alpha.catalogProcessingExtensionPoint,
21
- config: backendPluginApi.coreServices.rootConfig,
22
- logger: backendPluginApi.coreServices.logger,
23
- scheduler: backendPluginApi.coreServices.scheduler
24
- },
25
- async init({ catalog, config, logger, scheduler }) {
26
- const providers = BitbucketServerEntityProvider.BitbucketServerEntityProvider.fromConfig(config, {
27
- logger,
28
- scheduler
29
- });
30
- catalog.addEntityProvider(providers);
31
- }
32
- });
33
- }
34
- });
7
+ const _feature = catalogModuleBitbucketServerEntityProvider.catalogModuleBitbucketServerEntityProvider;
35
8
 
36
- exports.default = catalogModuleBitbucketServerEntityProvider;
9
+ exports.default = _feature;
37
10
  //# sourceMappingURL=alpha.cjs.js.map
@@ -1 +1 @@
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 {\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: 'bitbucket-server-entity-provider',\n register(env) {\n env.registerInit({\n deps: {\n catalog: catalogProcessingExtensionPoint,\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({ catalog, config, logger, scheduler }) {\n const providers = BitbucketServerEntityProvider.fromConfig(config, {\n logger,\n scheduler,\n });\n\n catalog.addEntityProvider(providers);\n },\n });\n },\n});\n"],"names":["createBackendModule","catalogProcessingExtensionPoint","coreServices","BitbucketServerEntityProvider"],"mappings":";;;;;;;;;;;;;AA0BO,MAAM,6CAA6CA,oCAAoB,CAAA;AAAA,EAC5E,QAAU,EAAA,SAAA;AAAA,EACV,QAAU,EAAA,kCAAA;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,UAAA;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,SAAA,GAAYC,2DAA8B,CAAA,UAAA,CAAW,MAAQ,EAAA;AAAA,UACjE,MAAA;AAAA,UACA,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/alpha.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { default as feature } from './module';\n\n/** @alpha */\nconst _feature = feature;\nexport default _feature;\n"],"names":["feature"],"mappings":";;;;;;AAmBA,MAAM,QAAW,GAAAA;;;;"}
package/dist/alpha.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
2
 
3
- /**
4
- * @alpha
5
- */
6
- declare const catalogModuleBitbucketServerEntityProvider: _backstage_backend_plugin_api.BackendFeature;
3
+ /** @alpha */
4
+ declare const _feature: _backstage_backend_plugin_api.BackendFeature;
7
5
 
8
- export { catalogModuleBitbucketServerEntityProvider as default };
6
+ export { _feature as default };
package/dist/index.cjs.js CHANGED
@@ -1,15 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var BitbucketServerEntityProvider = require('./cjs/BitbucketServerEntityProvider-BefRa_fm.cjs.js');
4
- require('@backstage/errors');
5
- require('@backstage/integration');
6
- require('uuid');
7
- require('node-fetch');
8
- require('@backstage/backend-plugin-api');
9
- require('@backstage/plugin-catalog-node');
3
+ Object.defineProperty(exports, '__esModule', { value: true });
10
4
 
5
+ var catalogModuleBitbucketServerEntityProvider = require('./module/catalogModuleBitbucketServerEntityProvider.cjs.js');
6
+ var BitbucketServerClient = require('./lib/BitbucketServerClient.cjs.js');
7
+ var BitbucketServerEntityProvider = require('./providers/BitbucketServerEntityProvider.cjs.js');
11
8
 
12
9
 
13
- exports.BitbucketServerClient = BitbucketServerEntityProvider.BitbucketServerClient;
10
+
11
+ exports.default = catalogModuleBitbucketServerEntityProvider.catalogModuleBitbucketServerEntityProvider;
12
+ exports.BitbucketServerClient = BitbucketServerClient.BitbucketServerClient;
14
13
  exports.BitbucketServerEntityProvider = BitbucketServerEntityProvider.BitbucketServerEntityProvider;
15
14
  //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,15 @@
1
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
+ import { LoggerService, SchedulerServiceTaskRunner, SchedulerService } from '@backstage/backend-plugin-api';
1
3
  import { Response } from 'node-fetch';
2
4
  import { BitbucketServerIntegrationConfig } from '@backstage/integration';
3
5
  import { Config } from '@backstage/config';
4
6
  import { LocationSpec, EntityProvider, EntityProviderConnection } from '@backstage/plugin-catalog-node';
5
7
  import { Entity } from '@backstage/catalog-model';
6
- import { LoggerService, SchedulerServiceTaskRunner, SchedulerService } from '@backstage/backend-plugin-api';
8
+
9
+ /**
10
+ * @public
11
+ */
12
+ declare const catalogModuleBitbucketServerEntityProvider: _backstage_backend_plugin_api.BackendFeature;
7
13
 
8
14
  /** @public */
9
15
  type BitbucketServerRepository = {
@@ -126,4 +132,4 @@ declare class BitbucketServerEntityProvider implements EntityProvider {
126
132
  private findEntities;
127
133
  }
128
134
 
129
- export { BitbucketServerClient, BitbucketServerEntityProvider, type BitbucketServerListOptions, type BitbucketServerLocationParser, type BitbucketServerPagedResponse, type BitbucketServerProject, type BitbucketServerRepository };
135
+ export { BitbucketServerClient, BitbucketServerEntityProvider, type BitbucketServerListOptions, type BitbucketServerLocationParser, type BitbucketServerPagedResponse, type BitbucketServerProject, type BitbucketServerRepository, catalogModuleBitbucketServerEntityProvider as default };
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+
3
+ var fetch = require('node-fetch');
4
+ var integration = require('@backstage/integration');
5
+
6
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
7
+
8
+ var fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
9
+
10
+ class BitbucketServerClient {
11
+ config;
12
+ static fromConfig(options) {
13
+ return new BitbucketServerClient(options);
14
+ }
15
+ constructor(options) {
16
+ this.config = options.config;
17
+ }
18
+ async listProjects(options) {
19
+ return this.pagedRequest(
20
+ `${this.config.apiBaseUrl}/projects`,
21
+ options.listOptions
22
+ );
23
+ }
24
+ async listRepositories(options) {
25
+ return this.pagedRequest(
26
+ `${this.config.apiBaseUrl}/projects/${encodeURIComponent(
27
+ options.projectKey
28
+ )}/repos`,
29
+ options.listOptions
30
+ );
31
+ }
32
+ async getFile(options) {
33
+ const base = new URL(this.config.apiBaseUrl);
34
+ return fetch__default.default(
35
+ `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,
36
+ integration.getBitbucketServerRequestOptions(this.config)
37
+ );
38
+ }
39
+ async getRepository(options) {
40
+ const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;
41
+ const response = await fetch__default.default(
42
+ request,
43
+ integration.getBitbucketServerRequestOptions(this.config)
44
+ );
45
+ return response.json();
46
+ }
47
+ resolvePath(options) {
48
+ const base = new URL(this.config.apiBaseUrl || "");
49
+ return {
50
+ path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`
51
+ };
52
+ }
53
+ async pagedRequest(endpoint, options) {
54
+ const request = new URL(endpoint);
55
+ for (const key in options) {
56
+ if (options[key]) {
57
+ request.searchParams.append(key, options[key].toString());
58
+ }
59
+ }
60
+ return this.getTypeMapped(request);
61
+ }
62
+ async getTypeMapped(url) {
63
+ return this.get(url).then((response) => {
64
+ return response.json();
65
+ });
66
+ }
67
+ async get(url) {
68
+ return this.request(new fetch.Request(url.toString(), { method: "GET" }));
69
+ }
70
+ async request(req) {
71
+ return fetch__default.default(req, integration.getBitbucketServerRequestOptions(this.config)).then(
72
+ (response) => {
73
+ if (!response.ok) {
74
+ throw new Error(
75
+ `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`
76
+ );
77
+ }
78
+ return response;
79
+ }
80
+ );
81
+ }
82
+ }
83
+ async function* paginated(request, options) {
84
+ const opts = { start: 0 };
85
+ let res;
86
+ do {
87
+ res = await request(opts);
88
+ opts.start = res.nextPageStart;
89
+ for (const item of res.values) {
90
+ yield item;
91
+ }
92
+ } while (!res.isLastPage);
93
+ }
94
+
95
+ exports.BitbucketServerClient = BitbucketServerClient;
96
+ exports.paginated = paginated;
97
+ //# sourceMappingURL=BitbucketServerClient.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitbucketServerClient.cjs.js","sources":["../../src/lib/BitbucketServerClient.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"],"names":["fetch","getBitbucketServerRequestOptions","Request"],"mappings":";;;;;;;;;AA4BO,MAAM,qBAAsB,CAAA;AAAA,EAChB,MAAA,CAAA;AAAA,EAEjB,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,IAAK,CAAA,MAAA,CAAO,UAAU,CAAA,SAAA,CAAA;AAAA,MACzB,OAAQ,CAAA,WAAA;AAAA,KACV,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,iBAAiB,OAG8C,EAAA;AACnE,IAAA,OAAO,IAAK,CAAA,YAAA;AAAA,MACV,CAAG,EAAA,IAAA,CAAK,MAAO,CAAA,UAAU,CAAa,UAAA,EAAA,kBAAA;AAAA,QACpC,OAAQ,CAAA,UAAA;AAAA,OACT,CAAA,MAAA,CAAA;AAAA,MACD,OAAQ,CAAA,WAAA;AAAA,KACV,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,QAAQ,OAIQ,EAAA;AACpB,IAAA,MAAM,IAAO,GAAA,IAAI,GAAI,CAAA,IAAA,CAAK,OAA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ACnC,EAAI,IAAA,GAAA,CAAA;AACJ,EAAG,GAAA;AACD,IAAM,GAAA,GAAA,MAAM,QAAQ,IAAI,CAAA,CAAA;AACxB,IAAA,IAAA,CAAK,QAAQ,GAAI,CAAA,aAAA,CAAA;AACjB,IAAW,KAAA,MAAA,IAAA,IAAQ,IAAI,MAAQ,EAAA;AAC7B,MAAM,MAAA,IAAA,CAAA;AAAA,KACR;AAAA,GACF,QAAS,CAAC,GAAI,CAAA,UAAA,EAAA;AAChB;;;;;"}
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+ var alpha = require('@backstage/plugin-catalog-node/alpha');
5
+ var BitbucketServerEntityProvider = require('../providers/BitbucketServerEntityProvider.cjs.js');
6
+
7
+ const catalogModuleBitbucketServerEntityProvider = backendPluginApi.createBackendModule({
8
+ pluginId: "catalog",
9
+ moduleId: "bitbucket-server-entity-provider",
10
+ register(env) {
11
+ env.registerInit({
12
+ deps: {
13
+ catalog: alpha.catalogProcessingExtensionPoint,
14
+ config: backendPluginApi.coreServices.rootConfig,
15
+ logger: backendPluginApi.coreServices.logger,
16
+ scheduler: backendPluginApi.coreServices.scheduler
17
+ },
18
+ async init({ catalog, config, logger, scheduler }) {
19
+ const providers = BitbucketServerEntityProvider.BitbucketServerEntityProvider.fromConfig(config, {
20
+ logger,
21
+ scheduler
22
+ });
23
+ catalog.addEntityProvider(providers);
24
+ }
25
+ });
26
+ }
27
+ });
28
+
29
+ exports.catalogModuleBitbucketServerEntityProvider = catalogModuleBitbucketServerEntityProvider;
30
+ //# sourceMappingURL=catalogModuleBitbucketServerEntityProvider.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalogModuleBitbucketServerEntityProvider.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 {\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 * @public\n */\nexport const catalogModuleBitbucketServerEntityProvider = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'bitbucket-server-entity-provider',\n register(env) {\n env.registerInit({\n deps: {\n catalog: catalogProcessingExtensionPoint,\n config: coreServices.rootConfig,\n logger: coreServices.logger,\n scheduler: coreServices.scheduler,\n },\n async init({ catalog, config, logger, scheduler }) {\n const providers = BitbucketServerEntityProvider.fromConfig(config, {\n logger,\n scheduler,\n });\n\n catalog.addEntityProvider(providers);\n },\n });\n },\n});\n"],"names":["createBackendModule","catalogProcessingExtensionPoint","coreServices","BitbucketServerEntityProvider"],"mappings":";;;;;;AA0BO,MAAM,6CAA6CA,oCAAoB,CAAA;AAAA,EAC5E,QAAU,EAAA,SAAA;AAAA,EACV,QAAU,EAAA,kCAAA;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,UAAA;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,SAAA,GAAYC,2DAA8B,CAAA,UAAA,CAAW,MAAQ,EAAA;AAAA,UACjE,MAAA;AAAA,UACA,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,167 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+ var integration = require('@backstage/integration');
5
+ var uuid = require('uuid');
6
+ var BitbucketServerClient = require('../lib/BitbucketServerClient.cjs.js');
7
+ var BitbucketServerEntityProviderConfig = require('./BitbucketServerEntityProviderConfig.cjs.js');
8
+ var BitbucketServerLocationParser = require('./BitbucketServerLocationParser.cjs.js');
9
+
10
+ function _interopNamespaceCompat(e) {
11
+ if (e && typeof e === 'object' && 'default' in e) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var uuid__namespace = /*#__PURE__*/_interopNamespaceCompat(uuid);
29
+
30
+ class BitbucketServerEntityProvider {
31
+ integration;
32
+ config;
33
+ parser;
34
+ logger;
35
+ scheduleFn;
36
+ connection;
37
+ static fromConfig(config, options) {
38
+ const integrations = integration.ScmIntegrations.fromConfig(config);
39
+ if (!options.schedule && !options.scheduler) {
40
+ throw new Error("Either schedule or scheduler must be provided.");
41
+ }
42
+ return BitbucketServerEntityProviderConfig.readProviderConfigs(config).map((providerConfig) => {
43
+ const integration = integrations.bitbucketServer.byHost(
44
+ providerConfig.host
45
+ );
46
+ if (!integration) {
47
+ throw new errors.InputError(
48
+ `No BitbucketServer integration found that matches host ${providerConfig.host}`
49
+ );
50
+ }
51
+ if (!options.schedule && !providerConfig.schedule) {
52
+ throw new Error(
53
+ `No schedule provided neither via code nor config for bitbucketServer-provider:${providerConfig.id}.`
54
+ );
55
+ }
56
+ const taskRunner = options.schedule ?? options.scheduler.createScheduledTaskRunner(providerConfig.schedule);
57
+ return new BitbucketServerEntityProvider(
58
+ providerConfig,
59
+ integration,
60
+ options.logger,
61
+ taskRunner,
62
+ options.parser
63
+ );
64
+ });
65
+ }
66
+ constructor(config, integration, logger, taskRunner, parser) {
67
+ this.integration = integration;
68
+ this.config = config;
69
+ this.parser = parser || BitbucketServerLocationParser.defaultBitbucketServerLocationParser;
70
+ this.logger = logger.child({
71
+ target: this.getProviderName()
72
+ });
73
+ this.scheduleFn = this.createScheduleFn(taskRunner);
74
+ }
75
+ createScheduleFn(taskRunner) {
76
+ return async () => {
77
+ const taskId = `${this.getProviderName()}:refresh`;
78
+ return taskRunner.run({
79
+ id: taskId,
80
+ fn: async () => {
81
+ const logger = this.logger.child({
82
+ class: BitbucketServerEntityProvider.prototype.constructor.name,
83
+ taskId,
84
+ taskInstanceId: uuid__namespace.v4()
85
+ });
86
+ try {
87
+ await this.refresh(logger);
88
+ } catch (error) {
89
+ logger.error(
90
+ `${this.getProviderName()} refresh failed, ${error}`,
91
+ error
92
+ );
93
+ }
94
+ }
95
+ });
96
+ };
97
+ }
98
+ /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
99
+ getProviderName() {
100
+ return `bitbucketServer-provider:${this.config.id}`;
101
+ }
102
+ /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
103
+ async connect(connection) {
104
+ this.connection = connection;
105
+ await this.scheduleFn();
106
+ }
107
+ async refresh(logger) {
108
+ if (!this.connection) {
109
+ throw new Error("Not initialized");
110
+ }
111
+ logger.info("Discovering catalog files in Bitbucket Server repositories");
112
+ const entities = await this.findEntities();
113
+ await this.connection.applyMutation({
114
+ type: "full",
115
+ entities: entities.map((entity) => ({
116
+ locationKey: this.getProviderName(),
117
+ entity
118
+ }))
119
+ });
120
+ logger.info(
121
+ `Committed ${entities.length} entities for Bitbucket Server repositories`
122
+ );
123
+ }
124
+ async findEntities() {
125
+ const client = BitbucketServerClient.BitbucketServerClient.fromConfig({
126
+ config: this.integration.config
127
+ });
128
+ const projects = BitbucketServerClient.paginated(
129
+ (options) => client.listProjects({ listOptions: options })
130
+ );
131
+ const result = [];
132
+ for await (const project of projects) {
133
+ if (this.config?.filters?.projectKey && !this.config.filters.projectKey.test(project.key)) {
134
+ continue;
135
+ }
136
+ const repositories = BitbucketServerClient.paginated(
137
+ (options) => client.listRepositories({
138
+ projectKey: project.key,
139
+ listOptions: options
140
+ })
141
+ );
142
+ for await (const repository of repositories) {
143
+ if (this.config?.filters?.repoSlug && !this.config.filters.repoSlug.test(repository.slug)) {
144
+ continue;
145
+ }
146
+ if (this.config?.filters?.skipArchivedRepos && repository.archived) {
147
+ continue;
148
+ }
149
+ for await (const entity of this.parser({
150
+ client,
151
+ logger: this.logger,
152
+ location: {
153
+ type: "url",
154
+ target: `${repository.links.self[0].href}${this.config.catalogPath}`,
155
+ presence: "optional"
156
+ }
157
+ })) {
158
+ result.push(entity);
159
+ }
160
+ }
161
+ }
162
+ return result;
163
+ }
164
+ }
165
+
166
+ exports.BitbucketServerEntityProvider = BitbucketServerEntityProvider;
167
+ //# sourceMappingURL=BitbucketServerEntityProvider.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitbucketServerEntityProvider.cjs.js","sources":["../../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 { 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 * 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';\nimport {\n LoggerService,\n SchedulerService,\n SchedulerServiceTaskRunner,\n} from '@backstage/backend-plugin-api';\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: LoggerService;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n\n static fromConfig(\n config: Config,\n options: {\n logger: LoggerService;\n parser?: BitbucketServerLocationParser;\n schedule?: SchedulerServiceTaskRunner;\n scheduler?: SchedulerService;\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: LoggerService,\n taskRunner: SchedulerServiceTaskRunner,\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(\n taskRunner: SchedulerServiceTaskRunner,\n ): () => 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(\n `${this.getProviderName()} refresh failed, ${error}`,\n error,\n );\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: LoggerService) {\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 if (this.config?.filters?.skipArchivedRepos && repository.archived) {\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":["ScmIntegrations","readProviderConfigs","InputError","defaultBitbucketServerLocationParser","uuid","BitbucketServerClient","paginated"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmDO,MAAM,6BAAwD,CAAA;AAAA,EAClD,WAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EACT,UAAA,CAAA;AAAA,EAER,OAAO,UACL,CAAA,MAAA,EACA,OAMiC,EAAA;AACjC,IAAM,MAAA,YAAA,GAAeA,2BAAgB,CAAA,UAAA,CAAW,MAAM,CAAA,CAAA;AAEtD,IAAA,IAAI,CAAC,OAAA,CAAQ,QAAY,IAAA,CAAC,QAAQ,SAAW,EAAA;AAC3C,MAAM,MAAA,IAAI,MAAM,gDAAgD,CAAA,CAAA;AAAA,KAClE;AAEA,IAAA,OAAOC,uDAAoB,CAAA,MAAM,CAAE,CAAA,GAAA,CAAI,CAAkB,cAAA,KAAA;AACvD,MAAM,MAAA,WAAA,GAAc,aAAa,eAAgB,CAAA,MAAA;AAAA,QAC/C,cAAe,CAAA,IAAA;AAAA,OACjB,CAAA;AACA,MAAA,IAAI,CAAC,WAAa,EAAA;AAChB,QAAA,MAAM,I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AA,IAAI,IAAK,CAAA,MAAA,EAAQ,OAAS,EAAA,iBAAA,IAAqB,WAAW,QAAU,EAAA;AAClE,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,CAAG,EAAA,UAAA,CAAW,KAAM,CAAA,IAAA,CAAK,CAAC,CAAA,CAAE,IAAI,CAAA,EAAG,IAAK,CAAA,MAAA,CAAO,WAAW,CAAA,CAAA;AAAA,YAClE,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;;;;"}
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var backendPluginApi = require('@backstage/backend-plugin-api');
4
+
5
+ const DEFAULT_CATALOG_PATH = "/catalog-info.yaml";
6
+ const DEFAULT_PROVIDER_ID = "default";
7
+ function readProviderConfigs(config) {
8
+ const providersConfig = config.getOptionalConfig(
9
+ "catalog.providers.bitbucketServer"
10
+ );
11
+ if (!providersConfig) {
12
+ return [];
13
+ }
14
+ if (providersConfig.has("host")) {
15
+ return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];
16
+ }
17
+ return providersConfig.keys().map((id) => {
18
+ const providerConfig = providersConfig.getConfig(id);
19
+ return readProviderConfig(id, providerConfig);
20
+ });
21
+ }
22
+ function readProviderConfig(id, config) {
23
+ const host = config.getString("host");
24
+ const catalogPath = config.getOptionalString("catalogPath") ?? DEFAULT_CATALOG_PATH;
25
+ const projectKeyPattern = config.getOptionalString("filters.projectKey");
26
+ const repoSlugPattern = config.getOptionalString("filters.repoSlug");
27
+ const skipArchivedReposFlag = config.getOptionalBoolean(
28
+ "filters.skipArchivedRepos"
29
+ );
30
+ const schedule = config.has("schedule") ? backendPluginApi.readSchedulerServiceTaskScheduleDefinitionFromConfig(
31
+ config.getConfig("schedule")
32
+ ) : void 0;
33
+ return {
34
+ id,
35
+ host,
36
+ catalogPath,
37
+ filters: {
38
+ projectKey: projectKeyPattern ? new RegExp(projectKeyPattern) : void 0,
39
+ repoSlug: repoSlugPattern ? new RegExp(repoSlugPattern) : void 0,
40
+ skipArchivedRepos: skipArchivedReposFlag
41
+ },
42
+ schedule
43
+ };
44
+ }
45
+
46
+ exports.readProviderConfigs = readProviderConfigs;
47
+ //# sourceMappingURL=BitbucketServerEntityProviderConfig.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitbucketServerEntityProviderConfig.cjs.js","sources":["../../src/providers/BitbucketServerEntityProviderConfig.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n SchedulerServiceTaskScheduleDefinition,\n readSchedulerServiceTaskScheduleDefinitionFromConfig,\n} from '@backstage/backend-plugin-api';\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 skipArchivedRepos?: boolean;\n };\n schedule?: SchedulerServiceTaskScheduleDefinition;\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 const skipArchivedReposFlag = config.getOptionalBoolean(\n 'filters.skipArchivedRepos',\n );\n\n const schedule = config.has('schedule')\n ? readSchedulerServiceTaskScheduleDefinitionFromConfig(\n config.getConfig('schedule'),\n )\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 skipArchivedRepos: skipArchivedReposFlag,\n },\n schedule,\n };\n}\n"],"names":["readSchedulerServiceTaskScheduleDefinitionFromConfig"],"mappings":";;;;AAsBA,MAAM,oBAAuB,GAAA,oBAAA,CAAA;AAC7B,MAAM,mBAAsB,GAAA,SAAA,CAAA;AAcrB,SAAS,oBACd,MACuC,EAAA;AACvC,EAAA,MAAM,kBAAkB,MAAO,CAAA,iBAAA;AAAA,IAC7B,mCAAA;AAAA,GACF,CAAA;AACA,EAAA,IAAI,CAAC,eAAiB,EAAA;AACpB,IAAA,OAAO,EAAC,CAAA;AAAA,GACV;AACA,EAAI,IAAA,eAAA,CAAgB,GAAI,CAAA,MAAM,CAAG,EAAA;AAE/B,IAAA,OAAO,CAAC,kBAAA,CAAmB,mBAAqB,EAAA,eAAe,CAAC,CAAA,CAAA;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10 @@
1
+ 'use strict';
2
+
3
+ var pluginCatalogNode = require('@backstage/plugin-catalog-node');
4
+
5
+ const defaultBitbucketServerLocationParser = async function* defaultBitbucketServerLocationParser2(options) {
6
+ yield pluginCatalogNode.locationSpecToLocationEntity({ location: options.location });
7
+ };
8
+
9
+ exports.defaultBitbucketServerLocationParser = defaultBitbucketServerLocationParser;
10
+ //# sourceMappingURL=BitbucketServerLocationParser.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BitbucketServerLocationParser.cjs.js","sources":["../../src/providers/BitbucketServerLocationParser.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n LocationSpec,\n locationSpecToLocationEntity,\n} from '@backstage/plugin-catalog-node';\nimport { Entity } from '@backstage/catalog-model';\nimport { BitbucketServerClient } from '../lib';\nimport { LoggerService } from '@backstage/backend-plugin-api';\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: LoggerService;\n}) => AsyncIterable<Entity>;\n\nexport const defaultBitbucketServerLocationParser =\n async function* defaultBitbucketServerLocationParser(options: {\n location: LocationSpec;\n }) {\n yield locationSpecToLocationEntity({ location: options.location });\n };\n"],"names":["defaultBitbucketServerLocationParser","locationSpecToLocationEntity"],"mappings":";;;;AAoCa,MAAA,oCAAA,GACX,gBAAgBA,qCAAAA,CAAqC,OAElD,EAAA;AACD,EAAA,MAAMC,8CAA6B,CAAA,EAAE,QAAU,EAAA,OAAA,CAAQ,UAAU,CAAA,CAAA;AACnE;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend-module-bitbucket-server",
3
- "version": "0.2.3-next.1",
3
+ "version": "0.2.3",
4
4
  "backstage": {
5
5
  "role": "backend-plugin-module",
6
6
  "pluginId": "catalog",
@@ -21,6 +21,7 @@
21
21
  "license": "Apache-2.0",
22
22
  "exports": {
23
23
  ".": {
24
+ "backstage": "@backstage/BackendFeature",
24
25
  "require": "./dist/index.cjs.js",
25
26
  "types": "./dist/index.d.ts",
26
27
  "default": "./dist/index.cjs.js"
@@ -50,19 +51,19 @@
50
51
  "test": "backstage-cli package test"
51
52
  },
52
53
  "dependencies": {
53
- "@backstage/backend-plugin-api": "1.0.1-next.0",
54
- "@backstage/catalog-model": "1.7.0",
55
- "@backstage/config": "1.2.0",
56
- "@backstage/errors": "1.2.4",
57
- "@backstage/integration": "1.15.1-next.0",
58
- "@backstage/plugin-catalog-node": "1.13.1-next.0",
54
+ "@backstage/backend-plugin-api": "^1.0.1",
55
+ "@backstage/catalog-model": "^1.7.0",
56
+ "@backstage/config": "^1.2.0",
57
+ "@backstage/errors": "^1.2.4",
58
+ "@backstage/integration": "^1.15.1",
59
+ "@backstage/plugin-catalog-node": "^1.13.1",
59
60
  "@types/node-fetch": "^2.5.12",
60
61
  "node-fetch": "^2.7.0",
61
62
  "uuid": "^9.0.0"
62
63
  },
63
64
  "devDependencies": {
64
- "@backstage/backend-test-utils": "1.0.1-next.1",
65
- "@backstage/cli": "0.28.0-next.1",
65
+ "@backstage/backend-test-utils": "^1.0.1",
66
+ "@backstage/cli": "^0.28.0",
66
67
  "luxon": "^3.0.0",
67
68
  "msw": "^1.0.0"
68
69
  },
@@ -1,301 +0,0 @@
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 backendPluginApi = require('@backstage/backend-plugin-api');
8
- var pluginCatalogNode = require('@backstage/plugin-catalog-node');
9
-
10
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
11
-
12
- function _interopNamespaceCompat(e) {
13
- if (e && typeof e === 'object' && 'default' in e) 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__*/_interopNamespaceCompat(uuid);
31
- var fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
32
-
33
- class BitbucketServerClient {
34
- config;
35
- static fromConfig(options) {
36
- return new BitbucketServerClient(options);
37
- }
38
- constructor(options) {
39
- this.config = options.config;
40
- }
41
- async listProjects(options) {
42
- return this.pagedRequest(
43
- `${this.config.apiBaseUrl}/projects`,
44
- options.listOptions
45
- );
46
- }
47
- async listRepositories(options) {
48
- return this.pagedRequest(
49
- `${this.config.apiBaseUrl}/projects/${encodeURIComponent(
50
- options.projectKey
51
- )}/repos`,
52
- options.listOptions
53
- );
54
- }
55
- async getFile(options) {
56
- const base = new URL(this.config.apiBaseUrl);
57
- return fetch__default.default(
58
- `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}/raw/${options.path}`,
59
- integration.getBitbucketServerRequestOptions(this.config)
60
- );
61
- }
62
- async getRepository(options) {
63
- const request = `${this.config.apiBaseUrl}/projects/${options.projectKey}/repos/${options.repo}`;
64
- const response = await fetch__default.default(
65
- request,
66
- integration.getBitbucketServerRequestOptions(this.config)
67
- );
68
- return response.json();
69
- }
70
- resolvePath(options) {
71
- const base = new URL(this.config.apiBaseUrl || "");
72
- return {
73
- path: `${base.protocol}//${base.host}/projects/${options.projectKey}/repos/${options.repo}${options.path}`
74
- };
75
- }
76
- async pagedRequest(endpoint, options) {
77
- const request = new URL(endpoint);
78
- for (const key in options) {
79
- if (options[key]) {
80
- request.searchParams.append(key, options[key].toString());
81
- }
82
- }
83
- return this.getTypeMapped(request);
84
- }
85
- async getTypeMapped(url) {
86
- return this.get(url).then((response) => {
87
- return response.json();
88
- });
89
- }
90
- async get(url) {
91
- return this.request(new fetch.Request(url.toString(), { method: "GET" }));
92
- }
93
- async request(req) {
94
- return fetch__default.default(req, integration.getBitbucketServerRequestOptions(this.config)).then(
95
- (response) => {
96
- if (!response.ok) {
97
- throw new Error(
98
- `Unexpected response for ${req.method} ${req.url}. Expected 200 but got ${response.status} - ${response.statusText}`
99
- );
100
- }
101
- return response;
102
- }
103
- );
104
- }
105
- }
106
- async function* paginated(request, options) {
107
- const opts = { start: 0 };
108
- let res;
109
- do {
110
- res = await request(opts);
111
- opts.start = res.nextPageStart;
112
- for (const item of res.values) {
113
- yield item;
114
- }
115
- } while (!res.isLastPage);
116
- }
117
-
118
- const DEFAULT_CATALOG_PATH = "/catalog-info.yaml";
119
- const DEFAULT_PROVIDER_ID = "default";
120
- function readProviderConfigs(config) {
121
- const providersConfig = config.getOptionalConfig(
122
- "catalog.providers.bitbucketServer"
123
- );
124
- if (!providersConfig) {
125
- return [];
126
- }
127
- if (providersConfig.has("host")) {
128
- return [readProviderConfig(DEFAULT_PROVIDER_ID, providersConfig)];
129
- }
130
- return providersConfig.keys().map((id) => {
131
- const providerConfig = providersConfig.getConfig(id);
132
- return readProviderConfig(id, providerConfig);
133
- });
134
- }
135
- function readProviderConfig(id, config) {
136
- const host = config.getString("host");
137
- const catalogPath = config.getOptionalString("catalogPath") ?? DEFAULT_CATALOG_PATH;
138
- const projectKeyPattern = config.getOptionalString("filters.projectKey");
139
- const repoSlugPattern = config.getOptionalString("filters.repoSlug");
140
- const skipArchivedReposFlag = config.getOptionalBoolean(
141
- "filters.skipArchivedRepos"
142
- );
143
- const schedule = config.has("schedule") ? backendPluginApi.readSchedulerServiceTaskScheduleDefinitionFromConfig(
144
- config.getConfig("schedule")
145
- ) : 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
- skipArchivedRepos: skipArchivedReposFlag
154
- },
155
- schedule
156
- };
157
- }
158
-
159
- const defaultBitbucketServerLocationParser = async function* defaultBitbucketServerLocationParser2(options) {
160
- yield pluginCatalogNode.locationSpecToLocationEntity({ location: options.location });
161
- };
162
-
163
- class BitbucketServerEntityProvider {
164
- integration;
165
- config;
166
- parser;
167
- logger;
168
- scheduleFn;
169
- connection;
170
- static fromConfig(config, options) {
171
- const integrations = integration.ScmIntegrations.fromConfig(config);
172
- if (!options.schedule && !options.scheduler) {
173
- throw new Error("Either schedule or scheduler must be provided.");
174
- }
175
- return readProviderConfigs(config).map((providerConfig) => {
176
- const integration = integrations.bitbucketServer.byHost(
177
- providerConfig.host
178
- );
179
- if (!integration) {
180
- throw new errors.InputError(
181
- `No BitbucketServer integration found that matches host ${providerConfig.host}`
182
- );
183
- }
184
- if (!options.schedule && !providerConfig.schedule) {
185
- throw new Error(
186
- `No schedule provided neither via code nor config for bitbucketServer-provider:${providerConfig.id}.`
187
- );
188
- }
189
- const taskRunner = options.schedule ?? options.scheduler.createScheduledTaskRunner(providerConfig.schedule);
190
- return new BitbucketServerEntityProvider(
191
- providerConfig,
192
- integration,
193
- options.logger,
194
- taskRunner,
195
- options.parser
196
- );
197
- });
198
- }
199
- constructor(config, integration, logger, taskRunner, parser) {
200
- this.integration = integration;
201
- this.config = config;
202
- this.parser = parser || defaultBitbucketServerLocationParser;
203
- this.logger = logger.child({
204
- target: this.getProviderName()
205
- });
206
- this.scheduleFn = this.createScheduleFn(taskRunner);
207
- }
208
- createScheduleFn(taskRunner) {
209
- return async () => {
210
- const taskId = `${this.getProviderName()}:refresh`;
211
- return taskRunner.run({
212
- id: taskId,
213
- fn: async () => {
214
- const logger = this.logger.child({
215
- class: BitbucketServerEntityProvider.prototype.constructor.name,
216
- taskId,
217
- taskInstanceId: uuid__namespace.v4()
218
- });
219
- try {
220
- await this.refresh(logger);
221
- } catch (error) {
222
- logger.error(
223
- `${this.getProviderName()} refresh failed, ${error}`,
224
- error
225
- );
226
- }
227
- }
228
- });
229
- };
230
- }
231
- /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.getProviderName} */
232
- getProviderName() {
233
- return `bitbucketServer-provider:${this.config.id}`;
234
- }
235
- /** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
236
- async connect(connection) {
237
- this.connection = connection;
238
- await this.scheduleFn();
239
- }
240
- async refresh(logger) {
241
- if (!this.connection) {
242
- throw new Error("Not initialized");
243
- }
244
- logger.info("Discovering catalog files in Bitbucket Server repositories");
245
- const entities = await this.findEntities();
246
- await this.connection.applyMutation({
247
- type: "full",
248
- entities: entities.map((entity) => ({
249
- locationKey: this.getProviderName(),
250
- entity
251
- }))
252
- });
253
- logger.info(
254
- `Committed ${entities.length} entities for Bitbucket Server repositories`
255
- );
256
- }
257
- async findEntities() {
258
- const client = BitbucketServerClient.fromConfig({
259
- config: this.integration.config
260
- });
261
- const projects = paginated(
262
- (options) => client.listProjects({ listOptions: options })
263
- );
264
- const result = [];
265
- for await (const project of projects) {
266
- if (this.config?.filters?.projectKey && !this.config.filters.projectKey.test(project.key)) {
267
- continue;
268
- }
269
- const repositories = paginated(
270
- (options) => client.listRepositories({
271
- projectKey: project.key,
272
- listOptions: options
273
- })
274
- );
275
- for await (const repository of repositories) {
276
- if (this.config?.filters?.repoSlug && !this.config.filters.repoSlug.test(repository.slug)) {
277
- continue;
278
- }
279
- if (this.config?.filters?.skipArchivedRepos && repository.archived) {
280
- continue;
281
- }
282
- for await (const entity of this.parser({
283
- client,
284
- logger: this.logger,
285
- location: {
286
- type: "url",
287
- target: `${repository.links.self[0].href}${this.config.catalogPath}`,
288
- presence: "optional"
289
- }
290
- })) {
291
- result.push(entity);
292
- }
293
- }
294
- }
295
- return result;
296
- }
297
- }
298
-
299
- exports.BitbucketServerClient = BitbucketServerClient;
300
- exports.BitbucketServerEntityProvider = BitbucketServerEntityProvider;
301
- //# sourceMappingURL=BitbucketServerEntityProvider-BefRa_fm.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BitbucketServerEntityProvider-BefRa_fm.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 SchedulerServiceTaskScheduleDefinition,\n readSchedulerServiceTaskScheduleDefinitionFromConfig,\n} from '@backstage/backend-plugin-api';\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 skipArchivedRepos?: boolean;\n };\n schedule?: SchedulerServiceTaskScheduleDefinition;\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 const skipArchivedReposFlag = config.getOptionalBoolean(\n 'filters.skipArchivedRepos',\n );\n\n const schedule = config.has('schedule')\n ? readSchedulerServiceTaskScheduleDefinitionFromConfig(\n config.getConfig('schedule'),\n )\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 skipArchivedRepos: skipArchivedReposFlag,\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 { BitbucketServerClient } from '../lib';\nimport { LoggerService } from '@backstage/backend-plugin-api';\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: LoggerService;\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 { 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 * 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';\nimport {\n LoggerService,\n SchedulerService,\n SchedulerServiceTaskRunner,\n} from '@backstage/backend-plugin-api';\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: LoggerService;\n private readonly scheduleFn: () => Promise<void>;\n private connection?: EntityProviderConnection;\n\n static fromConfig(\n config: Config,\n options: {\n logger: LoggerService;\n parser?: BitbucketServerLocationParser;\n schedule?: SchedulerServiceTaskRunner;\n scheduler?: SchedulerService;\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: LoggerService,\n taskRunner: SchedulerServiceTaskRunner,\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(\n taskRunner: SchedulerServiceTaskRunner,\n ): () => 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(\n `${this.getProviderName()} refresh failed, ${error}`,\n error,\n );\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: LoggerService) {\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 if (this.config?.filters?.skipArchivedRepos && repository.archived) {\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","readSchedulerServiceTaskScheduleDefinitionFromConfig","defaultBitbucketServerLocationParser","locationSpecToLocationEntity","ScmIntegrations","InputError","uuid"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BO,MAAM,qBAAsB,CAAA;AAAA,EAChB,MAAA,CAAA;AAAA,EAEjB,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,IAA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