Last active
June 22, 2024 22:44
-
-
Save jonico/1d75bc5de00d48be39d598908dba4e30 to your computer and use it in GitHub Desktop.
Backstage 1.25 with Postman plugin
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 characters
/* | |
* 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, | |
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(); | |
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')); | |
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', | |
}) | |
}, | |
}); | |
}, | |
})); | |
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment