From 2bbdcb4154c3e77b96161a03617b8ed15848fb64 Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Tue, 27 Jun 2023 14:50:26 -0500 Subject: [PATCH 1/3] Added support to Badges for new backend Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- .changeset/chatty-buttons-deny.md | 5 +++ packages/backend-next/package.json | 1 + packages/backend-next/src/index.ts | 4 ++ plugins/badges-backend/README.md | 18 ++++++++ plugins/badges-backend/package.json | 1 + plugins/badges-backend/src/index.ts | 1 + plugins/badges-backend/src/plugin.ts | 61 ++++++++++++++++++++++++++++ yarn.lock | 2 + 8 files changed, 93 insertions(+) create mode 100644 .changeset/chatty-buttons-deny.md create mode 100644 plugins/badges-backend/src/plugin.ts diff --git a/.changeset/chatty-buttons-deny.md b/.changeset/chatty-buttons-deny.md new file mode 100644 index 0000000000..bd602d52ba --- /dev/null +++ b/.changeset/chatty-buttons-deny.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-badges-backend': patch +--- + +Added support for the [new backend system](https://backstage.io/docs/backend-system/) diff --git a/packages/backend-next/package.json b/packages/backend-next/package.json index 53b43a0172..04dc3e2cf3 100644 --- a/packages/backend-next/package.json +++ b/packages/backend-next/package.json @@ -28,6 +28,7 @@ "@backstage/backend-defaults": "workspace:^", "@backstage/plugin-app-backend": "workspace:^", "@backstage/plugin-auth-node": "workspace:^", + "@backstage/plugin-badges-backend": "workspace:^", "@backstage/plugin-catalog-backend": "workspace:^", "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^", "@backstage/plugin-entity-feedback-backend": "workspace:^", diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 900062d61b..60b5315ab0 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -32,11 +32,15 @@ import { techdocsPlugin } from '@backstage/plugin-techdocs-backend/alpha'; import { todoPlugin } from '@backstage/plugin-todo-backend'; import { entityFeedbackPlugin } from '@backstage/plugin-entity-feedback-backend'; import { catalogModuleUnprocessedEntities } from '@backstage/plugin-catalog-backend-module-unprocessed'; +import { badgesPlugin } from '@backstage/plugin-badges-backend'; const backend = createBackend(); backend.add(appPlugin({ appPackageName: 'example-app' })); +// Badges +backend.add(badgesPlugin()); + // Entity Feedback backend.add(entityFeedbackPlugin()); diff --git a/plugins/badges-backend/README.md b/plugins/badges-backend/README.md index ddbb30bc4e..3a2b7f52d3 100644 --- a/plugins/badges-backend/README.md +++ b/plugins/badges-backend/README.md @@ -76,6 +76,24 @@ const createEnv = makeCreateEnv(config); apiRouter.use(notFoundHandler()); ``` +### New Backend System + +The Badges 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 { badgesPlugin } from '@backstage/plugin-badges-backend/alpha'; + const backend = createBackend(); + + // ... other feature additions + ++ backend.add(badgesPlugin()); + + backend.start(); +``` + ## Badge builder Badges are created by classes implementing the `BadgeBuilder` type. The default diff --git a/plugins/badges-backend/package.json b/plugins/badges-backend/package.json index 8af1b13096..3106e363cc 100644 --- a/plugins/badges-backend/package.json +++ b/plugins/badges-backend/package.json @@ -34,6 +34,7 @@ }, "dependencies": { "@backstage/backend-common": "workspace:^", + "@backstage/backend-plugin-api": "workspace:^", "@backstage/catalog-client": "workspace:^", "@backstage/catalog-model": "workspace:^", "@backstage/config": "workspace:^", diff --git a/plugins/badges-backend/src/index.ts b/plugins/badges-backend/src/index.ts index 35a061c516..0c417a7ad6 100644 --- a/plugins/badges-backend/src/index.ts +++ b/plugins/badges-backend/src/index.ts @@ -25,3 +25,4 @@ export * from './lib'; export * from './service/router'; export * from './types'; export * from './database/badgesStore'; +export { badgesPlugin } from './plugin'; diff --git a/plugins/badges-backend/src/plugin.ts b/plugins/badges-backend/src/plugin.ts new file mode 100644 index 0000000000..ecc03f0c15 --- /dev/null +++ b/plugins/badges-backend/src/plugin.ts @@ -0,0 +1,61 @@ +/* + * Copyright 2023 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'; + +/** + * Badges backend plugin + * + * @public + */ +export const badgesPlugin = createBackendPlugin({ + pluginId: 'badges', + register(env) { + env.registerInit({ + deps: { + config: coreServices.config, + logger: coreServices.logger, + discovery: coreServices.discovery, + tokenManager: coreServices.tokenManager, + identity: coreServices.identity, + httpRouter: coreServices.httpRouter, + }, + async init({ + config, + logger, + discovery, + tokenManager, + identity, + httpRouter, + }) { + httpRouter.use( + await createRouter({ + config, + logger: loggerToWinstonLogger(logger), + discovery, + tokenManager, + identity, + }), + ); + }, + }); + }, +}); diff --git a/yarn.lock b/yarn.lock index fe70ce4e17..eedac582b9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5139,6 +5139,7 @@ __metadata: resolution: "@backstage/plugin-badges-backend@workspace:plugins/badges-backend" dependencies: "@backstage/backend-common": "workspace:^" + "@backstage/backend-plugin-api": "workspace:^" "@backstage/backend-test-utils": "workspace:^" "@backstage/catalog-client": "workspace:^" "@backstage/catalog-model": "workspace:^" @@ -24927,6 +24928,7 @@ __metadata: "@backstage/cli": "workspace:^" "@backstage/plugin-app-backend": "workspace:^" "@backstage/plugin-auth-node": "workspace:^" + "@backstage/plugin-badges-backend": "workspace:^" "@backstage/plugin-catalog-backend": "workspace:^" "@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^" "@backstage/plugin-entity-feedback-backend": "workspace:^" From bc3b19068581d8be66d1d9f3128397a8800ff5d2 Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Tue, 27 Jun 2023 18:14:14 -0500 Subject: [PATCH 2/3] Updated api-report Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- plugins/badges-backend/api-report.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/badges-backend/api-report.md b/plugins/badges-backend/api-report.md index 09a02ba44d..4594228543 100644 --- a/plugins/badges-backend/api-report.md +++ b/plugins/badges-backend/api-report.md @@ -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 { CatalogApi } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; import { Entity } from '@backstage/catalog-model'; @@ -81,6 +82,9 @@ export type BadgeSpec = { markdown: string; }; +// @public +export const badgesPlugin: () => BackendFeature; + // @public export interface BadgesStore { // (undocumented) From 408c38e3e1d5421f32c03d3a23d36d349eccd060 Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Wed, 28 Jun 2023 06:44:33 -0500 Subject: [PATCH 3/3] Corrected import not to be from alpha Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- plugins/badges-backend/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/badges-backend/README.md b/plugins/badges-backend/README.md index 3a2b7f52d3..22c3311ff1 100644 --- a/plugins/badges-backend/README.md +++ b/plugins/badges-backend/README.md @@ -84,7 +84,7 @@ In your `packages/backend/src/index.ts` make the following changes: ```diff import { createBackend } from '@backstage/backend-defaults'; -+ import { badgesPlugin } from '@backstage/plugin-badges-backend/alpha'; ++ import { badgesPlugin } from '@backstage/plugin-badges-backend'; const backend = createBackend(); // ... other feature additions