expose the permission plugin using the new backend system
Signed-off-by: eipc16 <pprzemek.312@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-permission-backend': minor
|
||||
---
|
||||
|
||||
Introduced alpha export of the `permissionPlugin` using the new backend system
|
||||
@@ -27,8 +27,12 @@
|
||||
"dependencies": {
|
||||
"@backstage/backend-defaults": "workspace:^",
|
||||
"@backstage/plugin-app-backend": "workspace:^",
|
||||
"@backstage/plugin-auth-node": "workspace:^",
|
||||
"@backstage/plugin-catalog-backend": "workspace:^",
|
||||
"@backstage/plugin-kubernetes-backend": "workspace:^",
|
||||
"@backstage/plugin-permission-backend": "workspace:^",
|
||||
"@backstage/plugin-permission-common": "workspace:^",
|
||||
"@backstage/plugin-permission-node": "workspace:^",
|
||||
"@backstage/plugin-scaffolder-backend": "workspace:^",
|
||||
"@backstage/plugin-search-backend": "workspace:^",
|
||||
"@backstage/plugin-search-backend-module-catalog": "workspace:^",
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import { BackstageIdentityResponse } from '@backstage/plugin-auth-node';
|
||||
import {
|
||||
AuthorizeResult,
|
||||
PolicyDecision,
|
||||
} from '@backstage/plugin-permission-common';
|
||||
import {
|
||||
PermissionPolicy,
|
||||
PolicyQuery,
|
||||
} from '@backstage/plugin-permission-node';
|
||||
|
||||
export class ExamplePermissionPolicy implements PermissionPolicy {
|
||||
async handle(
|
||||
_request: PolicyQuery,
|
||||
_user?: BackstageIdentityResponse,
|
||||
): Promise<PolicyDecision> {
|
||||
return {
|
||||
result: AuthorizeResult.ALLOW,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ import { searchModuleCatalogCollator } from '@backstage/plugin-search-backend-mo
|
||||
import { searchModuleTechDocsCollator } from '@backstage/plugin-search-backend-module-techdocs/alpha';
|
||||
import { searchModuleExploreCollator } from '@backstage/plugin-search-backend-module-explore/alpha';
|
||||
import { kubernetesPlugin } from '@backstage/plugin-kubernetes-backend/alpha';
|
||||
import { permissionPlugin } from '@backstage/plugin-permission-backend/alpha';
|
||||
import { ExamplePermissionPolicy } from './ExamplePermissionPolicy';
|
||||
|
||||
const backend = createBackend();
|
||||
|
||||
@@ -48,4 +50,8 @@ backend.add(searchModuleExploreCollator());
|
||||
|
||||
// Kubernetes
|
||||
backend.add(kubernetesPlugin());
|
||||
|
||||
// Permissions
|
||||
backend.add(permissionPlugin({ policy: new ExamplePermissionPolicy() }));
|
||||
|
||||
backend.start();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
## API Report File for "@backstage/plugin-permission-backend"
|
||||
|
||||
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
||||
|
||||
```ts
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { PermissionPolicy } from '@backstage/plugin-permission-node';
|
||||
|
||||
// @alpha
|
||||
export const permissionPlugin: (
|
||||
options: PermissionPluginOptions,
|
||||
) => BackendFeature;
|
||||
|
||||
// @alpha
|
||||
export type PermissionPluginOptions = {
|
||||
policy: PermissionPolicy;
|
||||
};
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
```
|
||||
@@ -9,6 +9,21 @@
|
||||
"main": "dist/index.cjs.js",
|
||||
"types": "dist/index.d.ts"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./alpha": "./src/alpha.ts",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"alpha": [
|
||||
"src/alpha.ts"
|
||||
],
|
||||
"package.json": [
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
},
|
||||
"backstage": {
|
||||
"role": "backend-plugin"
|
||||
},
|
||||
@@ -23,6 +38,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/backend-common": "workspace:^",
|
||||
"@backstage/backend-plugin-api": "workspace:^",
|
||||
"@backstage/config": "workspace:^",
|
||||
"@backstage/errors": "workspace:^",
|
||||
"@backstage/plugin-auth-node": "workspace:^",
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2020 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 { permissionPlugin, type PermissionPluginOptions } from './plugin';
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2021 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 { loggerToWinstonLogger } from '@backstage/backend-common';
|
||||
import {
|
||||
coreServices,
|
||||
createBackendPlugin,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { PermissionPolicy } from '@backstage/plugin-permission-node';
|
||||
import { createRouter } from './service';
|
||||
|
||||
/**
|
||||
* Permission plugin options
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export type PermissionPluginOptions = {
|
||||
policy: PermissionPolicy;
|
||||
};
|
||||
|
||||
/**
|
||||
* Permission plugin
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export const permissionPlugin = createBackendPlugin(
|
||||
(options: PermissionPluginOptions) => ({
|
||||
pluginId: 'permission',
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
http: coreServices.httpRouter,
|
||||
config: coreServices.config,
|
||||
logger: coreServices.logger,
|
||||
discovery: coreServices.discovery,
|
||||
identity: coreServices.identity,
|
||||
},
|
||||
async init({ http, config, logger, discovery, identity }) {
|
||||
const winstonLogger = loggerToWinstonLogger(logger);
|
||||
http.use(
|
||||
await createRouter({
|
||||
config,
|
||||
discovery,
|
||||
identity,
|
||||
logger: winstonLogger,
|
||||
policy: options.policy,
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
@@ -7593,6 +7593,7 @@ __metadata:
|
||||
resolution: "@backstage/plugin-permission-backend@workspace:plugins/permission-backend"
|
||||
dependencies:
|
||||
"@backstage/backend-common": "workspace:^"
|
||||
"@backstage/backend-plugin-api": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/config": "workspace:^"
|
||||
"@backstage/errors": "workspace:^"
|
||||
@@ -23441,8 +23442,12 @@ __metadata:
|
||||
"@backstage/backend-defaults": "workspace:^"
|
||||
"@backstage/cli": "workspace:^"
|
||||
"@backstage/plugin-app-backend": "workspace:^"
|
||||
"@backstage/plugin-auth-node": "workspace:^"
|
||||
"@backstage/plugin-catalog-backend": "workspace:^"
|
||||
"@backstage/plugin-kubernetes-backend": "workspace:^"
|
||||
"@backstage/plugin-permission-backend": "workspace:^"
|
||||
"@backstage/plugin-permission-common": "workspace:^"
|
||||
"@backstage/plugin-permission-node": "workspace:^"
|
||||
"@backstage/plugin-scaffolder-backend": "workspace:^"
|
||||
"@backstage/plugin-search-backend": "workspace:^"
|
||||
"@backstage/plugin-search-backend-module-catalog": "workspace:^"
|
||||
|
||||
Reference in New Issue
Block a user