feat: support new backend system at explore-backend

Add the backend plugin `explorePlugin` as default export
that registers the router for the explore backend
with the `StaticExploreToolProvider` loading its data
from the config `explore.tools`.

Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
Patrick Jungermann
2024-01-08 00:33:46 +01:00
parent a070f29921
commit fd3d51caaf
8 changed files with 153 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
---
'@backstage/plugin-explore-backend': patch
---
Add support for the new backend system.
A new backend plugin for the explore backend
was added and exported as `default`.
You can use it with the new backend system like
```ts title="packages/backend/src/index.ts"
backend.add(import('@backstage/plugin-explore-backend'));
```
+30
View File
@@ -9,6 +9,36 @@ for these tools.
### Adding the plugin to your `packages/backend`
Install dependencies
```bash
# From your Backstage root directory
yarn add --cwd packages/backend @backstage/plugin-explore-backend
```
Add feature
```ts title="packages/backend/src/index.ts"
backend.add(import('@backstage/plugin-explore-backend'));
```
Config:
```yaml
explore:
tools:
- title: New Relic
description: new relic plugin
url: /newrelic
image: https://i.imgur.com/L37ikrX.jpg
tags:
- newrelic
- proxy
- nerdGraph
```
### Adding the plugin to your `packages/backend` (old)
#### Tools as Config
Install dependencies
+5
View File
@@ -3,6 +3,7 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BackendFeature } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import { ExploreTool } from '@backstage/plugin-explore-common';
import express from 'express';
@@ -16,6 +17,10 @@ import type { ToolDocumentCollatorFactoryOptions as ToolDocumentCollatorFactoryO
// @public (undocumented)
export function createRouter(options: RouterOptions): Promise<express.Router>;
// @public
const explorePlugin: () => BackendFeature;
export default explorePlugin;
// @public (undocumented)
export interface ExploreToolProvider {
getTools(request: GetExploreToolsRequest): Promise<GetExploreToolsResponse>;
+2
View File
@@ -29,6 +29,7 @@
},
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/plugin-explore-common": "workspace:^",
"@backstage/plugin-search-backend-module-explore": "workspace:^",
@@ -42,6 +43,7 @@
"yn": "^4.0.0"
},
"devDependencies": {
"@backstage/backend-test-utils": "workspace:^",
"@backstage/cli": "workspace:^",
"@types/supertest": "^2.0.8",
"supertest": "^6.2.4"
+1
View File
@@ -20,6 +20,7 @@
* @packageDocumentation
*/
export { explorePlugin as default } from './plugin';
export * from './service';
export * from './tools';
@@ -0,0 +1,50 @@
/*
* 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 { mockServices, startTestBackend } from '@backstage/backend-test-utils';
import { ExploreTool } from '@backstage/plugin-explore-common';
import { explorePlugin } from './plugin';
describe('explorePlugin', () => {
it('should register explore plugin and its router', async () => {
const tool: ExploreTool = {
title: 'Tool Title',
image: 'https://example.com/image.png',
url: 'https://example.com',
lifecycle: 'production',
tags: ['tag1', 'tag2'],
};
const httpRouterMock = mockServices.httpRouter.mock();
await startTestBackend({
extensionPoints: [],
features: [
explorePlugin(),
httpRouterMock.factory,
mockServices.rootConfig.factory({
data: {
explore: {
tools: [tool],
},
},
}),
],
});
expect(httpRouterMock.use).toHaveBeenCalledTimes(1);
});
});
+49
View File
@@ -0,0 +1,49 @@
/*
* 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';
import { StaticExploreToolProvider } from './tools';
/**
* The explore backend plugin.
*
* @public
*/
export const explorePlugin = createBackendPlugin({
pluginId: 'explore',
register(env) {
env.registerInit({
deps: {
config: coreServices.rootConfig,
httpRouter: coreServices.httpRouter,
logger: coreServices.logger,
},
async init({ config, httpRouter, logger }) {
httpRouter.use(
await createRouter({
logger: loggerToWinstonLogger(logger),
toolProvider: StaticExploreToolProvider.fromConfig(config),
}),
);
},
});
},
});
+2
View File
@@ -6412,6 +6412,8 @@ __metadata:
resolution: "@backstage/plugin-explore-backend@workspace:plugins/explore-backend"
dependencies:
"@backstage/backend-common": "workspace:^"
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/backend-test-utils": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/config": "workspace:^"
"@backstage/plugin-explore-common": "workspace:^"