Skip to content

Commit 5bd00e0

Browse files
Merge pull request #4 from postman-solutions-eng/backstage-latest-versions
Changes to make Postman Backstage plugins work with Backstage v 1.24+
2 parents 2345464 + a48b629 commit 5bd00e0

File tree

1 file changed

+90
-5
lines changed

1 file changed

+90
-5
lines changed

README.md

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This plugin is designed to integrate Postman functionality into your Backstage a
3232

3333
# Disclaimer and Plugin Compatibility
3434
These backstage plugins are not officially supported by Postman and are intended for Backstage users to integrate Postman into their API documentation easily.
35-
They have been successfully tested with Backstage v1.22 and 1.23. Please file an issue if you are using a newer version of Backstage so that we can recommend how to integrate best under those circumstances.
35+
They have been successfully tested with Backstage v1.22, v1.23 and 1.28. Please file an issue if you are using a newer version of Backstage so that we can recommend how to integrate best under those circumstances.
3636

3737
# Plugin Features
3838

@@ -206,7 +206,92 @@ This guide provides instructions for configuring your application to interact wi
206206

207207
If you prefer not to utilise caching and always get the latest information from Postman, you can set the TTL value to 0 or any value smaller than the interval at which the entity service refreshes.
208208

209-
### Add the backend plugin to your Backstage application
209+
### Add the backend plugin to your Backstage application (newer Backstage versions >= v1.24)
210+
211+
1. Modify file `packages/backend/src/index.ts`, and add the following to it:
212+
213+
```ts
214+
...
215+
216+
import { createBackend } from '@backstage/backend-defaults';
217+
218+
// new code after other imports
219+
import { loggerToWinstonLogger, CacheManager } from '@backstage/backend-common';
220+
import {
221+
coreServices,
222+
createBackendPlugin,
223+
createBackendModule,
224+
} from '@backstage/backend-plugin-api';
225+
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha';
226+
import { PostmanEntityProvider, createRouter as postmanRouter } from '@postman-solutions/postman-backstage-backend-plugin';
227+
228+
const backend = createBackend();
229+
...
230+
backend.add(import('@backstage/plugin-search-backend-module-techdocs/alpha'));
231+
232+
// new code after all other plugins have been added to backend
233+
234+
backend.add(createBackendPlugin({
235+
pluginId: 'postman',
236+
register(env) {
237+
env.registerInit({
238+
deps: {
239+
config: coreServices.rootConfig,
240+
logger: coreServices.logger,
241+
httpRouter: coreServices.httpRouter,
242+
},
243+
async init({ config, logger, httpRouter }) {
244+
245+
const legacyLogger = loggerToWinstonLogger(logger);
246+
httpRouter.use(await postmanRouter({ config, logger: legacyLogger }));
247+
httpRouter.addAuthPolicy({
248+
path: '/:id',
249+
allow: 'unauthenticated',
250+
})
251+
},
252+
});
253+
},
254+
}));
255+
256+
// optional for the entity service
257+
const postmanEntityServiceModule = createBackendModule({
258+
pluginId: 'catalog', // name of the plugin that the module is targeting
259+
moduleId: 'custom-extensions',
260+
register(env) {
261+
env.registerInit({
262+
deps: {
263+
catalog: catalogProcessingExtensionPoint,
264+
config: coreServices.rootConfig,
265+
logger: coreServices.logger,
266+
scheduler: coreServices.scheduler,
267+
},
268+
async init({ catalog, config, logger, scheduler}) {
269+
const cacheManager = CacheManager.fromConfig(config);
270+
const cache = cacheManager.forPlugin('postman').getClient({defaultTtl: config?.getNumber('postman.cache.ttl') ?? 60000 })
271+
const postmanEntityProvider = PostmanEntityProvider.fromConfig(config, {logger: logger, cache})
272+
const postmanEntityProviderSynchInterval = config?.getNumber('postman.entityProviderSynchInterval') ?? 5;
273+
catalog.addEntityProvider(postmanEntityProvider);
274+
275+
await scheduler.scheduleTask({
276+
id: 'run_postman_entity_provider_refresh',
277+
fn: async () => {
278+
await postmanEntityProvider.run();
279+
},
280+
frequency: { minutes: postmanEntityProviderSynchInterval },
281+
timeout: { minutes: 10 },
282+
});
283+
284+
},
285+
});
286+
},
287+
});
288+
backend.add(postmanEntityServiceModule);
289+
290+
backend.start();
291+
```
292+
293+
294+
### Add the backend plugin to your Backstage application (older Backstage versions < 1.24)
210295

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

@@ -253,7 +338,7 @@ postman:
253338
entityProviderSynchInterval: SYNC_FREQUENCY_IN_MINUTES (optional)
254339
```
255340

256-
Additionally, you would need to insert the following lines into your `packages/backend/src/plugins/catalog.ts` file:
341+
Additionally, if you are using an older version of Backstage ( < 1.24) you would need to insert the following lines into your `packages/backend/src/plugins/catalog.ts` file:
257342

258343
``` ts
259344
...
@@ -289,6 +374,8 @@ import { CacheManager } from '@backstage/backend-common';
289374
...
290375
```
291376

377+
For newer versions of Backstage (v1.24+), we included the entity service initialization code in our modifications for `packages/backend/src/index.ts`.
378+
292379
# Configure Backend Content Security Policy to display embedded pictures (optional)
293380

294381
If your Postman API docs contain embedded pictures like this one
@@ -309,8 +396,6 @@ backend:
309396
- https://avatars.githubusercontent.com
310397
```
311398

312-
313-
314399
# Postman Metadata Guide
315400

316401
## Metadata Object Overview

0 commit comments

Comments
 (0)