Create separate roles and auto-create plugin databases
This would create a role per plugin (with a predictable pattern) before creating a database owned by that role. This removes the need to manually provision databases and users.
This commit is contained in:
@@ -49,9 +49,9 @@ import { PluginEnvironment } from './types';
|
||||
function makeCreateEnv(loadedConfigs: AppConfig[]) {
|
||||
const config = ConfigReader.fromConfigs(loadedConfigs);
|
||||
|
||||
return (plugin: string): PluginEnvironment => {
|
||||
return async (plugin: string): Promise<PluginEnvironment> => {
|
||||
const logger = getRootLogger().child({ type: 'plugin', plugin });
|
||||
const database = createDatabaseClient(
|
||||
const database = await createDatabaseClient(
|
||||
config.getConfig('backend.database'),
|
||||
{
|
||||
connection: {
|
||||
@@ -68,35 +68,41 @@ async function main() {
|
||||
const configs = await loadBackendConfig();
|
||||
const configReader = ConfigReader.fromConfigs(configs);
|
||||
const createEnv = makeCreateEnv(configs);
|
||||
const healthcheckEnv = useHotMemoize(module, () => createEnv('healthcheck'));
|
||||
const catalogEnv = useHotMemoize(module, () => createEnv('catalog'));
|
||||
const scaffolderEnv = useHotMemoize(module, () => createEnv('scaffolder'));
|
||||
const authEnv = useHotMemoize(module, () => createEnv('auth'));
|
||||
const proxyEnv = useHotMemoize(module, () => createEnv('proxy'));
|
||||
const rollbarEnv = useHotMemoize(module, () => createEnv('rollbar'));
|
||||
const sentryEnv = useHotMemoize(module, () => createEnv('sentry'));
|
||||
const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs'));
|
||||
const kubernetesEnv = useHotMemoize(module, () => createEnv('kubernetes'));
|
||||
const graphqlEnv = useHotMemoize(module, () => createEnv('graphql'));
|
||||
const appEnv = useHotMemoize(module, () => createEnv('app'));
|
||||
const healthcheckEnv = useHotMemoize(module, async () =>
|
||||
createEnv('healthcheck'),
|
||||
);
|
||||
const catalogEnv = useHotMemoize(module, async () => createEnv('catalog'));
|
||||
const scaffolderEnv = useHotMemoize(module, async () =>
|
||||
createEnv('scaffolder'),
|
||||
);
|
||||
const authEnv = useHotMemoize(module, async () => createEnv('auth'));
|
||||
const proxyEnv = useHotMemoize(module, async () => createEnv('proxy'));
|
||||
const rollbarEnv = useHotMemoize(module, async () => createEnv('rollbar'));
|
||||
const sentryEnv = useHotMemoize(module, async () => createEnv('sentry'));
|
||||
const techdocsEnv = useHotMemoize(module, async () => createEnv('techdocs'));
|
||||
const kubernetesEnv = useHotMemoize(module, async () =>
|
||||
createEnv('kubernetes'),
|
||||
);
|
||||
const graphqlEnv = useHotMemoize(module, async () => createEnv('graphql'));
|
||||
const appEnv = useHotMemoize(module, async () => createEnv('app'));
|
||||
|
||||
const apiRouter = Router();
|
||||
apiRouter.use('/catalog', await catalog(catalogEnv));
|
||||
apiRouter.use('/rollbar', await rollbar(rollbarEnv));
|
||||
apiRouter.use('/scaffolder', await scaffolder(scaffolderEnv));
|
||||
apiRouter.use('/sentry', await sentry(sentryEnv));
|
||||
apiRouter.use('/auth', await auth(authEnv));
|
||||
apiRouter.use('/techdocs', await techdocs(techdocsEnv));
|
||||
apiRouter.use('/kubernetes', await kubernetes(kubernetesEnv));
|
||||
apiRouter.use('/proxy', await proxy(proxyEnv));
|
||||
apiRouter.use('/graphql', await graphql(graphqlEnv));
|
||||
apiRouter.use('/catalog', await catalog(await catalogEnv));
|
||||
apiRouter.use('/rollbar', await rollbar(await rollbarEnv));
|
||||
apiRouter.use('/scaffolder', await scaffolder(await scaffolderEnv));
|
||||
apiRouter.use('/sentry', await sentry(await sentryEnv));
|
||||
apiRouter.use('/auth', await auth(await authEnv));
|
||||
apiRouter.use('/techdocs', await techdocs(await techdocsEnv));
|
||||
apiRouter.use('/kubernetes', await kubernetes(await kubernetesEnv));
|
||||
apiRouter.use('/proxy', await proxy(await proxyEnv));
|
||||
apiRouter.use('/graphql', await graphql(await graphqlEnv));
|
||||
apiRouter.use(notFoundHandler());
|
||||
|
||||
const service = createServiceBuilder(module)
|
||||
.loadConfig(configReader)
|
||||
.addRouter('', await healthcheck(healthcheckEnv))
|
||||
.addRouter('', await healthcheck(await healthcheckEnv))
|
||||
.addRouter('/api', apiRouter)
|
||||
.addRouter('', await app(appEnv));
|
||||
.addRouter('', await app(await appEnv));
|
||||
|
||||
await service.start().catch(err => {
|
||||
console.log(err);
|
||||
|
||||
Reference in New Issue
Block a user