New backend system for Azure Site backend plugin

Signed-off-by: Deepankumar Loganathan <deepan0433@gmail.com>
This commit is contained in:
Deepankumar Loganathan
2024-02-20 14:32:12 +01:00
parent 8e9dfe7002
commit 85db926bb6
7 changed files with 95 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-azure-sites-backend': patch
---
Added new backend system for the Azure Sites backend plugin
+27 -2
View File
@@ -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"}`.
+4
View File
@@ -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<express.Router>;
+2
View File
@@ -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",
+1
View File
@@ -17,3 +17,4 @@
export * from './service/router';
export * from './api';
export * from './config';
export { azureSitesPlugin } from './plugin';
+54
View File
@@ -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,
}),
);
},
});
},
});
+2
View File
@@ -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