From 85db926bb6a40d0546113dbc13b7f70b961f22ce Mon Sep 17 00:00:00 2001 From: Deepankumar Loganathan Date: Tue, 20 Feb 2024 14:32:12 +0100 Subject: [PATCH] New backend system for Azure Site backend plugin Signed-off-by: Deepankumar Loganathan --- .changeset/five-mayflies-juggle.md | 5 +++ plugins/azure-sites-backend/README.md | 29 +++++++++++- plugins/azure-sites-backend/api-report.md | 4 ++ plugins/azure-sites-backend/package.json | 2 + plugins/azure-sites-backend/src/index.ts | 1 + plugins/azure-sites-backend/src/plugin.ts | 54 +++++++++++++++++++++++ yarn.lock | 2 + 7 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 .changeset/five-mayflies-juggle.md create mode 100644 plugins/azure-sites-backend/src/plugin.ts diff --git a/.changeset/five-mayflies-juggle.md b/.changeset/five-mayflies-juggle.md new file mode 100644 index 0000000000..56bf28a8e9 --- /dev/null +++ b/.changeset/five-mayflies-juggle.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-azure-sites-backend': patch +--- + +Added new backend system for the Azure Sites backend plugin diff --git a/plugins/azure-sites-backend/README.md b/plugins/azure-sites-backend/README.md index 892cbe4024..843e9ff92b 100644 --- a/plugins/azure-sites-backend/README.md +++ b/plugins/azure-sites-backend/README.md @@ -33,6 +33,8 @@ Configuration Details: Here's how to get the backend plugin up and running: +#### Legacy Backend System + 1. First we need to add the `@backstage/plugin-azure-sites-backend` package to your backend: ```sh @@ -105,6 +107,29 @@ Here's how to get the backend plugin up and running: } ``` -5. Now run `yarn start-backend` from the repo root. +#### New Backend System -6. Finally, open `http://localhost:7007/api/azure/health` in a browser, it should return `{"status":"ok"}`. +The Azure Sites backend plugin has support for the [new backend system](https://backstage.io/docs/backend-system/), here's how you can set that up: + +In your `packages/backend/src/index.ts` make the following changes: + +```diff + import { createBackend } from '@backstage/backend-defaults'; ++ import { azureSitesPlugin } from '@backstage/plugin-azure-sites-backend; + + const backend = createBackend(); + + // ... other feature additions + ++ backend.add(azureSitesPlugin); + + // ... + + backend.start(); +``` + +#### Start Backed & Test + +1. Now run `yarn start-backend` from the repo root. + +2. Finally, open `http://localhost:7007/api/azure/health` in a browser, it should return `{"status":"ok"}`. diff --git a/plugins/azure-sites-backend/api-report.md b/plugins/azure-sites-backend/api-report.md index 04cd22596a..5adc3c3c47 100644 --- a/plugins/azure-sites-backend/api-report.md +++ b/plugins/azure-sites-backend/api-report.md @@ -6,6 +6,7 @@ import { AzureSiteListRequest } from '@backstage/plugin-azure-sites-common'; import { AzureSiteListResponse } from '@backstage/plugin-azure-sites-common'; import { AzureSiteStartStopRequest } from '@backstage/plugin-azure-sites-common'; +import { BackendFeature } from '@backstage/backend-plugin-api'; import { CatalogApi } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; import express from 'express'; @@ -50,6 +51,9 @@ export class AzureSitesConfig { readonly tenantId: string; } +// @public +export const azureSitesPlugin: () => BackendFeature; + // @public (undocumented) export function createRouter(options: RouterOptions): Promise; diff --git a/plugins/azure-sites-backend/package.json b/plugins/azure-sites-backend/package.json index 05eafa97f1..ff4b41441f 100644 --- a/plugins/azure-sites-backend/package.json +++ b/plugins/azure-sites-backend/package.json @@ -36,12 +36,14 @@ "@azure/arm-resourcegraph": "^4.2.1", "@azure/identity": "^4.0.0", "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/catalog-client": "workspace:^", "@backstage/catalog-model": "workspace:^", "@backstage/config": "workspace:^", "@backstage/errors": "workspace:^", "@backstage/plugin-auth-node": "workspace:^", "@backstage/plugin-azure-sites-common": "workspace:^", + "@backstage/plugin-catalog-node": "workspace:^", "@backstage/plugin-permission-common": "workspace:^", "@backstage/plugin-permission-node": "workspace:^", "@types/express": "^4.17.6", diff --git a/plugins/azure-sites-backend/src/index.ts b/plugins/azure-sites-backend/src/index.ts index 97f94e4470..22d120acc5 100644 --- a/plugins/azure-sites-backend/src/index.ts +++ b/plugins/azure-sites-backend/src/index.ts @@ -17,3 +17,4 @@ export * from './service/router'; export * from './api'; export * from './config'; +export { azureSitesPlugin } from './plugin'; diff --git a/plugins/azure-sites-backend/src/plugin.ts b/plugins/azure-sites-backend/src/plugin.ts new file mode 100644 index 0000000000..90a9c416bd --- /dev/null +++ b/plugins/azure-sites-backend/src/plugin.ts @@ -0,0 +1,54 @@ +/* + * Copyright 2024 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 { createRouter } from './service/router'; +import { catalogServiceRef } from '@backstage/plugin-catalog-node/alpha'; +import { AzureSitesApi } from './api'; + +/** + * Azure Sites Backend Plugin + * + * @public + */ +export const azureSitesPlugin = createBackendPlugin({ + pluginId: 'azure-sites', + register(env) { + env.registerInit({ + deps: { + config: coreServices.rootConfig, + logger: coreServices.logger, + httpRouter: coreServices.httpRouter, + permissions: coreServices.permissions, + catalogApi: catalogServiceRef, + }, + async init({ config, logger, httpRouter, permissions, catalogApi }) { + const azureSitesApi = AzureSitesApi.fromConfig(config); + httpRouter.use( + await createRouter({ + logger: loggerToWinstonLogger(logger), + azureSitesApi, + permissions, + catalogApi, + }), + ); + }, + }); + }, +}); diff --git a/yarn.lock b/yarn.lock index b612c502e2..f223ccdff7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5093,6 +5093,7 @@ __metadata: "@azure/arm-resourcegraph": ^4.2.1 "@azure/identity": ^4.0.0 "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/catalog-client": "workspace:^" "@backstage/catalog-model": "workspace:^" "@backstage/cli": "workspace:^" @@ -5100,6 +5101,7 @@ __metadata: "@backstage/errors": "workspace:^" "@backstage/plugin-auth-node": "workspace:^" "@backstage/plugin-azure-sites-common": "workspace:^" + "@backstage/plugin-catalog-node": "workspace:^" "@backstage/plugin-permission-common": "workspace:^" "@backstage/plugin-permission-node": "workspace:^" "@types/express": ^4.17.6