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..18c51239c3 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 @@ -49,14 +51,17 @@ Here's how to get the backend plugin up and running: } from '@backstage/plugin-azure-sites-backend'; import { Router } from 'express'; import { PluginEnvironment } from '../types'; + import { CatalogClient } from '@backstage/catalog-client'; export default async function createPlugin( env: PluginEnvironment, ): Promise { + const catalogApi = new CatalogClient({ discoveryApi: env.discovery }); return await createRouter({ logger: env.logger, azureSitesApi: AzureSitesApi.fromConfig(env.config), permissions: env.permissions, + catalogApi, }); } ``` @@ -105,6 +110,28 @@ 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'; + + const backend = createBackend(); + + // ... other feature additions + ++ backend.add(import('@backstage/plugin-azure-sites-backend')); + + // ... + + 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 fa6e8f56c6..611a106816 100644 --- a/plugins/azure-sites-backend/api-report.md +++ b/plugins/azure-sites-backend/api-report.md @@ -7,6 +7,7 @@ import { AuthService } from '@backstage/backend-plugin-api'; 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 { DiscoveryService } from '@backstage/backend-plugin-api'; @@ -53,6 +54,10 @@ export class AzureSitesConfig { readonly tenantId: string; } +// @public +const azureSitesPlugin: () => BackendFeature; +export default azureSitesPlugin; + // @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 fdaf8825ae..46cd4a5e79 100644 --- a/plugins/azure-sites-backend/package.json +++ b/plugins/azure-sites-backend/package.json @@ -43,6 +43,7 @@ "@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..7f56b8e92a 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 as default } 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 c2b9797393..500419db19 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5008,6 +5008,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