Expose types to handle Database management

This implements several types to own and manage databases on a database
server. The current SimpleDatabase* classes preserve the present
behaviour; future implementations can segregate databases to be owned by
different roles.
This commit is contained in:
Joel Low
2020-10-01 17:38:12 +08:00
parent af85ba3198
commit e277c5dfa5
10 changed files with 203 additions and 43 deletions
+5 -3
View File
@@ -17,7 +17,6 @@
import express from 'express';
import Router from 'express-promise-router';
import cookieParser from 'cookie-parser';
import Knex from 'knex';
import { Logger } from 'winston';
import { createAuthProvider } from '../providers';
import { Config } from '@backstage/config';
@@ -25,11 +24,12 @@ import { DatabaseKeyStore, TokenFactory, createOidcRouter } from '../identity';
import {
NotFoundError,
PluginEndpointDiscovery,
PluginDatabaseFactory,
} from '@backstage/backend-common';
export interface RouterOptions {
logger: Logger;
database: Knex;
database: PluginDatabaseFactory;
config: Config;
discovery: PluginEndpointDiscovery;
}
@@ -47,7 +47,9 @@ export async function createRouter({
const keyDurationSeconds = 3600;
const keyStore = await DatabaseKeyStore.create({ database });
const keyStore = await DatabaseKeyStore.create({
database: await database.getDatabase(),
});
const tokenIssuer = new TokenFactory({
issuer: authUrl,
keyStore,
@@ -53,7 +53,11 @@ export async function startStandaloneServer(
const router = await createRouter({
logger,
config,
database,
database: {
async getDatabase(_database?: string) {
return database;
},
},
discovery,
});