feat: Allow custom root ACL.

This commit is contained in:
Ruben Verborgh
2021-01-15 12:38:22 +01:00
committed by Joachim Van Herwegen
parent 87f1450d0d
commit e544e6dc11
6 changed files with 61 additions and 30 deletions

View File

@@ -9,6 +9,7 @@ import { TEXT_TURTLE } from '../util/ContentTypes';
import { ensureTrailingSlash, joinFilePath } from '../util/PathUtil';
import { Initializer } from './Initializer';
const DEFAULT_ACL_PATH = joinFilePath(__dirname, '../../templates/root/.acl');
/**
* Ensures that a root ACL is present.
*/
@@ -17,16 +18,19 @@ export class AclInitializer extends Initializer {
private readonly store: ResourceStore;
private readonly aclManager: AclManager;
private readonly root: ResourceIdentifier;
private readonly aclPath: string;
public constructor(
baseUrl: string,
store: ResourceStore,
aclManager: AclManager,
) {
public constructor(settings: {
store: ResourceStore;
aclManager: AclManager;
baseUrl: string;
aclPath?: string;
}) {
super();
this.store = store;
this.aclManager = aclManager;
this.root = { path: ensureTrailingSlash(baseUrl) };
this.store = settings.store;
this.aclManager = settings.aclManager;
this.root = { path: ensureTrailingSlash(settings.baseUrl) };
this.aclPath = settings.aclPath ?? DEFAULT_ACL_PATH;
}
public async handle(): Promise<void> {
@@ -42,7 +46,7 @@ export class AclInitializer extends Initializer {
// The associated ACL document MUST include an authorization policy with acl:Control access privilege."
// https://solid.github.io/specification/protocol#storage
protected async setRootAclDocument(rootAcl: ResourceIdentifier): Promise<void> {
const acl = await fsPromises.readFile(joinFilePath(__dirname, '../../templates/root/.acl'), 'utf8');
const acl = await fsPromises.readFile(this.aclPath, 'utf8');
this.logger.debug(`Installing root ACL document at ${rootAcl.path}`);
await this.store.setRepresentation(rootAcl, new BasicRepresentation(acl, rootAcl, TEXT_TURTLE));
}

View File

@@ -21,13 +21,13 @@ import namedNode = DataFactory.namedNode;
*/
export class RootContainerInitializer extends Initializer {
protected readonly logger = getLoggerFor(this);
private readonly baseId: ResourceIdentifier;
private readonly store: ResourceStore;
private readonly baseId: ResourceIdentifier;
public constructor(baseUrl: string, store: ResourceStore) {
public constructor(settings: { store: ResourceStore; baseUrl: string }) {
super();
this.baseId = { path: ensureTrailingSlash(baseUrl) };
this.store = store;
this.store = settings.store;
this.baseId = { path: ensureTrailingSlash(settings.baseUrl) };
}
public async handle(): Promise<void> {