Last active
June 22, 2024 22:44
-
-
Save jonico/1d75bc5de00d48be39d598908dba4e30 to your computer and use it in GitHub Desktop.
Revisions
-
jonico revised this gist
Jun 22, 2024 . 1 changed file with 37 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,11 @@ import { loggerToWinstonLogger } from '@backstage/backend-common'; import { coreServices, createBackendPlugin, createBackendModule, } from '@backstage/backend-plugin-api'; import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node/alpha'; import { PostmanEntityProvider } from '@postman-solutions/postman-backstage-backend-plugin'; import { CacheManager } from '@backstage/backend-common'; import { createRouter as postmanRouter} from '@postman-solutions/postman-backstage-backend-plugin'; const backend = createBackend(); @@ -46,16 +49,6 @@ backend.add(import('@backstage/plugin-search-backend/alpha')); backend.add(import('@backstage/plugin-search-backend-module-catalog/alpha')); backend.add(import('@backstage/plugin-search-backend-module-techdocs/alpha')); backend.add(createBackendPlugin({ pluginId: 'postman', register(env) { @@ -78,4 +71,37 @@ backend.add(createBackendPlugin({ }, })); const postmanEntityServiceModule = createBackendModule({ pluginId: 'catalog', // name of the plugin that the module is targeting moduleId: 'custom-extensions', register(env) { env.registerInit({ deps: { catalog: catalogProcessingExtensionPoint, config: coreServices.rootConfig, logger: coreServices.logger, scheduler: coreServices.scheduler, }, async init({ catalog, config, logger, scheduler}) { const cacheManager = CacheManager.fromConfig(config); const cache = cacheManager.forPlugin('postman').getClient({defaultTtl: config?.getNumber('postman.cache.ttl') ?? 60000 }) const postmanEntityProvider = PostmanEntityProvider.fromConfig(config, {logger: logger, cache}) const postmanEntityProviderSynchInterval = config?.getNumber('postman.entityProviderSynchInterval') ?? 5; catalog.addEntityProvider(postmanEntityProvider); await scheduler.scheduleTask({ id: 'run_postman_entity_provider_refresh', fn: async () => { await postmanEntityProvider.run(); }, frequency: { minutes: postmanEntityProviderSynchInterval }, timeout: { minutes: 10 }, }); }, }); }, }); backend.add(postmanEntityServiceModule); backend.start(); -
jonico created this gist
Jun 22, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ /* * Hi! * * Note that this is an EXAMPLE Backstage backend. Please check the README. * * Happy hacking! */ import { createBackend } from '@backstage/backend-defaults'; import { loggerToWinstonLogger } from '@backstage/backend-common'; import { coreServices, createBackendPlugin, } from '@backstage/backend-plugin-api'; import { createRouter as postmanRouter} from '@postman-solutions/postman-backstage-backend-plugin'; const backend = createBackend(); backend.add(import('@backstage/plugin-app-backend/alpha')); backend.add(import('@backstage/plugin-proxy-backend/alpha')); backend.add(import('@backstage/plugin-scaffolder-backend/alpha')); backend.add(import('@backstage/plugin-techdocs-backend/alpha')); // auth plugin backend.add(import('@backstage/plugin-auth-backend')); // See https://backstage.io/docs/backend-system/building-backends/migrating#the-auth-plugin //backend.add(import('@backstage/plugin-auth-backend-module-guest-provider')); backend.add(import('@backstage/plugin-auth-backend-module-github-provider')); // catalog plugin backend.add(import('@backstage/plugin-catalog-backend/alpha')); backend.add( import('@backstage/plugin-catalog-backend-module-scaffolder-entity-model'), ); // permission plugin backend.add(import('@backstage/plugin-permission-backend/alpha')); backend.add( import('@backstage/plugin-permission-backend-module-allow-all-policy'), ); // search plugin backend.add(import('@backstage/plugin-search-backend/alpha')); backend.add(import('@backstage/plugin-search-backend-module-catalog/alpha')); backend.add(import('@backstage/plugin-search-backend-module-techdocs/alpha')); // // Correctly handle the dynamic import to match the expected Promise structure // backend.add(legacyPlugin('postman', // import('@postman-solutions/postman-backstage-backend-plugin') // .then((module) => ({ // default: module.createRouter, // })) // )); backend.add(createBackendPlugin({ pluginId: 'postman', register(env) { env.registerInit({ deps: { config: coreServices.rootConfig, logger: coreServices.logger, httpRouter: coreServices.httpRouter, }, async init({ config, logger, httpRouter }) { const legacyLogger = loggerToWinstonLogger(logger); httpRouter.use(await postmanRouter({ config, logger: legacyLogger })); httpRouter.addAuthPolicy({ path: '/:id', allow: 'unauthenticated', }) }, }); }, })); backend.start();