mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add DataAccessorBasedStore integration
This commit is contained in:
64
test/configs/AuthenticatedFileBasedDataAccessorConfig.ts
Normal file
64
test/configs/AuthenticatedFileBasedDataAccessorConfig.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import type { HttpHandler,
|
||||
ResourceStore } from '../../index';
|
||||
import {
|
||||
AuthenticatedLdpHandler,
|
||||
BasicResponseWriter,
|
||||
CompositeAsyncHandler,
|
||||
MethodPermissionsExtractor,
|
||||
RdfToQuadConverter,
|
||||
UnsecureWebIdExtractor,
|
||||
QuadToRdfConverter,
|
||||
} from '../../index';
|
||||
import type { ServerConfig } from './ServerConfig';
|
||||
import {
|
||||
getConvertingStore,
|
||||
getBasicRequestParser,
|
||||
getOperationHandler,
|
||||
getWebAclAuthorizer,
|
||||
getFileDataAccessorStore,
|
||||
} from './Util';
|
||||
|
||||
/**
|
||||
* AuthenticatedFileResourceStoreConfig works with
|
||||
* - a WebAclAuthorizer
|
||||
* - a FileResourceStore wrapped in a converting store (rdf to quad & quad to rdf)
|
||||
* - GET, POST, PUT & DELETE operation handlers
|
||||
*/
|
||||
export class AuthenticatedFileBasedDataAccessorConfig implements ServerConfig {
|
||||
public base: string;
|
||||
public store: ResourceStore;
|
||||
|
||||
public constructor(base: string, rootFilepath: string) {
|
||||
this.base = base;
|
||||
this.store = getConvertingStore(
|
||||
getFileDataAccessorStore(base, rootFilepath),
|
||||
[ new QuadToRdfConverter(),
|
||||
new RdfToQuadConverter() ],
|
||||
);
|
||||
}
|
||||
|
||||
public getHttpHandler(): HttpHandler {
|
||||
const requestParser = getBasicRequestParser();
|
||||
|
||||
const credentialsExtractor = new UnsecureWebIdExtractor();
|
||||
const permissionsExtractor = new CompositeAsyncHandler([
|
||||
new MethodPermissionsExtractor(),
|
||||
]);
|
||||
|
||||
const operationHandler = getOperationHandler(this.store);
|
||||
|
||||
const responseWriter = new BasicResponseWriter();
|
||||
const authorizer = getWebAclAuthorizer(this.store, this.base);
|
||||
|
||||
const handler = new AuthenticatedLdpHandler({
|
||||
requestParser,
|
||||
credentialsExtractor,
|
||||
permissionsExtractor,
|
||||
authorizer,
|
||||
operationHandler,
|
||||
responseWriter,
|
||||
});
|
||||
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
62
test/configs/FileBasedDataAccessorConfig.ts
Normal file
62
test/configs/FileBasedDataAccessorConfig.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { HttpHandler,
|
||||
ResourceStore } from '../../index';
|
||||
import {
|
||||
AllowEverythingAuthorizer,
|
||||
AuthenticatedLdpHandler,
|
||||
BasicResponseWriter,
|
||||
CompositeAsyncHandler,
|
||||
MethodPermissionsExtractor,
|
||||
QuadToRdfConverter,
|
||||
RawBodyParser,
|
||||
RdfToQuadConverter,
|
||||
UnsecureWebIdExtractor,
|
||||
} from '../../index';
|
||||
import type { ServerConfig } from './ServerConfig';
|
||||
import {
|
||||
getOperationHandler,
|
||||
getConvertingStore,
|
||||
getBasicRequestParser,
|
||||
getFileDataAccessorStore,
|
||||
} from './Util';
|
||||
|
||||
/**
|
||||
* FileBasedDataAccessorConfig works with
|
||||
* - an AllowEverythingAuthorizer (no acl)
|
||||
* - a DataAccessorBasedStore with a FileDataAccessor wrapped in a converting store (rdf to quad & quad to rdf)
|
||||
* - GET, POST, PUT & DELETE operation handlers
|
||||
*/
|
||||
export class FileBasedDataAccessorConfig implements ServerConfig {
|
||||
public store: ResourceStore;
|
||||
|
||||
public constructor(base: string, rootFilepath: string) {
|
||||
this.store = getConvertingStore(
|
||||
getFileDataAccessorStore(base, rootFilepath),
|
||||
[ new QuadToRdfConverter(), new RdfToQuadConverter() ],
|
||||
);
|
||||
}
|
||||
|
||||
public getHttpHandler(): HttpHandler {
|
||||
// This is for the sake of test coverage, as it could also be just getBasicRequestParser()
|
||||
const requestParser = getBasicRequestParser([ new RawBodyParser() ]);
|
||||
|
||||
const credentialsExtractor = new UnsecureWebIdExtractor();
|
||||
const permissionsExtractor = new CompositeAsyncHandler([
|
||||
new MethodPermissionsExtractor(),
|
||||
]);
|
||||
const authorizer = new AllowEverythingAuthorizer();
|
||||
|
||||
const operationHandler = getOperationHandler(this.store);
|
||||
const responseWriter = new BasicResponseWriter();
|
||||
|
||||
const handler = new AuthenticatedLdpHandler({
|
||||
requestParser,
|
||||
credentialsExtractor,
|
||||
permissionsExtractor,
|
||||
authorizer,
|
||||
operationHandler,
|
||||
responseWriter,
|
||||
});
|
||||
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import type { HttpHandler } from '../../src/server/HttpHandler';
|
||||
import type { ResourceStore } from '../../src/storage/ResourceStore';
|
||||
|
||||
export interface ServerConfig {
|
||||
store: ResourceStore;
|
||||
getHttpHandler: () => HttpHandler;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,10 @@ import {
|
||||
BasicTargetExtractor,
|
||||
CompositeAsyncHandler,
|
||||
ContentTypeParser,
|
||||
DataAccessorBasedStore,
|
||||
DeleteOperationHandler,
|
||||
ExtensionBasedMapper,
|
||||
FileDataAccessor,
|
||||
FileResourceStore,
|
||||
GetOperationHandler,
|
||||
HeadOperationHandler,
|
||||
@@ -32,7 +35,6 @@ import {
|
||||
UrlContainerManager,
|
||||
WebAclAuthorizer,
|
||||
} from '../../index';
|
||||
import { ExtensionBasedMapper } from '../../src/storage/ExtensionBasedMapper';
|
||||
|
||||
export const BASE = 'http://test.com';
|
||||
|
||||
@@ -56,6 +58,21 @@ export const getFileResourceStore = (base: string, rootFilepath: string): FileRe
|
||||
new MetadataController(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Gives a file data accessor store based on (default) runtime config.
|
||||
* @param base - Base URL.
|
||||
* @param rootFilepath - The root file path.
|
||||
*
|
||||
* @returns The data accessor based store.
|
||||
*/
|
||||
export const getFileDataAccessorStore = (base: string, rootFilepath: string): DataAccessorBasedStore =>
|
||||
new DataAccessorBasedStore(
|
||||
new FileDataAccessor(new ExtensionBasedMapper(base, rootFilepath), new MetadataController()),
|
||||
base,
|
||||
new MetadataController(),
|
||||
new UrlContainerManager(base),
|
||||
);
|
||||
|
||||
/**
|
||||
* Gives an in memory resource store based on (default) base url.
|
||||
* @param base - Optional base parameter for the run time config.
|
||||
|
||||
Reference in New Issue
Block a user