Skip to content

Commit

Permalink
feat(readme): remove support for old backend system (AxisCommunicatio…
Browse files Browse the repository at this point in the history
…ns#216)

Co-authored-by: Niklas Aronsson <[email protected]>
Co-authored-by: Frida Jacobsson <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 1b47182 commit 6939770
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 100 deletions.
6 changes: 6 additions & 0 deletions .changeset/shiny-timers-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@axis-backstage/plugin-readme-backend': minor
---

**BREAKING**: The `readme-backend` has been migrated to the new backend system. If
you are using the new backend system module, this does not affect you.
39 changes: 0 additions & 39 deletions plugins/readme-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,6 @@ yarn --cwd packages/backend add @axis-backstage/plugin-readme-backend

Here's how to get the backend plugin up and running:

1. Create a new file named `packages/backend/src/plugins/readme.ts`, and add the following to it:

```ts
import { createRouter } from '@axis-backstage/plugin-readme-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';

export default async function createPlugin(
env: PluginEnvironment,
): Promise<Router> {
return await createRouter({
logger: env.logger,
config: env.config,
reader: env.reader,
discovery: env.discovery,
tokenManager: env.tokenManager,
});
}
```

2. Wire this into the overall backend router by adding the following to `packages/backend/src/index.ts`:

```ts
import readme from './plugins/readme';
...

async function main() {
// Add this line under the other lines that follow the useHotMemoize pattern
const readmeEnv = useHotMemoize(module, () => createEnv('readme'),

// Add this under the lines that add their routers to apiRouter
apiRouter.use('/readme', await readme(readmeEnv));
}
```
### New Backend System
The Readme backend plugin has support for the [new backend system](https://backstage.io/docs/backend-system/). Here is how you can set it up:
In your `packages/backend/src/index.ts` make the following changes:

```diff
Expand Down
20 changes: 0 additions & 20 deletions plugins/readme-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,9 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { AuthService } from '@backstage/backend-plugin-api';
import { BackendFeatureCompat } from '@backstage/backend-plugin-api';
import { DiscoveryService } from '@backstage/backend-plugin-api';
import express from 'express';
import { LoggerService } from '@backstage/backend-plugin-api';
import { RootConfigService } from '@backstage/backend-plugin-api';
import { TokenManagerService } from '@backstage/backend-plugin-api';
import { UrlReaderService } from '@backstage/backend-plugin-api';

// @public @deprecated
export function createRouter(options: RouterOptions): Promise<express.Router>;

// @public
const readmePlugin: BackendFeatureCompat;
export default readmePlugin;

// @public @deprecated
export interface RouterOptions {
auth?: AuthService;
config: RootConfigService;
discovery: DiscoveryService;
logger: LoggerService;
reader: UrlReaderService;
tokenManager?: TokenManagerService;
}
```
1 change: 0 additions & 1 deletion plugins/readme-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/backend-common": "^0.24.0",
"@backstage/backend-defaults": "^0.4.3",
"@backstage/backend-plugin-api": "^0.8.0",
"@backstage/catalog-client": "^1.6.6",
Expand Down
1 change: 0 additions & 1 deletion plugins/readme-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
* @packageDocumentation
*/

export * from './service/router';
export { readmePlugin as default } from './plugin';
6 changes: 3 additions & 3 deletions plugins/readme-backend/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export const readmePlugin = createBackendPlugin({
register(env) {
env.registerInit({
deps: {
logger: coreServices.logger,
auth: coreServices.auth,
config: coreServices.rootConfig,
reader: coreServices.urlReader,
discovery: coreServices.discovery,
auth: coreServices.auth,
httpRouter: coreServices.httpRouter,
logger: coreServices.logger,
reader: coreServices.urlReader,
},
async init({ auth, logger, config, reader, discovery, httpRouter }) {
httpRouter.use(
Expand Down
3 changes: 1 addition & 2 deletions plugins/readme-backend/src/service/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ describe('createRouter', () => {
const config = mockServices.rootConfig();
const logger = mockServices.rootLogger.mock();
const discovery = mockServices.discovery.mock();
const tokenManager = mockServices.tokenManager.mock();
const reader = UrlReaders.default({ logger, config });

const router = await createRouter({
auth: mockServices.auth.mock(),
logger,
config,
discovery,
tokenManager,
reader,
});
app = express().use(router);
Expand Down
39 changes: 6 additions & 33 deletions plugins/readme-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {
LoggerService,
RootConfigService,
UrlReaderService,
TokenManagerService,
} from '@backstage/backend-plugin-api';
import { createLegacyAuthAdapters } from '@backstage/backend-common';
import { ScmIntegrations } from '@backstage/integration';
import {
getEntitySourceLocation,
Expand All @@ -24,49 +22,24 @@ import { ReadmeFile } from './types';

/**
* Constructs a readme router.
* @deprecated Please migrate to the new backend system as this will be removed in the future.
* @public
*
*/
export interface RouterOptions {
/**
* Implementation of Winston logger
*/
logger: LoggerService;

/**
* Backstage config object
*/
interface RouterOptions {
auth: AuthService;
config: RootConfigService;

/**
* Backstage url reader instance
*/
reader: UrlReaderService;
/**
* Backstage discovery service
*/
discovery: DiscoveryService;
/**
* Backstage token manager service
*/
tokenManager?: TokenManagerService;
/**
* Backstage auth service
*/
auth?: AuthService;
logger: LoggerService;
reader: UrlReaderService;
}

/**
* Constructs a readme router.
*
* @deprecated Please migrate to the new backend system as this will be removed in the future.
* @public
*/
export async function createRouter(
options: RouterOptions,
): Promise<express.Router> {
const { logger, config, reader, discovery } = options;
const { auth } = createLegacyAuthAdapters(options);
const { auth, logger, config, reader, discovery } = options;
const catalogClient = new CatalogClient({ discoveryApi: discovery });

const pluginCache = CacheManager.fromConfig(config).forPlugin('readme');
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,6 @@ __metadata:
version: 0.0.0-use.local
resolution: "@axis-backstage/plugin-readme-backend@workspace:plugins/readme-backend"
dependencies:
"@backstage/backend-common": "npm:^0.24.0"
"@backstage/backend-defaults": "npm:^0.4.3"
"@backstage/backend-plugin-api": "npm:^0.8.0"
"@backstage/backend-test-utils": "npm:^0.5.0"
Expand Down

0 comments on commit 6939770

Please sign in to comment.