From 8f835847061941a6aeff4ef8bf2bafb79170e371 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Wed, 24 Nov 2021 14:35:10 +0000 Subject: [PATCH] permission-backend: remove standaloneServer, run.ts and AllowAllPermissionPolicy The run.ts / standaloneServer.ts stuff is a hangover and expected to be removed or heavily adjusted in the future, and since it's intended to run from the command line, there's no neat way to pass in a permission policy. As such it's not going to be useful in its current form, so we're removing it for now. Signed-off-by: Mike Lewis --- plugins/permission-backend/src/run.ts | 33 ----------- .../service/AllowAllPermissionPolicy.test.ts | 35 ----------- .../src/service/AllowAllPermissionPolicy.ts | 34 ----------- .../src/service/standaloneServer.ts | 59 ------------------- 4 files changed, 161 deletions(-) delete mode 100644 plugins/permission-backend/src/run.ts delete mode 100644 plugins/permission-backend/src/service/AllowAllPermissionPolicy.test.ts delete mode 100644 plugins/permission-backend/src/service/AllowAllPermissionPolicy.ts delete mode 100644 plugins/permission-backend/src/service/standaloneServer.ts diff --git a/plugins/permission-backend/src/run.ts b/plugins/permission-backend/src/run.ts deleted file mode 100644 index 53d4e4334a..0000000000 --- a/plugins/permission-backend/src/run.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 { getRootLogger } from '@backstage/backend-common'; -import yn from 'yn'; -import { startStandaloneServer } from './service/standaloneServer'; - -const port = process.env.PLUGIN_PORT ? Number(process.env.PLUGIN_PORT) : 7007; -const enableCors = yn(process.env.PLUGIN_CORS, { default: false }); -const logger = getRootLogger(); - -startStandaloneServer({ port, enableCors, logger }).catch(err => { - logger.error(err); - process.exit(1); -}); - -process.on('SIGINT', () => { - logger.info('CTRL+C pressed; exiting.'); - process.exit(0); -}); diff --git a/plugins/permission-backend/src/service/AllowAllPermissionPolicy.test.ts b/plugins/permission-backend/src/service/AllowAllPermissionPolicy.test.ts deleted file mode 100644 index 5ebebd04e5..0000000000 --- a/plugins/permission-backend/src/service/AllowAllPermissionPolicy.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 { - AuthorizeResult, - Permission, -} from '@backstage/plugin-permission-common'; -import { AllowAllPermissionPolicy } from './AllowAllPermissionPolicy'; - -describe('AllowAllPermissionPolicy', () => { - const policy = new AllowAllPermissionPolicy(); - - it('returns ALLOW when no identity is passed', async () => { - await expect( - policy.handle({ - permission: { - name: 'any.permission', - } as Permission, - }), - ).resolves.toEqual({ result: AuthorizeResult.ALLOW }); - }); -}); diff --git a/plugins/permission-backend/src/service/AllowAllPermissionPolicy.ts b/plugins/permission-backend/src/service/AllowAllPermissionPolicy.ts deleted file mode 100644 index bb39d4a334..0000000000 --- a/plugins/permission-backend/src/service/AllowAllPermissionPolicy.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 { BackstageIdentity } from '@backstage/plugin-auth-backend'; -import { AuthorizeResult } from '@backstage/plugin-permission-common'; -import { - PermissionPolicy, - PolicyAuthorizeRequest, - PolicyResult, -} from '@backstage/plugin-permission-node'; - -export class AllowAllPermissionPolicy implements PermissionPolicy { - async handle( - _request: PolicyAuthorizeRequest, - _user?: BackstageIdentity, - ): Promise { - return { - result: AuthorizeResult.ALLOW, - }; - } -} diff --git a/plugins/permission-backend/src/service/standaloneServer.ts b/plugins/permission-backend/src/service/standaloneServer.ts deleted file mode 100644 index a2478ac57b..0000000000 --- a/plugins/permission-backend/src/service/standaloneServer.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 { - createServiceBuilder, - loadBackendConfig, - SingleHostDiscovery, -} from '@backstage/backend-common'; -import { Server } from 'http'; -import { Logger } from 'winston'; -import { AllowAllPermissionPolicy } from './AllowAllPermissionPolicy'; -import { createRouter } from './router'; - -export interface ServerOptions { - port: number; - enableCors: boolean; - logger: Logger; -} - -export async function startStandaloneServer( - options: ServerOptions, -): Promise { - const logger = options.logger.child({ service: 'permission-backend' }); - const config = await loadBackendConfig({ logger, argv: process.argv }); - const discovery = SingleHostDiscovery.fromConfig(config); - logger.debug('Starting application server...'); - const router = await createRouter({ - logger, - discovery, - policy: new AllowAllPermissionPolicy(), - }); - - let service = createServiceBuilder(module) - .setPort(options.port) - .addRouter('/permission', router); - if (options.enableCors) { - service = service.enableCors({ origin: 'http://localhost:3000' }); - } - - return await service.start().catch(err => { - logger.error(err); - process.exit(1); - }); -} - -module.hot?.accept();