@backstage/plugin-catalog-backend-module-unprocessed 0.0.0-nightly-20240322021005 → 0.0.0-nightly-20240323021043
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 +29 -5
- package/dist/index.cjs.js +6 -7
- package/dist/index.cjs.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
# @backstage/plugin-catalog-backend-module-unprocessed
|
|
2
2
|
|
|
3
|
-
## 0.0.0-nightly-
|
|
3
|
+
## 0.0.0-nightly-20240323021043
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- f3e2e86: Internal update that injects custom permissions into the catalog using its extension point
|
|
7
8
|
- Updated dependencies
|
|
8
|
-
- @backstage/
|
|
9
|
-
- @backstage/
|
|
10
|
-
- @backstage/plugin-
|
|
11
|
-
- @backstage/backend-plugin-api@0.0.0-nightly-
|
|
9
|
+
- @backstage/plugin-catalog-node@0.0.0-nightly-20240323021043
|
|
10
|
+
- @backstage/backend-common@0.0.0-nightly-20240323021043
|
|
11
|
+
- @backstage/plugin-auth-node@0.0.0-nightly-20240323021043
|
|
12
|
+
- @backstage/backend-plugin-api@0.0.0-nightly-20240323021043
|
|
12
13
|
- @backstage/catalog-model@1.4.5
|
|
13
14
|
- @backstage/errors@1.2.4
|
|
14
15
|
- @backstage/plugin-catalog-unprocessed-entities-common@0.0.1
|
|
15
16
|
- @backstage/plugin-permission-common@0.7.13
|
|
16
17
|
|
|
18
|
+
## 0.4.2
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- f3e2e86: Internal update that injects custom permissions into the catalog using its extension point
|
|
23
|
+
- Updated dependencies
|
|
24
|
+
- @backstage/plugin-catalog-node@1.10.0
|
|
25
|
+
- @backstage/backend-common@0.21.5
|
|
26
|
+
- @backstage/plugin-auth-node@0.4.10
|
|
27
|
+
- @backstage/backend-plugin-api@0.6.15
|
|
28
|
+
- @backstage/catalog-model@1.4.5
|
|
29
|
+
- @backstage/errors@1.2.4
|
|
30
|
+
- @backstage/plugin-catalog-unprocessed-entities-common@0.0.1
|
|
31
|
+
- @backstage/plugin-permission-common@0.7.13
|
|
32
|
+
|
|
33
|
+
## 0.4.1
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 9c7fb30: Internal update that injects custom permissions into the catalog using its extension point
|
|
38
|
+
- Updated dependencies
|
|
39
|
+
- @backstage/plugin-catalog-node@1.9.0
|
|
40
|
+
|
|
17
41
|
## 0.4.0
|
|
18
42
|
|
|
19
43
|
### Minor Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
6
|
var Router = require('express-promise-router');
|
|
7
7
|
var pluginPermissionCommon = require('@backstage/plugin-permission-common');
|
|
8
|
-
var pluginPermissionNode = require('@backstage/plugin-permission-node');
|
|
9
8
|
var pluginCatalogUnprocessedEntitiesCommon = require('@backstage/plugin-catalog-unprocessed-entities-common');
|
|
10
9
|
var errors = require('@backstage/errors');
|
|
11
10
|
var backendCommon = require('@backstage/backend-common');
|
|
11
|
+
var alpha = require('@backstage/plugin-catalog-node/alpha');
|
|
12
12
|
|
|
13
13
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
14
14
|
|
|
@@ -95,16 +95,12 @@ class UnprocessedEntitiesModule {
|
|
|
95
95
|
return res;
|
|
96
96
|
}
|
|
97
97
|
registerRoutes() {
|
|
98
|
-
const permissionIntegrationRouter = pluginPermissionNode.createPermissionIntegrationRouter({
|
|
99
|
-
permissions: [pluginCatalogUnprocessedEntitiesCommon.unprocessedEntitiesDeletePermission]
|
|
100
|
-
});
|
|
101
98
|
const isRequestAuthorized = async (req, permission) => {
|
|
102
99
|
const decision = (await this.permissions.authorize([{ permission }], {
|
|
103
100
|
credentials: await this.httpAuth.credentials(req)
|
|
104
101
|
}))[0];
|
|
105
102
|
return decision.result !== pluginPermissionCommon.AuthorizeResult.DENY;
|
|
106
103
|
};
|
|
107
|
-
this.router.use(permissionIntegrationRouter);
|
|
108
104
|
this.moduleRouter.get("/entities/unprocessed/failed", async (req, res) => {
|
|
109
105
|
return res.json(
|
|
110
106
|
await this.unprocessed({
|
|
@@ -147,7 +143,8 @@ const catalogModuleUnprocessedEntities = backendPluginApi.createBackendModule({
|
|
|
147
143
|
logger: backendPluginApi.coreServices.logger,
|
|
148
144
|
httpAuth: backendPluginApi.coreServices.httpAuth,
|
|
149
145
|
discovery: backendPluginApi.coreServices.discovery,
|
|
150
|
-
permissions: backendPluginApi.coreServices.permissions
|
|
146
|
+
permissions: backendPluginApi.coreServices.permissions,
|
|
147
|
+
catalogPermissions: alpha.catalogPermissionExtensionPoint
|
|
151
148
|
},
|
|
152
149
|
async init({
|
|
153
150
|
database,
|
|
@@ -155,7 +152,8 @@ const catalogModuleUnprocessedEntities = backendPluginApi.createBackendModule({
|
|
|
155
152
|
logger,
|
|
156
153
|
permissions,
|
|
157
154
|
httpAuth,
|
|
158
|
-
discovery
|
|
155
|
+
discovery,
|
|
156
|
+
catalogPermissions
|
|
159
157
|
}) {
|
|
160
158
|
const module = UnprocessedEntitiesModule.create({
|
|
161
159
|
database: await database.getClient(),
|
|
@@ -164,6 +162,7 @@ const catalogModuleUnprocessedEntities = backendPluginApi.createBackendModule({
|
|
|
164
162
|
discovery,
|
|
165
163
|
httpAuth
|
|
166
164
|
});
|
|
165
|
+
catalogPermissions.addPermissions(pluginCatalogUnprocessedEntitiesCommon.unprocessedEntitiesDeletePermission);
|
|
167
166
|
module.registerRoutes();
|
|
168
167
|
logger.info(
|
|
169
168
|
"registered additional routes for catalogModuleUnprocessedEntities"
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/UnprocessedEntitiesModule.ts","../src/module.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 {\n HydratedRefreshState,\n RefreshState,\n UnprocessedEntitiesRequest,\n UnprocessedEntitiesResponse,\n} from './types';\nimport { Knex } from 'knex';\nimport {\n DiscoveryService,\n HttpAuthService,\n HttpRouterService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport Router from 'express-promise-router';\nimport type { Request } from 'express';\n\nimport {\n AuthorizeResult,\n BasicPermission,\n} from '@backstage/plugin-permission-common';\nimport { createPermissionIntegrationRouter } from '@backstage/plugin-permission-node';\nimport { unprocessedEntitiesDeletePermission } from '@backstage/plugin-catalog-unprocessed-entities-common';\nimport { NotAllowedError } from '@backstage/errors';\nimport { createLegacyAuthAdapters } from '@backstage/backend-common';\n\n/**\n * Module providing Unprocessed Entities API endpoints\n *\n * @public\n */\nexport class UnprocessedEntitiesModule {\n private readonly moduleRouter;\n\n private readonly httpAuth: HttpAuthService;\n\n private constructor(\n private readonly database: Knex,\n private readonly router: Pick<HttpRouterService, 'use'>,\n private readonly permissions: PermissionsService,\n discovery: DiscoveryService,\n httpAuth?: HttpAuthService,\n ) {\n this.moduleRouter = Router();\n this.router.use(this.moduleRouter);\n\n this.httpAuth = createLegacyAuthAdapters({\n discovery,\n httpAuth,\n }).httpAuth;\n }\n\n static create(options: {\n router: Pick<HttpRouterService, 'use'>;\n database: Knex;\n discovery: DiscoveryService;\n permissions: PermissionsService;\n httpAuth?: HttpAuthService;\n }) {\n return new UnprocessedEntitiesModule(\n options.database,\n options.router,\n options.permissions,\n options.discovery,\n options.httpAuth,\n );\n }\n\n private async unprocessed(\n request: UnprocessedEntitiesRequest,\n ): Promise<UnprocessedEntitiesResponse> {\n if (request.reason === 'pending') {\n return {\n type: 'pending',\n entities: await this.pending(request.owner),\n };\n }\n return {\n type: 'failed',\n entities: await this.failed(request.owner),\n };\n }\n\n private hydrateRefreshState(r: RefreshState): HydratedRefreshState {\n return {\n ...r,\n unprocessed_entity: JSON.parse(r.unprocessed_entity),\n ...(r.processed_entity && {\n processed_entity: JSON.parse(r.processed_entity),\n }),\n ...(r.errors && { errors: JSON.parse(r.errors) }),\n ...(r.cache && { cache: JSON.parse(r.cache) }),\n };\n }\n\n private async pending(owner?: string): Promise<HydratedRefreshState[]> {\n const res = (\n await this.database('refresh_state.*')\n .from('refresh_state')\n .leftJoin(\n 'final_entities',\n 'final_entities.entity_id',\n 'refresh_state.entity_id',\n )\n .whereNull('final_entities.entity_id')\n ).map(this.hydrateRefreshState);\n if (owner) {\n return res.filter(r => r.unprocessed_entity.spec?.owner === owner);\n }\n\n return res;\n }\n\n private async failed(owner?: string): Promise<HydratedRefreshState[]> {\n const res = (\n await this.database('refresh_state.*')\n .from('refresh_state')\n .rightJoin(\n 'final_entities',\n 'final_entities.entity_id',\n 'refresh_state.entity_id',\n )\n .whereNull('final_entities.final_entity')\n ).map(this.hydrateRefreshState);\n if (owner) {\n return res.filter(r => r.unprocessed_entity.spec?.owner === owner);\n }\n\n return res;\n }\n\n registerRoutes() {\n const permissionIntegrationRouter = createPermissionIntegrationRouter({\n permissions: [unprocessedEntitiesDeletePermission],\n });\n\n const isRequestAuthorized = async (\n req: Request,\n permission: BasicPermission,\n ): Promise<boolean> => {\n const decision = (\n await this.permissions.authorize([{ permission }], {\n credentials: await this.httpAuth.credentials(req),\n })\n )[0];\n\n return decision.result !== AuthorizeResult.DENY;\n };\n\n this.router.use(permissionIntegrationRouter);\n\n this.moduleRouter\n .get('/entities/unprocessed/failed', async (req, res) => {\n return res.json(\n await this.unprocessed({\n reason: 'failed',\n owner: String(req.query.owner),\n }),\n );\n })\n .get('/entities/unprocessed/pending', async (req, res) => {\n return res.json(\n await this.unprocessed({\n reason: 'pending',\n owner: String(req.query.owner),\n }),\n );\n })\n .delete(\n '/entities/unprocessed/delete/:entity_id',\n async (request, response) => {\n const authorized = await isRequestAuthorized(\n request,\n unprocessedEntitiesDeletePermission,\n );\n\n if (!authorized) {\n throw new NotAllowedError('Unauthorized');\n }\n\n await this.database('refresh_state')\n .where({ entity_id: request.params.entity_id })\n .delete();\n\n response.status(204).send();\n },\n );\n }\n}\n","/*\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 {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { UnprocessedEntitiesModule } from './UnprocessedEntitiesModule';\n\n/**\n * Catalog Module for Unprocessed Entities\n *\n * @public\n */\nexport const catalogModuleUnprocessedEntities = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'catalog-module-unprocessed-entities',\n register(env) {\n env.registerInit({\n deps: {\n database: coreServices.database,\n router: coreServices.httpRouter,\n logger: coreServices.logger,\n httpAuth: coreServices.httpAuth,\n discovery: coreServices.discovery,\n permissions: coreServices.permissions,\n },\n async init({\n database,\n router,\n logger,\n permissions,\n httpAuth,\n discovery,\n }) {\n const module = UnprocessedEntitiesModule.create({\n database: await database.getClient(),\n router,\n permissions,\n discovery,\n httpAuth,\n });\n\n module.registerRoutes();\n\n logger.info(\n 'registered additional routes for catalogModuleUnprocessedEntities',\n );\n },\n });\n },\n});\n"],"names":["Router","createLegacyAuthAdapters","createPermissionIntegrationRouter","unprocessedEntitiesDeletePermission","AuthorizeResult","NotAllowedError","createBackendModule","coreServices"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8CO,MAAM,yBAA0B,CAAA;AAAA,EAK7B,WACW,CAAA,QAAA,EACA,MACA,EAAA,WAAA,EACjB,WACA,QACA,EAAA;AALiB,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA,CAAA;AACA,IAAA,IAAA,CAAA,WAAA,GAAA,WAAA,CAAA;AAPnB,IAAiB,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA,CAAA;AAEjB,IAAiB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AASf,IAAA,IAAA,CAAK,eAAeA,uBAAO,EAAA,CAAA;AAC3B,IAAK,IAAA,CAAA,MAAA,CAAO,GAAI,CAAA,IAAA,CAAK,YAAY,CAAA,CAAA;AAEjC,IAAA,IAAA,CAAK,WAAWC,sCAAyB,CAAA;AAAA,MACvC,SAAA;AAAA,MACA,QAAA;AAAA,KACD,CAAE,CAAA,QAAA,CAAA;AAAA,GACL;AAAA,EAEA,OAAO,OAAO,OAMX,EAAA;AACD,IAAA,OAAO,IAAI,yBAAA;AAAA,MACT,OAAQ,CAAA,QAAA;AAAA,MACR,OAAQ,CAAA,MAAA;AAAA,MACR,OAAQ,CAAA,WAAA;AAAA,MACR,OAAQ,CAAA,SAAA;AAAA,MACR,OAAQ,CAAA,QAAA;AAAA,KACV,CAAA;AAAA,GACF;AAAA,EAEA,MAAc,YACZ,OACsC,EAAA;AACtC,IAAI,IAAA,OAAA,CAAQ,WAAW,SAAW,EAAA;AAChC,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,SAAA;AAAA,QACN,QAAU,EAAA,MAAM,IAAK,CAAA,OAAA,CAAQ,QAAQ,KAAK,CAAA;AAAA,OAC5C,CAAA;AAAA,K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A,SAAA;AAAA,EACV,QAAU,EAAA,qCAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,UAAUC,6BAAa,CAAA,QAAA;AAAA,QACvB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,MAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,WAAWA,6BAAa,CAAA,SAAA;AAAA,QACxB,aAAaA,6BAAa,CAAA,WAAA;AAAA,OAC5B;AAAA,MACA,MAAM,IAAK,CAAA;AAAA,QACT,QAAA;AAAA,QACA,MAAA;AAAA,QACA,MAAA;AAAA,QACA,WAAA;AAAA,QACA,QAAA;AAAA,QACA,SAAA;AAAA,OACC,EAAA;AACD,QAAM,MAAA,MAAA,GAAS,0BAA0B,MAAO,CAAA;AAAA,UAC9C,QAAA,EAAU,MAAM,QAAA,CAAS,SAAU,EAAA;AAAA,UACnC,MAAA;AAAA,UACA,WAAA;AAAA,UACA,SAAA;AAAA,UACA,QAAA;AAAA,SACD,CAAA,CAAA;AAED,QAAA,MAAA,CAAO,cAAe,EAAA,CAAA;AAEtB,QAAO,MAAA,CAAA,IAAA;AAAA,UACL,mEAAA;AAAA,SACF,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/UnprocessedEntitiesModule.ts","../src/module.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 {\n HydratedRefreshState,\n RefreshState,\n UnprocessedEntitiesRequest,\n UnprocessedEntitiesResponse,\n} from './types';\nimport { Knex } from 'knex';\nimport {\n DiscoveryService,\n HttpAuthService,\n HttpRouterService,\n PermissionsService,\n} from '@backstage/backend-plugin-api';\nimport Router from 'express-promise-router';\nimport type { Request } from 'express';\n\nimport {\n AuthorizeResult,\n BasicPermission,\n} from '@backstage/plugin-permission-common';\nimport { unprocessedEntitiesDeletePermission } from '@backstage/plugin-catalog-unprocessed-entities-common';\nimport { NotAllowedError } from '@backstage/errors';\nimport { createLegacyAuthAdapters } from '@backstage/backend-common';\n\n/**\n * Module providing Unprocessed Entities API endpoints\n *\n * @public\n */\nexport class UnprocessedEntitiesModule {\n private readonly moduleRouter;\n\n private readonly httpAuth: HttpAuthService;\n\n private constructor(\n private readonly database: Knex,\n private readonly router: Pick<HttpRouterService, 'use'>,\n private readonly permissions: PermissionsService,\n discovery: DiscoveryService,\n httpAuth?: HttpAuthService,\n ) {\n this.moduleRouter = Router();\n this.router.use(this.moduleRouter);\n\n this.httpAuth = createLegacyAuthAdapters({\n discovery,\n httpAuth,\n }).httpAuth;\n }\n\n static create(options: {\n router: Pick<HttpRouterService, 'use'>;\n database: Knex;\n discovery: DiscoveryService;\n permissions: PermissionsService;\n httpAuth?: HttpAuthService;\n }) {\n return new UnprocessedEntitiesModule(\n options.database,\n options.router,\n options.permissions,\n options.discovery,\n options.httpAuth,\n );\n }\n\n private async unprocessed(\n request: UnprocessedEntitiesRequest,\n ): Promise<UnprocessedEntitiesResponse> {\n if (request.reason === 'pending') {\n return {\n type: 'pending',\n entities: await this.pending(request.owner),\n };\n }\n return {\n type: 'failed',\n entities: await this.failed(request.owner),\n };\n }\n\n private hydrateRefreshState(r: RefreshState): HydratedRefreshState {\n return {\n ...r,\n unprocessed_entity: JSON.parse(r.unprocessed_entity),\n ...(r.processed_entity && {\n processed_entity: JSON.parse(r.processed_entity),\n }),\n ...(r.errors && { errors: JSON.parse(r.errors) }),\n ...(r.cache && { cache: JSON.parse(r.cache) }),\n };\n }\n\n private async pending(owner?: string): Promise<HydratedRefreshState[]> {\n const res = (\n await this.database('refresh_state.*')\n .from('refresh_state')\n .leftJoin(\n 'final_entities',\n 'final_entities.entity_id',\n 'refresh_state.entity_id',\n )\n .whereNull('final_entities.entity_id')\n ).map(this.hydrateRefreshState);\n if (owner) {\n return res.filter(r => r.unprocessed_entity.spec?.owner === owner);\n }\n\n return res;\n }\n\n private async failed(owner?: string): Promise<HydratedRefreshState[]> {\n const res = (\n await this.database('refresh_state.*')\n .from('refresh_state')\n .rightJoin(\n 'final_entities',\n 'final_entities.entity_id',\n 'refresh_state.entity_id',\n )\n .whereNull('final_entities.final_entity')\n ).map(this.hydrateRefreshState);\n if (owner) {\n return res.filter(r => r.unprocessed_entity.spec?.owner === owner);\n }\n\n return res;\n }\n\n registerRoutes() {\n const isRequestAuthorized = async (\n req: Request,\n permission: BasicPermission,\n ): Promise<boolean> => {\n const decision = (\n await this.permissions.authorize([{ permission }], {\n credentials: await this.httpAuth.credentials(req),\n })\n )[0];\n\n return decision.result !== AuthorizeResult.DENY;\n };\n\n this.moduleRouter\n .get('/entities/unprocessed/failed', async (req, res) => {\n return res.json(\n await this.unprocessed({\n reason: 'failed',\n owner: String(req.query.owner),\n }),\n );\n })\n .get('/entities/unprocessed/pending', async (req, res) => {\n return res.json(\n await this.unprocessed({\n reason: 'pending',\n owner: String(req.query.owner),\n }),\n );\n })\n .delete(\n '/entities/unprocessed/delete/:entity_id',\n async (request, response) => {\n const authorized = await isRequestAuthorized(\n request,\n unprocessedEntitiesDeletePermission,\n );\n\n if (!authorized) {\n throw new NotAllowedError('Unauthorized');\n }\n\n await this.database('refresh_state')\n .where({ entity_id: request.params.entity_id })\n .delete();\n\n response.status(204).send();\n },\n );\n }\n}\n","/*\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 {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { UnprocessedEntitiesModule } from './UnprocessedEntitiesModule';\nimport { catalogPermissionExtensionPoint } from '@backstage/plugin-catalog-node/alpha';\nimport { unprocessedEntitiesDeletePermission } from '@backstage/plugin-catalog-unprocessed-entities-common';\n\n/**\n * Catalog Module for Unprocessed Entities\n *\n * @public\n */\nexport const catalogModuleUnprocessedEntities = createBackendModule({\n pluginId: 'catalog',\n moduleId: 'catalog-module-unprocessed-entities',\n register(env) {\n env.registerInit({\n deps: {\n database: coreServices.database,\n router: coreServices.httpRouter,\n logger: coreServices.logger,\n httpAuth: coreServices.httpAuth,\n discovery: coreServices.discovery,\n permissions: coreServices.permissions,\n catalogPermissions: catalogPermissionExtensionPoint,\n },\n async init({\n database,\n router,\n logger,\n permissions,\n httpAuth,\n discovery,\n catalogPermissions,\n }) {\n const module = UnprocessedEntitiesModule.create({\n database: await database.getClient(),\n router,\n permissions,\n discovery,\n httpAuth,\n });\n\n catalogPermissions.addPermissions(unprocessedEntitiesDeletePermission);\n\n module.registerRoutes();\n\n logger.info(\n 'registered additional routes for catalogModuleUnprocessedEntities',\n );\n },\n });\n },\n});\n"],"names":["Router","createLegacyAuthAdapters","AuthorizeResult","unprocessedEntitiesDeletePermission","NotAllowedError","createBackendModule","coreServices","catalogPermissionExtensionPoint"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA6CO,MAAM,yBAA0B,CAAA;AAAA,EAK7B,WACW,CAAA,QAAA,EACA,MACA,EAAA,WAAA,EACjB,WACA,QACA,EAAA;AALiB,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;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AA;AAAA,QACA,MAAA;AAAA,QACA,WAAA;AAAA,QACA,QAAA;AAAA,QACA,SAAA;AAAA,QACA,kBAAA;AAAA,OACC,EAAA;AACD,QAAM,MAAA,MAAA,GAAS,0BAA0B,MAAO,CAAA;AAAA,UAC9C,QAAA,EAAU,MAAM,QAAA,CAAS,SAAU,EAAA;AAAA,UACnC,MAAA;AAAA,UACA,WAAA;AAAA,UACA,SAAA;AAAA,UACA,QAAA;AAAA,SACD,CAAA,CAAA;AAED,QAAA,kBAAA,CAAmB,eAAeJ,0EAAmC,CAAA,CAAA;AAErE,QAAA,MAAA,CAAO,cAAe,EAAA,CAAA;AAEtB,QAAO,MAAA,CAAA,IAAA;AAAA,UACL,mEAAA;AAAA,SACF,CAAA;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-catalog-backend-module-unprocessed",
|
|
3
3
|
"description": "Backstage Catalog module to view unprocessed entities",
|
|
4
|
-
"version": "0.0.0-nightly-
|
|
4
|
+
"version": "0.0.0-nightly-20240323021043",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -28,21 +28,21 @@
|
|
|
28
28
|
"postpack": "backstage-cli package postpack"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@backstage/cli": "^0.0.0-nightly-
|
|
31
|
+
"@backstage/cli": "^0.0.0-nightly-20240323021043",
|
|
32
32
|
"@types/express": "^4.17.6"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@backstage/backend-common": "^0.0.0-nightly-
|
|
39
|
-
"@backstage/backend-plugin-api": "^0.0.0-nightly-
|
|
38
|
+
"@backstage/backend-common": "^0.0.0-nightly-20240323021043",
|
|
39
|
+
"@backstage/backend-plugin-api": "^0.0.0-nightly-20240323021043",
|
|
40
40
|
"@backstage/catalog-model": "^1.4.5",
|
|
41
41
|
"@backstage/errors": "^1.2.4",
|
|
42
|
-
"@backstage/plugin-auth-node": "^0.0.0-nightly-
|
|
42
|
+
"@backstage/plugin-auth-node": "^0.0.0-nightly-20240323021043",
|
|
43
|
+
"@backstage/plugin-catalog-node": "^0.0.0-nightly-20240323021043",
|
|
43
44
|
"@backstage/plugin-catalog-unprocessed-entities-common": "^0.0.1",
|
|
44
45
|
"@backstage/plugin-permission-common": "^0.7.13",
|
|
45
|
-
"@backstage/plugin-permission-node": "^0.0.0-nightly-20240322021005",
|
|
46
46
|
"express-promise-router": "^4.1.1",
|
|
47
47
|
"knex": "^3.0.0"
|
|
48
48
|
}
|