feat: Move runtime config into dedicated component, Closes #67

* Move runtime config into dedicated component, Closes #67

* Migrate FileResourceStore to RuntimeConfig
This commit is contained in:
Ruben Taelman
2020-08-26 10:25:47 +02:00
committed by GitHub
parent 4f8ebff7f7
commit 5126356c94
14 changed files with 194 additions and 84 deletions

View File

@@ -2,6 +2,7 @@ import { AclManager } from '../authorization/AclManager';
import { DATA_TYPE_BINARY } from '../util/ContentTypes';
import { ExpressHttpServer } from '../server/ExpressHttpServer';
import { ResourceStore } from '../storage/ResourceStore';
import { RuntimeConfig } from './RuntimeConfig';
import streamifyArray from 'streamify-array';
/**
@@ -11,11 +12,18 @@ export class Setup {
private readonly httpServer: ExpressHttpServer;
private readonly store: ResourceStore;
private readonly aclManager: AclManager;
private readonly runtimeConfig: RuntimeConfig;
public constructor(httpServer: ExpressHttpServer, store: ResourceStore, aclManager: AclManager) {
public constructor(
httpServer: ExpressHttpServer,
store: ResourceStore,
aclManager: AclManager,
runtimeConfig: RuntimeConfig,
) {
this.httpServer = httpServer;
this.store = store;
this.aclManager = aclManager;
this.runtimeConfig = runtimeConfig;
}
/**
@@ -23,7 +31,7 @@ export class Setup {
* @param port - A port number.
* @param base - A base URL.
*/
public async setup(port: number, base: string): Promise<void> {
public async setup(): Promise<void> {
// Set up acl so everything can still be done by default
// Note that this will need to be adapted to go through all the correct channels later on
const aclSetup = async(): Promise<void> => {
@@ -38,10 +46,10 @@ export class Setup {
acl:mode acl:Append;
acl:mode acl:Delete;
acl:mode acl:Control;
acl:accessTo <${base}>;
acl:default <${base}>.`;
acl:accessTo <${this.runtimeConfig.base}>;
acl:default <${this.runtimeConfig.base}>.`;
await this.store.setRepresentation(
await this.aclManager.getAcl({ path: base }),
await this.aclManager.getAcl({ path: this.runtimeConfig.base }),
{
dataType: DATA_TYPE_BINARY,
data: streamifyArray([ acl ]),
@@ -56,6 +64,6 @@ export class Setup {
await aclSetup();
this.httpServer.listen(port);
this.httpServer.listen(this.runtimeConfig.port);
}
}