@backstage/backend-defaults 0.2.18 → 0.2.19-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/cache/package.json +6 -0
- package/config.d.ts +39 -0
- package/database/package.json +6 -0
- package/discovery/package.json +6 -0
- package/dist/cache.cjs.js +21 -0
- package/dist/cache.cjs.js.map +1 -0
- package/dist/cache.d.ts +9 -0
- package/dist/database.cjs.js +32 -0
- package/dist/database.cjs.js.map +1 -0
- package/dist/database.d.ts +9 -0
- package/dist/discovery.cjs.js +97 -0
- package/dist/discovery.cjs.js.map +1 -0
- package/dist/discovery.d.ts +55 -0
- package/dist/index.cjs.js +18 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/lifecycle.cjs.js +63 -0
- package/dist/lifecycle.cjs.js.map +1 -0
- package/dist/lifecycle.d.ts +11 -0
- package/dist/permissions.cjs.js +24 -0
- package/dist/permissions.cjs.js.map +1 -0
- package/dist/permissions.d.ts +8 -0
- package/dist/rootConfig.cjs.js +23 -0
- package/dist/rootConfig.cjs.js.map +1 -0
- package/dist/rootConfig.d.ts +23 -0
- package/dist/rootLifecycle.cjs.js +75 -0
- package/dist/rootLifecycle.cjs.js.map +1 -0
- package/dist/rootLifecycle.d.ts +11 -0
- package/dist/scheduler.cjs.js +694 -0
- package/dist/scheduler.cjs.js.map +1 -0
- package/dist/scheduler.d.ts +10 -0
- package/dist/urlReader.cjs.js +21 -0
- package/dist/urlReader.cjs.js.map +1 -0
- package/dist/urlReader.d.ts +7 -0
- package/lifecycle/package.json +6 -0
- package/migrations/scheduler/20210928160613_init.js +64 -0
- package/package.json +100 -23
- package/permissions/package.json +6 -0
- package/rootConfig/package.json +6 -0
- package/rootLifecycle/package.json +6 -0
- package/scheduler/package.json +6 -0
- package/urlReader/package.json +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @backstage/backend-defaults
|
|
2
2
|
|
|
3
|
+
## 0.2.19-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6551b3d: Added core service factories and implementations from
|
|
8
|
+
`@backstage/backend-app-api`. They are now available as subpath exports, e.g.
|
|
9
|
+
`@backstage/backend-defaults/scheduler` is where the service factory and default
|
|
10
|
+
implementation of `coreServices.scheduler` now lives. They have been marked as
|
|
11
|
+
deprecated in their old locations.
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- @backstage/backend-app-api@0.7.6-next.0
|
|
14
|
+
- @backstage/backend-common@0.22.1-next.0
|
|
15
|
+
- @backstage/plugin-events-node@0.3.5-next.0
|
|
16
|
+
- @backstage/backend-plugin-api@0.6.19-next.0
|
|
17
|
+
- @backstage/plugin-permission-node@0.7.30-next.0
|
|
18
|
+
- @backstage/config-loader@1.8.0
|
|
19
|
+
- @backstage/config@1.2.0
|
|
20
|
+
- @backstage/errors@1.2.4
|
|
21
|
+
- @backstage/types@1.1.1
|
|
22
|
+
|
|
3
23
|
## 0.2.18
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/config.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 The Backstage Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface Config {
|
|
18
|
+
/**
|
|
19
|
+
* Options used by the default discovery service.
|
|
20
|
+
*/
|
|
21
|
+
discovery?: {
|
|
22
|
+
/**
|
|
23
|
+
* A list of target baseUrls and the associated plugins.
|
|
24
|
+
*/
|
|
25
|
+
endpoints: Array<{
|
|
26
|
+
/**
|
|
27
|
+
* The target base URL to use for the plugin.
|
|
28
|
+
*
|
|
29
|
+
* Can be either a string or an object with internal and external keys.
|
|
30
|
+
* Targets with `{{pluginId}}` or `{{ pluginId }} in the URL will be replaced with the plugin ID.
|
|
31
|
+
*/
|
|
32
|
+
target: string | { internal: string; external: string };
|
|
33
|
+
/**
|
|
34
|
+
* Array of plugins which use the target base URL.
|
|
35
|
+
*/
|
|
36
|
+
plugins: string[];
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendCommon = require('@backstage/backend-common');
|
|
4
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
5
|
+
|
|
6
|
+
const cacheServiceFactory = backendPluginApi.createServiceFactory({
|
|
7
|
+
service: backendPluginApi.coreServices.cache,
|
|
8
|
+
deps: {
|
|
9
|
+
config: backendPluginApi.coreServices.rootConfig,
|
|
10
|
+
plugin: backendPluginApi.coreServices.pluginMetadata
|
|
11
|
+
},
|
|
12
|
+
async createRootContext({ config }) {
|
|
13
|
+
return backendCommon.CacheManager.fromConfig(config);
|
|
14
|
+
},
|
|
15
|
+
async factory({ plugin }, manager) {
|
|
16
|
+
return manager.forPlugin(plugin.getId()).getClient();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
exports.cacheServiceFactory = cacheServiceFactory;
|
|
21
|
+
//# sourceMappingURL=cache.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.cjs.js","sources":["../src/entrypoints/cache/cacheServiceFactory.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 { CacheManager } from '@backstage/backend-common';\nimport {\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\n\n/**\n * @public\n */\nexport const cacheServiceFactory = createServiceFactory({\n service: coreServices.cache,\n deps: {\n config: coreServices.rootConfig,\n plugin: coreServices.pluginMetadata,\n },\n async createRootContext({ config }) {\n return CacheManager.fromConfig(config);\n },\n async factory({ plugin }, manager) {\n return manager.forPlugin(plugin.getId()).getClient();\n },\n});\n"],"names":["createServiceFactory","coreServices","CacheManager"],"mappings":";;;;;AAyBO,MAAM,sBAAsBA,qCAAqB,CAAA;AAAA,EACtD,SAASC,6BAAa,CAAA,KAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACJ,QAAQA,6BAAa,CAAA,UAAA;AAAA,IACrB,QAAQA,6BAAa,CAAA,cAAA;AAAA,GACvB;AAAA,EACA,MAAM,iBAAA,CAAkB,EAAE,MAAA,EAAU,EAAA;AAClC,IAAO,OAAAC,0BAAA,CAAa,WAAW,MAAM,CAAA,CAAA;AAAA,GACvC;AAAA,EACA,MAAM,OAAA,CAAQ,EAAE,MAAA,IAAU,OAAS,EAAA;AACjC,IAAA,OAAO,QAAQ,SAAU,CAAA,MAAA,CAAO,KAAM,EAAC,EAAE,SAAU,EAAA,CAAA;AAAA,GACrD;AACF,CAAC;;;;"}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import * as _backstage_backend_common from '@backstage/backend-common';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
declare const cacheServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_common.CacheClient, "plugin">;
|
|
8
|
+
|
|
9
|
+
export { cacheServiceFactory };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendCommon = require('@backstage/backend-common');
|
|
4
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
5
|
+
var config = require('@backstage/config');
|
|
6
|
+
|
|
7
|
+
const databaseServiceFactory = backendPluginApi.createServiceFactory({
|
|
8
|
+
service: backendPluginApi.coreServices.database,
|
|
9
|
+
deps: {
|
|
10
|
+
config: backendPluginApi.coreServices.rootConfig,
|
|
11
|
+
lifecycle: backendPluginApi.coreServices.lifecycle,
|
|
12
|
+
pluginMetadata: backendPluginApi.coreServices.pluginMetadata
|
|
13
|
+
},
|
|
14
|
+
async createRootContext({ config: config$1 }) {
|
|
15
|
+
return config$1.getOptional("backend.database") ? backendCommon.DatabaseManager.fromConfig(config$1) : backendCommon.DatabaseManager.fromConfig(
|
|
16
|
+
new config.ConfigReader({
|
|
17
|
+
backend: {
|
|
18
|
+
database: { client: "better-sqlite3", connection: ":memory:" }
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
},
|
|
23
|
+
async factory({ pluginMetadata, lifecycle }, databaseManager) {
|
|
24
|
+
return databaseManager.forPlugin(pluginMetadata.getId(), {
|
|
25
|
+
pluginMetadata,
|
|
26
|
+
lifecycle
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
exports.databaseServiceFactory = databaseServiceFactory;
|
|
32
|
+
//# sourceMappingURL=database.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.cjs.js","sources":["../src/entrypoints/database/databaseServiceFactory.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 { DatabaseManager } from '@backstage/backend-common';\nimport {\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport { ConfigReader } from '@backstage/config';\n\n/**\n * @public\n */\nexport const databaseServiceFactory = createServiceFactory({\n service: coreServices.database,\n deps: {\n config: coreServices.rootConfig,\n lifecycle: coreServices.lifecycle,\n pluginMetadata: coreServices.pluginMetadata,\n },\n async createRootContext({ config }) {\n return config.getOptional('backend.database')\n ? DatabaseManager.fromConfig(config)\n : DatabaseManager.fromConfig(\n new ConfigReader({\n backend: {\n database: { client: 'better-sqlite3', connection: ':memory:' },\n },\n }),\n );\n },\n async factory({ pluginMetadata, lifecycle }, databaseManager) {\n return databaseManager.forPlugin(pluginMetadata.getId(), {\n pluginMetadata,\n lifecycle,\n });\n },\n});\n"],"names":["createServiceFactory","coreServices","config","DatabaseManager","ConfigReader"],"mappings":";;;;;;AA0BO,MAAM,yBAAyBA,qCAAqB,CAAA;AAAA,EACzD,SAASC,6BAAa,CAAA,QAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACJ,QAAQA,6BAAa,CAAA,UAAA;AAAA,IACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,IACxB,gBAAgBA,6BAAa,CAAA,cAAA;AAAA,GAC/B;AAAA,EACA,MAAM,iBAAA,CAAkB,UAAEC,QAAA,EAAU,EAAA;AAClC,IAAO,OAAAA,QAAA,CAAO,YAAY,kBAAkB,CAAA,GACxCC,8BAAgB,UAAW,CAAAD,QAAM,IACjCC,6BAAgB,CAAA,UAAA;AAAA,MACd,IAAIC,mBAAa,CAAA;AAAA,QACf,OAAS,EAAA;AAAA,UACP,QAAU,EAAA,EAAE,MAAQ,EAAA,gBAAA,EAAkB,YAAY,UAAW,EAAA;AAAA,SAC/D;AAAA,OACD,CAAA;AAAA,KACH,CAAA;AAAA,GACN;AAAA,EACA,MAAM,OAAQ,CAAA,EAAE,cAAgB,EAAA,SAAA,IAAa,eAAiB,EAAA;AAC5D,IAAA,OAAO,eAAgB,CAAA,SAAA,CAAU,cAAe,CAAA,KAAA,EAAS,EAAA;AAAA,MACvD,cAAA;AAAA,MACA,SAAA;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import * as _backstage_backend_common from '@backstage/backend-common';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
declare const databaseServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_common.PluginDatabaseManager, "plugin">;
|
|
8
|
+
|
|
9
|
+
export { databaseServiceFactory };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var backendAppApi = require('@backstage/backend-app-api');
|
|
5
|
+
|
|
6
|
+
class HostDiscovery {
|
|
7
|
+
constructor(internalBaseUrl, externalBaseUrl, discoveryConfig) {
|
|
8
|
+
this.internalBaseUrl = internalBaseUrl;
|
|
9
|
+
this.externalBaseUrl = externalBaseUrl;
|
|
10
|
+
this.discoveryConfig = discoveryConfig;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new HostDiscovery discovery instance by reading
|
|
14
|
+
* from the `backend` config section, specifically the `.baseUrl` for
|
|
15
|
+
* discovering the external URL, and the `.listen` and `.https` config
|
|
16
|
+
* for the internal one.
|
|
17
|
+
*
|
|
18
|
+
* Can be overridden in config by providing a target and corresponding plugins in `discovery.endpoints`.
|
|
19
|
+
* eg.
|
|
20
|
+
* ```yaml
|
|
21
|
+
* discovery:
|
|
22
|
+
* endpoints:
|
|
23
|
+
* - target: https://internal.example.com/internal-catalog
|
|
24
|
+
* plugins: [catalog]
|
|
25
|
+
* - target: https://internal.example.com/secure/api/{{pluginId}}
|
|
26
|
+
* plugins: [auth, permission]
|
|
27
|
+
* - target:
|
|
28
|
+
* internal: https://internal.example.com/search
|
|
29
|
+
* external: https://example.com/search
|
|
30
|
+
* plugins: [search]
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* The basePath defaults to `/api`, meaning the default full internal
|
|
34
|
+
* path for the `catalog` plugin will be `http://localhost:7007/api/catalog`.
|
|
35
|
+
*/
|
|
36
|
+
static fromConfig(config, options) {
|
|
37
|
+
const basePath = options?.basePath ?? "/api";
|
|
38
|
+
const externalBaseUrl = config.getString("backend.baseUrl").replace(/\/+$/, "");
|
|
39
|
+
const {
|
|
40
|
+
listen: { host: listenHost = "::", port: listenPort }
|
|
41
|
+
} = backendAppApi.readHttpServerOptions(config.getConfig("backend"));
|
|
42
|
+
const protocol = config.has("backend.https") ? "https" : "http";
|
|
43
|
+
let host = listenHost;
|
|
44
|
+
if (host === "::" || host === "") {
|
|
45
|
+
host = "localhost";
|
|
46
|
+
} else if (host === "0.0.0.0") {
|
|
47
|
+
host = "127.0.0.1";
|
|
48
|
+
}
|
|
49
|
+
if (host.includes(":")) {
|
|
50
|
+
host = `[${host}]`;
|
|
51
|
+
}
|
|
52
|
+
const internalBaseUrl = `${protocol}://${host}:${listenPort}`;
|
|
53
|
+
return new HostDiscovery(
|
|
54
|
+
internalBaseUrl + basePath,
|
|
55
|
+
externalBaseUrl + basePath,
|
|
56
|
+
config.getOptionalConfig("discovery")
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
getTargetFromConfig(pluginId, type) {
|
|
60
|
+
const endpoints = this.discoveryConfig?.getOptionalConfigArray("endpoints");
|
|
61
|
+
const target = endpoints?.find((endpoint) => endpoint.getStringArray("plugins").includes(pluginId))?.get("target");
|
|
62
|
+
if (!target) {
|
|
63
|
+
const baseUrl = type === "external" ? this.externalBaseUrl : this.internalBaseUrl;
|
|
64
|
+
return `${baseUrl}/${encodeURIComponent(pluginId)}`;
|
|
65
|
+
}
|
|
66
|
+
if (typeof target === "string") {
|
|
67
|
+
return target.replace(
|
|
68
|
+
/\{\{\s*pluginId\s*\}\}/g,
|
|
69
|
+
encodeURIComponent(pluginId)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return target[type].replace(
|
|
73
|
+
/\{\{\s*pluginId\s*\}\}/g,
|
|
74
|
+
encodeURIComponent(pluginId)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
async getBaseUrl(pluginId) {
|
|
78
|
+
return this.getTargetFromConfig(pluginId, "internal");
|
|
79
|
+
}
|
|
80
|
+
async getExternalBaseUrl(pluginId) {
|
|
81
|
+
return this.getTargetFromConfig(pluginId, "external");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const discoveryServiceFactory = backendPluginApi.createServiceFactory({
|
|
86
|
+
service: backendPluginApi.coreServices.discovery,
|
|
87
|
+
deps: {
|
|
88
|
+
config: backendPluginApi.coreServices.rootConfig
|
|
89
|
+
},
|
|
90
|
+
async factory({ config }) {
|
|
91
|
+
return HostDiscovery.fromConfig(config);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
exports.HostDiscovery = HostDiscovery;
|
|
96
|
+
exports.discoveryServiceFactory = discoveryServiceFactory;
|
|
97
|
+
//# sourceMappingURL=discovery.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.cjs.js","sources":["../src/entrypoints/discovery/HostDiscovery.ts","../src/entrypoints/discovery/discoveryServiceFactory.ts"],"sourcesContent":["/*\n * Copyright 2020 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 { Config } from '@backstage/config';\nimport { readHttpServerOptions } from '@backstage/backend-app-api';\nimport { DiscoveryService } from '@backstage/backend-plugin-api';\n\ntype Target = string | { internal: string; external: string };\n\n/**\n * HostDiscovery is a basic PluginEndpointDiscovery implementation\n * that can handle plugins that are hosted in a single or multiple deployments.\n *\n * The deployment may be scaled horizontally, as long as the external URL\n * is the same for all instances. However, internal URLs will always be\n * resolved to the same host, so there won't be any balancing of internal traffic.\n *\n * @public\n */\nexport class HostDiscovery implements DiscoveryService {\n /**\n * Creates a new HostDiscovery discovery instance by reading\n * from the `backend` config section, specifically the `.baseUrl` for\n * discovering the external URL, and the `.listen` and `.https` config\n * for the internal one.\n *\n * Can be overridden in config by providing a target and corresponding plugins in `discovery.endpoints`.\n * eg.\n * ```yaml\n * discovery:\n * endpoints:\n * - target: https://internal.example.com/internal-catalog\n * plugins: [catalog]\n * - target: https://internal.example.com/secure/api/{{pluginId}}\n * plugins: [auth, permission]\n * - target:\n * internal: https://internal.example.com/search\n * external: https://example.com/search\n * plugins: [search]\n * ```\n *\n * The basePath defaults to `/api`, meaning the default full internal\n * path for the `catalog` plugin will be `http://localhost:7007/api/catalog`.\n */\n static fromConfig(config: Config, options?: { basePath?: string }) {\n const basePath = options?.basePath ?? '/api';\n const externalBaseUrl = config\n .getString('backend.baseUrl')\n .replace(/\\/+$/, '');\n\n const {\n listen: { host: listenHost = '::', port: listenPort },\n } = readHttpServerOptions(config.getConfig('backend'));\n const protocol = config.has('backend.https') ? 'https' : 'http';\n\n // Translate bind-all to localhost, and support IPv6\n let host = listenHost;\n if (host === '::' || host === '') {\n // We use localhost instead of ::1, since IPv6-compatible systems should default\n // to using IPv6 when they see localhost, but if the system doesn't support IPv6\n // things will still work.\n host = 'localhost';\n } else if (host === '0.0.0.0') {\n host = '127.0.0.1';\n }\n if (host.includes(':')) {\n host = `[${host}]`;\n }\n\n const internalBaseUrl = `${protocol}://${host}:${listenPort}`;\n\n return new HostDiscovery(\n internalBaseUrl + basePath,\n externalBaseUrl + basePath,\n config.getOptionalConfig('discovery'),\n );\n }\n\n private constructor(\n private readonly internalBaseUrl: string,\n private readonly externalBaseUrl: string,\n private readonly discoveryConfig: Config | undefined,\n ) {}\n\n private getTargetFromConfig(pluginId: string, type: 'internal' | 'external') {\n const endpoints = this.discoveryConfig?.getOptionalConfigArray('endpoints');\n\n const target = endpoints\n ?.find(endpoint => endpoint.getStringArray('plugins').includes(pluginId))\n ?.get<Target>('target');\n\n if (!target) {\n const baseUrl =\n type === 'external' ? this.externalBaseUrl : this.internalBaseUrl;\n\n return `${baseUrl}/${encodeURIComponent(pluginId)}`;\n }\n\n if (typeof target === 'string') {\n return target.replace(\n /\\{\\{\\s*pluginId\\s*\\}\\}/g,\n encodeURIComponent(pluginId),\n );\n }\n\n return target[type].replace(\n /\\{\\{\\s*pluginId\\s*\\}\\}/g,\n encodeURIComponent(pluginId),\n );\n }\n\n async getBaseUrl(pluginId: string): Promise<string> {\n return this.getTargetFromConfig(pluginId, 'internal');\n }\n\n async getExternalBaseUrl(pluginId: string): Promise<string> {\n return this.getTargetFromConfig(pluginId, 'external');\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 coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport { HostDiscovery } from './HostDiscovery';\n\n/** @public */\nexport const discoveryServiceFactory = createServiceFactory({\n service: coreServices.discovery,\n deps: {\n config: coreServices.rootConfig,\n },\n async factory({ config }) {\n return HostDiscovery.fromConfig(config);\n },\n});\n"],"names":["readHttpServerOptions","createServiceFactory","coreServices"],"mappings":"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"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
|
3
|
+
import { Config } from '@backstage/config';
|
|
4
|
+
|
|
5
|
+
/** @public */
|
|
6
|
+
declare const discoveryServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.DiscoveryService, "plugin">;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* HostDiscovery is a basic PluginEndpointDiscovery implementation
|
|
10
|
+
* that can handle plugins that are hosted in a single or multiple deployments.
|
|
11
|
+
*
|
|
12
|
+
* The deployment may be scaled horizontally, as long as the external URL
|
|
13
|
+
* is the same for all instances. However, internal URLs will always be
|
|
14
|
+
* resolved to the same host, so there won't be any balancing of internal traffic.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
declare class HostDiscovery implements DiscoveryService {
|
|
19
|
+
private readonly internalBaseUrl;
|
|
20
|
+
private readonly externalBaseUrl;
|
|
21
|
+
private readonly discoveryConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new HostDiscovery discovery instance by reading
|
|
24
|
+
* from the `backend` config section, specifically the `.baseUrl` for
|
|
25
|
+
* discovering the external URL, and the `.listen` and `.https` config
|
|
26
|
+
* for the internal one.
|
|
27
|
+
*
|
|
28
|
+
* Can be overridden in config by providing a target and corresponding plugins in `discovery.endpoints`.
|
|
29
|
+
* eg.
|
|
30
|
+
* ```yaml
|
|
31
|
+
* discovery:
|
|
32
|
+
* endpoints:
|
|
33
|
+
* - target: https://internal.example.com/internal-catalog
|
|
34
|
+
* plugins: [catalog]
|
|
35
|
+
* - target: https://internal.example.com/secure/api/{{pluginId}}
|
|
36
|
+
* plugins: [auth, permission]
|
|
37
|
+
* - target:
|
|
38
|
+
* internal: https://internal.example.com/search
|
|
39
|
+
* external: https://example.com/search
|
|
40
|
+
* plugins: [search]
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* The basePath defaults to `/api`, meaning the default full internal
|
|
44
|
+
* path for the `catalog` plugin will be `http://localhost:7007/api/catalog`.
|
|
45
|
+
*/
|
|
46
|
+
static fromConfig(config: Config, options?: {
|
|
47
|
+
basePath?: string;
|
|
48
|
+
}): HostDiscovery;
|
|
49
|
+
private constructor();
|
|
50
|
+
private getTargetFromConfig;
|
|
51
|
+
getBaseUrl(pluginId: string): Promise<string>;
|
|
52
|
+
getExternalBaseUrl(pluginId: string): Promise<string>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { HostDiscovery, discoveryServiceFactory };
|
package/dist/index.cjs.js
CHANGED
|
@@ -2,27 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
require('@backstage/backend-common');
|
|
4
4
|
var backendAppApi = require('@backstage/backend-app-api');
|
|
5
|
+
var cache = require('@backstage/backend-defaults/cache');
|
|
6
|
+
var database = require('@backstage/backend-defaults/database');
|
|
7
|
+
var discovery = require('@backstage/backend-defaults/discovery');
|
|
8
|
+
var lifecycle = require('@backstage/backend-defaults/lifecycle');
|
|
9
|
+
var permissions = require('@backstage/backend-defaults/permissions');
|
|
10
|
+
var rootConfig = require('@backstage/backend-defaults/rootConfig');
|
|
11
|
+
var rootLifecycle = require('@backstage/backend-defaults/rootLifecycle');
|
|
12
|
+
var scheduler = require('@backstage/backend-defaults/scheduler');
|
|
13
|
+
var urlReader = require('@backstage/backend-defaults/urlReader');
|
|
5
14
|
var pluginEventsNode = require('@backstage/plugin-events-node');
|
|
6
15
|
|
|
7
16
|
const defaultServiceFactories = [
|
|
8
17
|
backendAppApi.authServiceFactory(),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
cache.cacheServiceFactory(),
|
|
19
|
+
rootConfig.rootConfigServiceFactory(),
|
|
20
|
+
database.databaseServiceFactory(),
|
|
21
|
+
discovery.discoveryServiceFactory(),
|
|
13
22
|
backendAppApi.httpAuthServiceFactory(),
|
|
14
23
|
backendAppApi.httpRouterServiceFactory(),
|
|
15
24
|
backendAppApi.identityServiceFactory(),
|
|
16
|
-
|
|
25
|
+
lifecycle.lifecycleServiceFactory(),
|
|
17
26
|
backendAppApi.loggerServiceFactory(),
|
|
18
|
-
|
|
27
|
+
permissions.permissionsServiceFactory(),
|
|
19
28
|
backendAppApi.rootHttpRouterServiceFactory(),
|
|
20
|
-
|
|
29
|
+
rootLifecycle.rootLifecycleServiceFactory(),
|
|
21
30
|
backendAppApi.rootLoggerServiceFactory(),
|
|
22
|
-
|
|
31
|
+
scheduler.schedulerServiceFactory(),
|
|
23
32
|
backendAppApi.tokenManagerServiceFactory(),
|
|
24
33
|
backendAppApi.userInfoServiceFactory(),
|
|
25
|
-
|
|
34
|
+
urlReader.urlReaderServiceFactory(),
|
|
26
35
|
pluginEventsNode.eventsServiceFactory()
|
|
27
36
|
];
|
|
28
37
|
function createBackend() {
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/CreateBackend.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 Backend,\n
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/CreateBackend.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 Backend,\n authServiceFactory,\n createSpecializedBackend,\n httpAuthServiceFactory,\n httpRouterServiceFactory,\n identityServiceFactory,\n loggerServiceFactory,\n rootHttpRouterServiceFactory,\n rootLoggerServiceFactory,\n tokenManagerServiceFactory,\n userInfoServiceFactory,\n} from '@backstage/backend-app-api';\nimport { cacheServiceFactory } from '@backstage/backend-defaults/cache';\nimport { databaseServiceFactory } from '@backstage/backend-defaults/database';\nimport { discoveryServiceFactory } from '@backstage/backend-defaults/discovery';\nimport { lifecycleServiceFactory } from '@backstage/backend-defaults/lifecycle';\nimport { permissionsServiceFactory } from '@backstage/backend-defaults/permissions';\nimport { rootConfigServiceFactory } from '@backstage/backend-defaults/rootConfig';\nimport { rootLifecycleServiceFactory } from '@backstage/backend-defaults/rootLifecycle';\nimport { schedulerServiceFactory } from '@backstage/backend-defaults/scheduler';\nimport { urlReaderServiceFactory } from '@backstage/backend-defaults/urlReader';\nimport { eventsServiceFactory } from '@backstage/plugin-events-node';\n\nexport const defaultServiceFactories = [\n authServiceFactory(),\n cacheServiceFactory(),\n rootConfigServiceFactory(),\n databaseServiceFactory(),\n discoveryServiceFactory(),\n httpAuthServiceFactory(),\n httpRouterServiceFactory(),\n identityServiceFactory(),\n lifecycleServiceFactory(),\n loggerServiceFactory(),\n permissionsServiceFactory(),\n rootHttpRouterServiceFactory(),\n rootLifecycleServiceFactory(),\n rootLoggerServiceFactory(),\n schedulerServiceFactory(),\n tokenManagerServiceFactory(),\n userInfoServiceFactory(),\n urlReaderServiceFactory(),\n eventsServiceFactory(),\n];\n\n/**\n * @public\n */\nexport function createBackend(): Backend {\n return createSpecializedBackend({ defaultServiceFactories });\n}\n"],"names":["authServiceFactory","cacheServiceFactory","rootConfigServiceFactory","databaseServiceFactory","discoveryServiceFactory","httpAuthServiceFactory","httpRouterServiceFactory","identityServiceFactory","lifecycleServiceFactory","loggerServiceFactory","permissionsServiceFactory","rootHttpRouterServiceFactory","rootLifecycleServiceFactory","rootLoggerServiceFactory","schedulerServiceFactory","tokenManagerServiceFactory","userInfoServiceFactory","urlReaderServiceFactory","eventsServiceFactory","createSpecializedBackend"],"mappings":";;;;;;;;;;;;;;;AAwCO,MAAM,uBAA0B,GAAA;AAAA,EACrCA,gCAAmB,EAAA;AAAA,EACnBC,yBAAoB,EAAA;AAAA,EACpBC,mCAAyB,EAAA;AAAA,EACzBC,+BAAuB,EAAA;AAAA,EACvBC,iCAAwB,EAAA;AAAA,EACxBC,oCAAuB,EAAA;AAAA,EACvBC,sCAAyB,EAAA;AAAA,EACzBC,oCAAuB,EAAA;AAAA,EACvBC,iCAAwB,EAAA;AAAA,EACxBC,kCAAqB,EAAA;AAAA,EACrBC,qCAA0B,EAAA;AAAA,EAC1BC,0CAA6B,EAAA;AAAA,EAC7BC,yCAA4B,EAAA;AAAA,EAC5BC,sCAAyB,EAAA;AAAA,EACzBC,iCAAwB,EAAA;AAAA,EACxBC,wCAA2B,EAAA;AAAA,EAC3BC,oCAAuB,EAAA;AAAA,EACvBC,iCAAwB,EAAA;AAAA,EACxBC,qCAAqB,EAAA;AACvB,CAAA,CAAA;AAKO,SAAS,aAAyB,GAAA;AACvC,EAAO,OAAAC,sCAAA,CAAyB,EAAE,uBAAA,EAAyB,CAAA,CAAA;AAC7D;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
|
|
5
|
+
class BackendPluginLifecycleImpl {
|
|
6
|
+
constructor(logger, rootLifecycle, pluginMetadata) {
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
this.rootLifecycle = rootLifecycle;
|
|
9
|
+
this.pluginMetadata = pluginMetadata;
|
|
10
|
+
}
|
|
11
|
+
#hasStarted = false;
|
|
12
|
+
#startupTasks = [];
|
|
13
|
+
addStartupHook(hook, options) {
|
|
14
|
+
if (this.#hasStarted) {
|
|
15
|
+
throw new Error("Attempted to add startup hook after startup");
|
|
16
|
+
}
|
|
17
|
+
this.#startupTasks.push({ hook, options });
|
|
18
|
+
}
|
|
19
|
+
async startup() {
|
|
20
|
+
if (this.#hasStarted) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this.#hasStarted = true;
|
|
24
|
+
this.logger.debug(
|
|
25
|
+
`Running ${this.#startupTasks.length} plugin startup tasks...`
|
|
26
|
+
);
|
|
27
|
+
await Promise.all(
|
|
28
|
+
this.#startupTasks.map(async ({ hook, options }) => {
|
|
29
|
+
const logger = options?.logger ?? this.logger;
|
|
30
|
+
try {
|
|
31
|
+
await hook();
|
|
32
|
+
logger.debug(`Plugin startup hook succeeded`);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
logger.error(`Plugin startup hook failed, ${error}`);
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
addShutdownHook(hook, options) {
|
|
40
|
+
const plugin = this.pluginMetadata.getId();
|
|
41
|
+
this.rootLifecycle.addShutdownHook(hook, {
|
|
42
|
+
logger: options?.logger?.child({ plugin }) ?? this.logger
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const lifecycleServiceFactory = backendPluginApi.createServiceFactory({
|
|
47
|
+
service: backendPluginApi.coreServices.lifecycle,
|
|
48
|
+
deps: {
|
|
49
|
+
logger: backendPluginApi.coreServices.logger,
|
|
50
|
+
rootLifecycle: backendPluginApi.coreServices.rootLifecycle,
|
|
51
|
+
pluginMetadata: backendPluginApi.coreServices.pluginMetadata
|
|
52
|
+
},
|
|
53
|
+
async factory({ rootLifecycle, logger, pluginMetadata }) {
|
|
54
|
+
return new BackendPluginLifecycleImpl(
|
|
55
|
+
logger,
|
|
56
|
+
rootLifecycle,
|
|
57
|
+
pluginMetadata
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
exports.lifecycleServiceFactory = lifecycleServiceFactory;
|
|
63
|
+
//# sourceMappingURL=lifecycle.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.cjs.js","sources":["../src/entrypoints/lifecycle/lifecycleServiceFactory.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 LifecycleService,\n LifecycleServiceShutdownHook,\n LifecycleServiceShutdownOptions,\n LifecycleServiceStartupHook,\n LifecycleServiceStartupOptions,\n LoggerService,\n PluginMetadataService,\n RootLifecycleService,\n coreServices,\n createServiceFactory,\n} from '@backstage/backend-plugin-api';\n\n/** @internal */\nexport class BackendPluginLifecycleImpl implements LifecycleService {\n constructor(\n private readonly logger: LoggerService,\n private readonly rootLifecycle: RootLifecycleService,\n private readonly pluginMetadata: PluginMetadataService,\n ) {}\n\n #hasStarted = false;\n #startupTasks: Array<{\n hook: LifecycleServiceStartupHook;\n options?: LifecycleServiceStartupOptions;\n }> = [];\n\n addStartupHook(\n hook: LifecycleServiceStartupHook,\n options?: LifecycleServiceStartupOptions,\n ): void {\n if (this.#hasStarted) {\n throw new Error('Attempted to add startup hook after startup');\n }\n this.#startupTasks.push({ hook, options });\n }\n\n async startup(): Promise<void> {\n if (this.#hasStarted) {\n return;\n }\n this.#hasStarted = true;\n\n this.logger.debug(\n `Running ${this.#startupTasks.length} plugin startup tasks...`,\n );\n await Promise.all(\n this.#startupTasks.map(async ({ hook, options }) => {\n const logger = options?.logger ?? this.logger;\n try {\n await hook();\n logger.debug(`Plugin startup hook succeeded`);\n } catch (error) {\n logger.error(`Plugin startup hook failed, ${error}`);\n }\n }),\n );\n }\n\n addShutdownHook(\n hook: LifecycleServiceShutdownHook,\n options?: LifecycleServiceShutdownOptions,\n ): void {\n const plugin = this.pluginMetadata.getId();\n this.rootLifecycle.addShutdownHook(hook, {\n logger: options?.logger?.child({ plugin }) ?? this.logger,\n });\n }\n}\n\n/**\n * Allows plugins to register shutdown hooks that are run when the process is about to exit.\n *\n * @public\n */\nexport const lifecycleServiceFactory = createServiceFactory({\n service: coreServices.lifecycle,\n deps: {\n logger: coreServices.logger,\n rootLifecycle: coreServices.rootLifecycle,\n pluginMetadata: coreServices.pluginMetadata,\n },\n async factory({ rootLifecycle, logger, pluginMetadata }) {\n return new BackendPluginLifecycleImpl(\n logger,\n rootLifecycle,\n pluginMetadata,\n );\n },\n});\n"],"names":["createServiceFactory","coreServices"],"mappings":";;;;AA8BO,MAAM,0BAAuD,CAAA;AAAA,EAClE,WAAA,CACmB,MACA,EAAA,aAAA,EACA,cACjB,EAAA;AAHiB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AACA,IAAA,IAAA,CAAA,aAAA,GAAA,aAAA,CAAA;AACA,IAAA,IAAA,CAAA,cAAA,GAAA,cAAA,CAAA;AAAA,GAChB;AAAA,EAEH,WAAc,GAAA,KAAA,CAAA;AAAA,EACd,gBAGK,EAAC,CAAA;AAAA,EAEN,cAAA,CACE,MACA,OACM,EAAA;AACN,IAAA,IAAI,KAAK,WAAa,EAAA;AACpB,MAAM,MAAA,IAAI,MAAM,6CAA6C,CAAA,CAAA;AAAA,KAC/D;AACA,IAAA,IAAA,CAAK,aAAc,CAAA,IAAA,CAAK,EAAE,IAAA,EAAM,SAAS,CAAA,CAAA;AAAA,GAC3C;AAAA,EAEA,MAAM,OAAyB,GAAA;AAC7B,IAAA,IAAI,KAAK,WAAa,EAAA;AACpB,MAAA,OAAA;AAAA,KACF;AACA,IAAA,IAAA,CAAK,WAAc,GAAA,IAAA,CAAA;AAEnB,IAAA,IAAA,CAAK,MAAO,CAAA,KAAA;AAAA,MACV,CAAA,QAAA,EAAW,IAAK,CAAA,aAAA,CAAc,MAAM,CAAA,wBAAA,CAAA;AAAA,KACtC,CAAA;AACA,IAAA,MAAM,OAAQ,CAAA,GAAA;AAAA,MACZ,KAAK,aAAc,CAAA,GAAA,CAAI,OAAO,EAAE,IAAA,EAAM,SAAc,KAAA;AAClD,QAAM,MAAA,MAAA,GAAS,OAAS,EAAA,MAAA,IAAU,IAAK,CAAA,MAAA,CAAA;AACvC,QAAI,IAAA;AACF,UAAA,MAAM,IAAK,EAAA,CAAA;AACX,UAAA,MAAA,CAAO,MAAM,CAA+B,6BAAA,CAAA,CAAA,CAAA;AAAA,iBACrC,KAAO,EAAA;AACd,UAAO,MAAA,CAAA,KAAA,CAAM,CAA+B,4BAAA,EAAA,KAAK,CAAE,CAAA,CAAA,CAAA;AAAA,SACrD;AAAA,OACD,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AAAA,EAEA,eAAA,CACE,MACA,OACM,EAAA;AACN,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,cAAA,CAAe,KAAM,EAAA,CAAA;AACzC,IAAK,IAAA,CAAA,aAAA,CAAc,gBAAgB,IAAM,EAAA;AAAA,MACvC,MAAA,EAAQ,SAAS,MAAQ,EAAA,KAAA,CAAM,EAAE,MAAO,EAAC,KAAK,IAAK,CAAA,MAAA;AAAA,KACpD,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAOO,MAAM,0BAA0BA,qCAAqB,CAAA;AAAA,EAC1D,SAASC,6BAAa,CAAA,SAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACJ,QAAQA,6BAAa,CAAA,MAAA;AAAA,IACrB,eAAeA,6BAAa,CAAA,aAAA;AAAA,IAC5B,gBAAgBA,6BAAa,CAAA,cAAA;AAAA,GAC/B;AAAA,EACA,MAAM,OAAQ,CAAA,EAAE,aAAe,EAAA,MAAA,EAAQ,gBAAkB,EAAA;AACvD,IAAA,OAAO,IAAI,0BAAA;AAAA,MACT,MAAA;AAAA,MACA,aAAA;AAAA,MACA,cAAA;AAAA,KACF,CAAA;AAAA,GACF;AACF,CAAC;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { LifecycleService } from '@backstage/backend-plugin-api';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Allows plugins to register shutdown hooks that are run when the process is about to exit.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
declare const lifecycleServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<LifecycleService, "plugin">;
|
|
10
|
+
|
|
11
|
+
export { lifecycleServiceFactory };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var pluginPermissionNode = require('@backstage/plugin-permission-node');
|
|
5
|
+
|
|
6
|
+
const permissionsServiceFactory = backendPluginApi.createServiceFactory({
|
|
7
|
+
service: backendPluginApi.coreServices.permissions,
|
|
8
|
+
deps: {
|
|
9
|
+
auth: backendPluginApi.coreServices.auth,
|
|
10
|
+
config: backendPluginApi.coreServices.rootConfig,
|
|
11
|
+
discovery: backendPluginApi.coreServices.discovery,
|
|
12
|
+
tokenManager: backendPluginApi.coreServices.tokenManager
|
|
13
|
+
},
|
|
14
|
+
async factory({ auth, config, discovery, tokenManager }) {
|
|
15
|
+
return pluginPermissionNode.ServerPermissionClient.fromConfig(config, {
|
|
16
|
+
auth,
|
|
17
|
+
discovery,
|
|
18
|
+
tokenManager
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
exports.permissionsServiceFactory = permissionsServiceFactory;
|
|
24
|
+
//# sourceMappingURL=permissions.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.cjs.js","sources":["../src/entrypoints/permissions/permissionsServiceFactory.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 createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport { ServerPermissionClient } from '@backstage/plugin-permission-node';\n\n/**\n * @public\n */\nexport const permissionsServiceFactory = createServiceFactory({\n service: coreServices.permissions,\n deps: {\n auth: coreServices.auth,\n config: coreServices.rootConfig,\n discovery: coreServices.discovery,\n tokenManager: coreServices.tokenManager,\n },\n async factory({ auth, config, discovery, tokenManager }) {\n return ServerPermissionClient.fromConfig(config, {\n auth,\n discovery,\n tokenManager,\n });\n },\n});\n"],"names":["createServiceFactory","coreServices","ServerPermissionClient"],"mappings":";;;;;AAyBO,MAAM,4BAA4BA,qCAAqB,CAAA;AAAA,EAC5D,SAASC,6BAAa,CAAA,WAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACJ,MAAMA,6BAAa,CAAA,IAAA;AAAA,IACnB,QAAQA,6BAAa,CAAA,UAAA;AAAA,IACrB,WAAWA,6BAAa,CAAA,SAAA;AAAA,IACxB,cAAcA,6BAAa,CAAA,YAAA;AAAA,GAC7B;AAAA,EACA,MAAM,OAAQ,CAAA,EAAE,MAAM,MAAQ,EAAA,SAAA,EAAW,cAAgB,EAAA;AACvD,IAAO,OAAAC,2CAAA,CAAuB,WAAW,MAAQ,EAAA;AAAA,MAC/C,IAAA;AAAA,MACA,SAAA;AAAA,MACA,YAAA;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
declare const permissionsServiceFactory: () => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.PermissionsService, "plugin">;
|
|
7
|
+
|
|
8
|
+
export { permissionsServiceFactory };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
4
|
+
var configLoader = require('@backstage/config-loader');
|
|
5
|
+
|
|
6
|
+
const rootConfigServiceFactory = backendPluginApi.createServiceFactory(
|
|
7
|
+
(options) => ({
|
|
8
|
+
service: backendPluginApi.coreServices.rootConfig,
|
|
9
|
+
deps: {},
|
|
10
|
+
async factory() {
|
|
11
|
+
const source = configLoader.ConfigSources.default({
|
|
12
|
+
argv: options?.argv,
|
|
13
|
+
remote: options?.remote,
|
|
14
|
+
watch: options?.watch
|
|
15
|
+
});
|
|
16
|
+
console.log(`Loading config from ${source}`);
|
|
17
|
+
return await configLoader.ConfigSources.toConfig(source);
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
exports.rootConfigServiceFactory = rootConfigServiceFactory;
|
|
23
|
+
//# sourceMappingURL=rootConfig.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rootConfig.cjs.js","sources":["../src/entrypoints/rootConfig/rootConfigServiceFactory.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 createServiceFactory,\n} from '@backstage/backend-plugin-api';\nimport {\n ConfigSources,\n RemoteConfigSourceOptions,\n} from '@backstage/config-loader';\n\n/**\n * @public\n */\nexport interface RootConfigFactoryOptions {\n /**\n * Process arguments to use instead of the default `process.argv()`.\n */\n argv?: string[];\n\n /**\n * Enables and sets options for remote configuration loading.\n */\n remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;\n watch?: boolean;\n}\n\n/**\n * @public\n */\nexport const rootConfigServiceFactory = createServiceFactory(\n (options?: RootConfigFactoryOptions) => ({\n service: coreServices.rootConfig,\n deps: {},\n async factory() {\n const source = ConfigSources.default({\n argv: options?.argv,\n remote: options?.remote,\n watch: options?.watch,\n });\n console.log(`Loading config from ${source}`);\n return await ConfigSources.toConfig(source);\n },\n }),\n);\n"],"names":["createServiceFactory","coreServices","ConfigSources"],"mappings":";;;;;AA4CO,MAAM,wBAA2B,GAAAA,qCAAA;AAAA,EACtC,CAAC,OAAwC,MAAA;AAAA,IACvC,SAASC,6BAAa,CAAA,UAAA;AAAA,IACtB,MAAM,EAAC;AAAA,IACP,MAAM,OAAU,GAAA;AACd,MAAM,MAAA,MAAA,GAASC,2BAAc,OAAQ,CAAA;AAAA,QACnC,MAAM,OAAS,EAAA,IAAA;AAAA,QACf,QAAQ,OAAS,EAAA,MAAA;AAAA,QACjB,OAAO,OAAS,EAAA,KAAA;AAAA,OACjB,CAAA,CAAA;AACD,MAAQ,OAAA,CAAA,GAAA,CAAI,CAAuB,oBAAA,EAAA,MAAM,CAAE,CAAA,CAAA,CAAA;AAC3C,MAAO,OAAA,MAAMA,0BAAc,CAAA,QAAA,CAAS,MAAM,CAAA,CAAA;AAAA,KAC5C;AAAA,GACF,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { RemoteConfigSourceOptions } from '@backstage/config-loader';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
interface RootConfigFactoryOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Process arguments to use instead of the default `process.argv()`.
|
|
10
|
+
*/
|
|
11
|
+
argv?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Enables and sets options for remote configuration loading.
|
|
14
|
+
*/
|
|
15
|
+
remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;
|
|
16
|
+
watch?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
declare const rootConfigServiceFactory: (options?: RootConfigFactoryOptions | undefined) => _backstage_backend_plugin_api.ServiceFactory<_backstage_backend_plugin_api.RootConfigService, "root">;
|
|
22
|
+
|
|
23
|
+
export { type RootConfigFactoryOptions, rootConfigServiceFactory };
|