backend-defaults: implement permissionIntegrations service

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-01-02 11:01:17 +01:00
parent 9ddfd94528
commit a19cb2b8a5
6 changed files with 120 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-defaults': patch
---
Added default implementation for the new `PermissionIntegrationsService`.
+12 -8
View File
@@ -28,6 +28,7 @@
"./httpRouter": "./src/entrypoints/httpRouter/index.ts",
"./lifecycle": "./src/entrypoints/lifecycle/index.ts",
"./logger": "./src/entrypoints/logger/index.ts",
"./permissionIntegrations": "./src/entrypoints/permissionIntegrations/index.ts",
"./permissions": "./src/entrypoints/permissions/index.ts",
"./rootConfig": "./src/entrypoints/rootConfig/index.ts",
"./rootHealth": "./src/entrypoints/rootHealth/index.ts",
@@ -67,6 +68,9 @@
"logger": [
"src/entrypoints/logger/index.ts"
],
"permissionIntegrations": [
"src/entrypoints/permissionIntegrations/index.ts"
],
"permissions": [
"src/entrypoints/permissions/index.ts"
],
@@ -185,14 +189,6 @@
"yn": "^4.0.0",
"zod": "^3.22.4"
},
"peerDependencies": {
"@google-cloud/cloud-sql-connector": "^1.4.0"
},
"peerDependenciesMeta": {
"@google-cloud/cloud-sql-connector": {
"optional": true
}
},
"devDependencies": {
"@aws-sdk/util-stream-node": "^3.350.0",
"@backstage/backend-plugin-api": "workspace:^",
@@ -214,5 +210,13 @@
"supertest": "^7.0.0",
"wait-for-expect": "^3.0.2"
},
"peerDependencies": {
"@google-cloud/cloud-sql-connector": "^1.4.0"
},
"peerDependenciesMeta": {
"@google-cloud/cloud-sql-connector": {
"optional": true
}
},
"configSchema": "config.d.ts"
}
@@ -0,0 +1,17 @@
## API Report File for "@backstage/backend-defaults"
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { PermissionIntegrationsService } from '@backstage/backend-plugin-api';
import { ServiceFactory } from '@backstage/backend-plugin-api';
// @public
export const permissionIntegrationsServiceFactory: ServiceFactory<
PermissionIntegrationsService,
'plugin',
'singleton'
>;
// (No @packageDocumentation comment for this package)
```
@@ -23,6 +23,7 @@ import { httpAuthServiceFactory } from '@backstage/backend-defaults/httpAuth';
import { httpRouterServiceFactory } from '@backstage/backend-defaults/httpRouter';
import { lifecycleServiceFactory } from '@backstage/backend-defaults/lifecycle';
import { loggerServiceFactory } from '@backstage/backend-defaults/logger';
import { permissionIntegrationsServiceFactory } from '@backstage/backend-defaults/permissionIntegrations';
import { permissionsServiceFactory } from '@backstage/backend-defaults/permissions';
import { rootConfigServiceFactory } from '@backstage/backend-defaults/rootConfig';
import { rootHealthServiceFactory } from '@backstage/backend-defaults/rootHealth';
@@ -44,6 +45,7 @@ export const defaultServiceFactories = [
httpRouterServiceFactory,
lifecycleServiceFactory,
loggerServiceFactory,
permissionIntegrationsServiceFactory,
permissionsServiceFactory,
rootHealthServiceFactory,
rootHttpRouterServiceFactory,
@@ -0,0 +1,17 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { permissionIntegrationsServiceFactory } from './permissionIntegrationsServiceFactory';
@@ -0,0 +1,67 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
coreServices,
createServiceFactory,
} from '@backstage/backend-plugin-api';
import { createPermissionIntegrationRouter } from '@backstage/plugin-permission-node';
/**
* Permission system integration for registering resources and permissions.
*
* See {@link @backstage/code-plugin-api#PermissionIntegrationsService}
* and {@link https://backstage.io/docs/backend-system/core-services/permission-integrations | the service docs}
* for more information.
*
* @public
*/
export const permissionIntegrationsServiceFactory = createServiceFactory({
service: coreServices.permissionIntegrations,
deps: {
lifecycle: coreServices.lifecycle,
httpRouter: coreServices.httpRouter,
},
async factory({ httpRouter, lifecycle }) {
const router = createPermissionIntegrationRouter();
httpRouter.use(router);
let started = false;
lifecycle.addStartupHook(() => {
started = true;
});
return {
addResourceType(resource) {
if (started) {
throw new Error(
'Cannot add permission resource types after the plugin has started',
);
}
router.addResourceType(resource);
},
addPermissions(permissions) {
if (started) {
throw new Error(
'Cannot add permissions after the plugin has started',
);
}
router.addPermissions(permissions);
},
};
},
});