chore: Move AllowAllPermissionPolicy to it's own backend module package

Signed-off-by: Jack Palmer <jackpalmer@spotify.com>
This commit is contained in:
Jack Palmer
2023-09-01 17:20:33 +01:00
parent d0da943ed2
commit 78dab638c9
11 changed files with 159 additions and 45 deletions
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
@@ -0,0 +1,5 @@
# @backstage/plugin-permission-backend-module-policy-allow-all
The allow all policy backend module for the permission plugin.
_This plugin was created through the Backstage CLI_
@@ -0,0 +1,40 @@
{
"name": "@backstage/plugin-permission-backend-module-policy-allow-all",
"description": "Allow all policy backend module for the permission plugin.",
"version": "0.0.0",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts"
},
"backstage": {
"role": "backend-plugin-module"
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build",
"lint": "backstage-cli package lint",
"test": "backstage-cli package test",
"clean": "backstage-cli package clean",
"prepack": "backstage-cli package prepack",
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/plugin-auth-node": "workspace:^",
"@backstage/plugin-permission-common": "workspace:^",
"@backstage/plugin-permission-node": "workspace:^"
},
"devDependencies": {
"@backstage/backend-test-utils": "workspace:^",
"@backstage/cli": "workspace:^"
},
"files": [
"dist"
]
}
@@ -0,0 +1,23 @@
/*
* 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.
*/
/**
* The allow all policy backend module for the permission plugin.
*
* @packageDocumentation
*/
export { permissionModuleAllowAllPolicy } from './module';
@@ -0,0 +1,34 @@
/*
* 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 { createBackendModule } from '@backstage/backend-plugin-api';
import { policyExtensionPoint } from '@backstage/plugin-permission-node/alpha';
import { AllowAllPermissionPolicy } from './policy';
/**
* A permission policy module that allows all requests.
*/
export const permissionModuleAllowAllPolicy = createBackendModule({
moduleId: 'allowAllPolicy',
pluginId: 'permission',
register(reg) {
reg.registerInit({
deps: { policy: policyExtensionPoint },
async init({ policy }) {
policy.setPolicy(new AllowAllPermissionPolicy());
},
});
},
});
@@ -0,0 +1,35 @@
import { BackstageIdentityResponse } from '@backstage/plugin-auth-node';
import {
AuthorizeResult,
PolicyDecision,
} from '@backstage/plugin-permission-common';
import {
PermissionPolicy,
PolicyQuery,
} from '@backstage/plugin-permission-node';
/*
* 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 class AllowAllPermissionPolicy implements PermissionPolicy {
async handle(
_request: PolicyQuery,
_user?: BackstageIdentityResponse,
): Promise<PolicyDecision> {
return {
result: AuthorizeResult.ALLOW,
};
}
}
+1 -1
View File
@@ -14,4 +14,4 @@
* limitations under the License.
*/
export { permissionPlugin, permissionModuleAllowAllPolicy } from './plugin';
export { permissionPlugin } from './plugin';
+2 -40
View File
@@ -17,18 +17,9 @@
import { loggerToWinstonLogger } from '@backstage/backend-common';
import {
coreServices,
createBackendModule,
createBackendPlugin,
} from '@backstage/backend-plugin-api';
import { BackstageIdentityResponse } from '@backstage/plugin-auth-node';
import {
AuthorizeResult,
PolicyDecision,
} from '@backstage/plugin-permission-common';
import {
PermissionPolicy,
PolicyQuery,
} from '@backstage/plugin-permission-node';
import { PermissionPolicy } from '@backstage/plugin-permission-node';
import {
policyExtensionPoint,
PolicyExtensionPoint,
@@ -46,35 +37,6 @@ class PolicyExtensionPointImpl implements PolicyExtensionPoint {
}
}
/**
* A permission policy module that allows all requests.
*
* @alpha
*/
export const permissionModuleAllowAllPolicy = createBackendModule({
moduleId: 'allowAllPolicy',
pluginId: 'permission',
register(reg) {
class AllowAllPermissionPolicy implements PermissionPolicy {
async handle(
_request: PolicyQuery,
_user?: BackstageIdentityResponse,
): Promise<PolicyDecision> {
return {
result: AuthorizeResult.ALLOW,
};
}
}
reg.registerInit({
deps: { policy: policyExtensionPoint },
async init({ policy }) {
policy.setPolicy(new AllowAllPermissionPolicy());
},
});
},
});
/**
* Permission plugin
*
@@ -99,7 +61,7 @@ export const permissionPlugin = createBackendPlugin({
const winstonLogger = loggerToWinstonLogger(logger);
if (!policies.policy) {
throw new Error(
'No policy module installed! Please install a policy module. If you want to allow all requests, use permissionModuleAllowAllPolicy',
'No policy module installed! Please install a policy module. If you want to allow all requests, use @backstage/plugin-permission-backend-module-policy-allow-all permissionModuleAllowAllPolicy',
);
}