Skip to content

Commit

Permalink
feat: integrate pod creation
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Dec 2, 2020
1 parent f387b36 commit 1a043ac
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/config-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"files-scs:config/presets/ldp/websockets.json",
"files-scs:config/presets/logging.json",
"files-scs:config/presets/middleware.json",
"files-scs:config/presets/pod-management.json",
"files-scs:config/presets/representation-conversion.json",
"files-scs:config/presets/setup.json",
"files-scs:config/presets/storage/backend/storage-memory.json",
Expand Down
1 change: 1 addition & 0 deletions config/config-file.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"files-scs:config/presets/ldp/websockets.json",
"files-scs:config/presets/logging.json",
"files-scs:config/presets/middleware.json",
"files-scs:config/presets/pod-management.json",
"files-scs:config/presets/representation-conversion.json",
"files-scs:config/presets/setup.json",
"files-scs:config/presets/storage/backend/storage-filesystem.json",
Expand Down
1 change: 1 addition & 0 deletions config/config-path-routing.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"files-scs:config/presets/ldp/websockets.json",
"files-scs:config/presets/logging.json",
"files-scs:config/presets/middleware.json",
"files-scs:config/presets/pod-management.json",
"files-scs:config/presets/representation-conversion.json",
"files-scs:config/presets/setup.json",
"files-scs:config/presets/storage/backend/storage-filesystem.json",
Expand Down
1 change: 1 addition & 0 deletions config/config-rdf-to-sparql-endpoint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"files-scs:config/presets/ldp/websockets.json",
"files-scs:config/presets/logging.json",
"files-scs:config/presets/middleware.json",
"files-scs:config/presets/pod-management.json",
"files-scs:config/presets/representation-conversion.json",
"files-scs:config/presets/setup.json",
"files-scs:config/presets/storage/backend/storage-filesystem.json",
Expand Down
1 change: 1 addition & 0 deletions config/config-sparql-endpoint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"files-scs:config/presets/ldp/websockets.json",
"files-scs:config/presets/logging.json",
"files-scs:config/presets/middleware.json",
"files-scs:config/presets/pod-management.json",
"files-scs:config/presets/representation-conversion.json",
"files-scs:config/presets/setup.json",
"files-scs:config/presets/storage/backend/storage-sparql-endpoint.json",
Expand Down
4 changes: 4 additions & 0 deletions config/presets/cli-params.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{
"@id": "urn:solid-server:default:variable:loggingLevel",
"@type": "Variable"
},
{
"@id": "urn:solid-server:default:variable:podTemplateFolder",
"@type": "Variable"
}
]
}
3 changes: 3 additions & 0 deletions config/presets/http.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
{
"@id": "urn:solid-server:default:Middleware"
},
{
"@id": "urn:solid-server:default:PodManagerHandler"
},
{
"@id": "urn:solid-server:default:LdpHandler"
}
Expand Down
51 changes: 51 additions & 0 deletions config/presets/pod-management.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^1.0.0/components/context.jsonld",
"@graph": [
{
"@id": "urn:solid-server:default:ResourcesGenerator",
"@type": "TemplatedResourcesGenerator",
"TemplatedResourcesGenerator:_templateFolder": {
"@id": "urn:solid-server:default:variable:podTemplateFolder"
},
"TemplatedResourcesGenerator:_factory": {
"@type": "ExtensionBasedMapperFactory"
},
"TemplatedResourcesGenerator:_engine": {
"@type": "HandlebarsTemplateEngine"
}
},
{
"@id": "urn:solid-server:default:PodManager",
"@type": "GeneratedPodManager",
"GeneratedPodManager:_store": {
"@id": "urn:solid-server:default:ResourceStore"
},
"GeneratedPodManager:_idGenerator": {
"@type": "SuffixIdentifierGenerator",
"SuffixIdentifierGenerator:_base": {
"@id": "urn:solid-server:default:variable:baseUrl"
}
},
"GeneratedPodManager:_resourcesGenerator": {
"@id": "urn:solid-server:default:ResourcesGenerator"
}
},
{
"@id": "urn:solid-server:default:PodManagerHandler",
"@type": "PodManagerHttpHandler",
"PodManagerHttpHandler:_args_requestPath": "/pods",
"PodManagerHttpHandler:_args_requestParser": {
"@id": "urn:solid-server:default:RequestParser"
},
"PodManagerHttpHandler:_args_agentParser": {
"@type": "AgentJsonParser"
},
"PodManagerHttpHandler:_args_manager": {
"@id": "urn:solid-server:default:PodManager"
},
"PodManagerHttpHandler:_args_responseWriter": {
"@id": "urn:solid-server:default:ResponseWriter"
}
}
]
}
18 changes: 18 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ export * from './src/logging/LogUtil';
export * from './src/logging/VoidLoggerFactory';
export * from './src/logging/WinstonLoggerFactory';

// Pods/Agent
export * from './src/pods/agent/Agent';
export * from './src/pods/agent/AgentJsonParser';
export * from './src/pods/agent/AgentParser';

// Pods/Generate
export * from './src/pods/generate/HandlebarsTemplateEngine';
export * from './src/pods/generate/IdentifierGenerator';
export * from './src/pods/generate/ResourcesGenerator';
export * from './src/pods/generate/SuffixIdentifierGenerator';
export * from './src/pods/generate/TemplateEngine';
export * from './src/pods/generate/TemplatedResourcesGenerator';

// Pods
export * from './src/pods/GeneratedPodManager';
export * from './src/pods/PodManager';
export * from './src/pods/PodManagerHttpHandler';

// Server
export * from './src/server/ExpressHttpServerFactory';
export * from './src/server/HttpHandler';
Expand Down
3 changes: 3 additions & 0 deletions src/init/CliRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const runCli = function({
port: { type: 'number', alias: 'p', default: 3000 },
rootFilePath: { type: 'string', alias: 'f' },
sparqlEndpoint: { type: 'string', alias: 's' },
podTemplateFolder: { type: 'string', alias: 't' },
})
.help();

Expand All @@ -58,6 +59,8 @@ export const runCli = function({
'urn:solid-server:default:variable:port': params.port,
'urn:solid-server:default:variable:rootFilePath': params.rootFilePath ?? process.cwd(),
'urn:solid-server:default:variable:sparqlEndpoint': params.sparqlEndpoint,
'urn:solid-server:default:variable:podTemplateFolder':
params.podTemplateFolder ?? path.join(__dirname, '../../templates'),
},
}) as Setup;
return await setup.setup();
Expand Down
26 changes: 26 additions & 0 deletions templates/.acl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Root ACL resource for the agent account
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.

# The homepage is readable by the public
<#public>
a acl:Authorization;
acl:agentClass foaf:Agent;
acl:accessTo </>;
acl:mode acl:Read.

# The owner has full access to every resource in their pod.
# Other agents have no access rights,
# unless specifically authorized in other .acl resources.
<#owner>
a acl:Authorization;
acl:agent <{{webId}}>;
# Optional owner email, to be used for account recovery:
{{#if email}}acl:agent <mailto:{{{email}}}>;{{/if}}
# Set the access to the root storage folder itself
acl:accessTo </>;
# All resources will inherit this authorization, by default
acl:default </>;
# The owner has all of the access modes allowed
acl:mode
acl:Read, acl:Write, acl:Control.
10 changes: 10 additions & 0 deletions templates/profile/card$.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@prefix foaf: <http://xmlns.com/foaf/0.1/>.

<>
a foaf:PersonalProfileDocument;
foaf:maker <{{webId}}>;
foaf:primaryTopic <{{webId}}>.

<{{webId}}>
a foaf:Person;
foaf:name "{{name}}".
4 changes: 4 additions & 0 deletions test/configs/middleware.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"files-scs:config/presets/cli-params.json"
],
"@graph": [
{
"@id": "urn:solid-server:default:PodManagerHandler",
"@type": "Variable"
},
{
"@id": "urn:solid-server:default:LdpHandler",
"@type": "Variable"
Expand Down
1 change: 1 addition & 0 deletions test/configs/websockets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"files-scs:config/presets/ldp/request-parser.json",
"files-scs:config/presets/ldp/websockets.json",
"files-scs:config/presets/middleware.json",
"files-scs:config/presets/pod-management.json",
"files-scs:config/presets/representation-conversion.json",
"files-scs:config/presets/storage/backend/storage-memory.json",
"files-scs:config/presets/storage/routing/no-routing.json",
Expand Down
1 change: 1 addition & 0 deletions test/integration/Middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('An Express server with middleware', (): void => {
beforeAll(async(): Promise<void> => {
const factory = await instantiateFromConfig(
'urn:solid-server:default:ExpressHttpServerFactory', 'middleware.json', {
'urn:solid-server:default:PodManagerHandler': new SimpleHttpHandler(),
'urn:solid-server:default:LdpHandler': new SimpleHttpHandler(),
'urn:solid-server:default:variable:port': port,
'urn:solid-server:default:variable:baseUrl': 'https://example.pod/',
Expand Down
1 change: 1 addition & 0 deletions test/integration/WebSocketsProtocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('A server with the Solid WebSockets API behind a proxy', (): void => {
'urn:solid-server:default:ServerFactory', 'websockets.json', {
'urn:solid-server:default:variable:port': port,
'urn:solid-server:default:variable:baseUrl': 'https://example.pod/',
'urn:solid-server:default:variable:podTemplateFolder': 'templates',
},
) as HttpServerFactory;
server = factory.startServer(port);
Expand Down
5 changes: 5 additions & 0 deletions test/unit/init/CliRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('CliRunner', (): void => {
'urn:solid-server:default:variable:rootFilePath': process.cwd(),
'urn:solid-server:default:variable:sparqlEndpoint': undefined,
'urn:solid-server:default:variable:loggingLevel': 'info',
'urn:solid-server:default:variable:podTemplateFolder': path.join(__dirname, '../../../templates'),
},
},
);
Expand All @@ -63,6 +64,7 @@ describe('CliRunner', (): void => {
'-f', '/root',
'-s', 'http://localhost:5000/sparql',
'-l', 'debug',
'-t', 'templates',
],
});
await mockSetup.setup();
Expand All @@ -78,6 +80,7 @@ describe('CliRunner', (): void => {
'urn:solid-server:default:variable:rootFilePath': '/root',
'urn:solid-server:default:variable:sparqlEndpoint': 'http://localhost:5000/sparql',
'urn:solid-server:default:variable:loggingLevel': 'debug',
'urn:solid-server:default:variable:podTemplateFolder': 'templates',
},
},
);
Expand All @@ -93,6 +96,7 @@ describe('CliRunner', (): void => {
'--rootFilePath', '/root',
'--sparqlEndpoint', 'http://localhost:5000/sparql',
'--loggingLevel', 'debug',
'--podTemplateFolder', 'templates',
],
});
await mockSetup.setup();
Expand All @@ -108,6 +112,7 @@ describe('CliRunner', (): void => {
'urn:solid-server:default:variable:rootFilePath': '/root',
'urn:solid-server:default:variable:sparqlEndpoint': 'http://localhost:5000/sparql',
'urn:solid-server:default:variable:loggingLevel': 'debug',
'urn:solid-server:default:variable:podTemplateFolder': 'templates',
},
},
);
Expand Down

0 comments on commit 1a043ac

Please sign in to comment.