Skip to content

Commit

Permalink
feat: Allow for custom CLI and variable options
Browse files Browse the repository at this point in the history
* feat: (AppRunner) Mechanism to configure cli args and derive componentsjs vars from them implemented

* fix: (AppRunner) tidying

* fix: (AppRunner) tidying up

* fix: (AppRunner) runCli method made sync

* fix; (VarResolver) refactored to multiple files, and other stylistic fixes.

* chore: (AppRunner) Uses builder pattern for yargs base arguments setup to enable better typescript inference

* fix(AppRunner): refactoring AppRunner and VarResolver

* fix(AppRunner): refactoring AppRunner promise handling

* fix(AppRunner): verror dependency removal

* fix: Simplify CLI error handling

* feat: Use same config for both CLI and app instantiation

* fix: Update typings and imports

* feat: Split VariableResolver behaviour to 2 classes

* feat: Move default value behaviour from CLI to ValueComputers

* test: Add unit tests for new CLI classes

* feat: Integrate new CLI configuration with all default configurations

* feat: Add createApp function to AppRunner

* docs: Update comments in CLI-related classes

* fix: Various fixes and refactors

Co-authored-by: damooo <damodara@protonmail.com>
  • Loading branch information
joachimvh and damooo authored Feb 11, 2022
1 parent d067165 commit c216efd
Show file tree
Hide file tree
Showing 39 changed files with 1,003 additions and 350 deletions.
11 changes: 9 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
## v3.0.0
### New features
- The Identity Provider now uses the `webid` scope as required for Solid-OIDC.
- The `VoidLocker` can be used to disable locking for development/testing purposes. This can be enabled by changing the `/config/util/resource-locker/` import to `debug-void.json`
- The `VoidLocker` can be used to disable locking for development/testing purposes.
This can be enabled by changing the `/config/util/resource-locker/` import to `debug-void.json`
- Added support for setting a quota on the server. See the `config/quota-file.json` config for an example.
- An official docker image is now built on each version tag and published at https://hub.docker.com/r/solidproject/community-server.
- Added support for N3 Patch.
- It is now possible to customize arguments to the `community-solid-server` command,
which enables passing custom variables to configurations and setting new default values.
- The AppRunner functions have changed to require Components.js variables.
This is important for anyone who starts the server from code.

### Configuration changes
You might need to make changes to your v2 configuration if you use a custom config.

The following changes pertain to the imports in the default configs:
- ...
- A new configuration option needs to be imported:
- `/app/variables/default/json` contains everything related to parsing CLI arguments
and assigning values to variables.

The following changes are relevant for v2 custom configs that replaced certain features.
- Conversion has been simplified so most converters are part of the conversion chain:
Expand Down
3 changes: 1 addition & 2 deletions bin/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
// eslint-disable-next-line @typescript-eslint/naming-convention
const { AppRunner } = require('..');
new AppRunner().runCli(process);
new AppRunner().runCliSync(process);
8 changes: 8 additions & 0 deletions config/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ Handles the setup page the first time the server is started.
* *optional*: Setup is available at `/setup` but the server can already be used.
Everyone can access the setup page so make sure to complete that as soon as possible.
* *required*: All requests will be redirected to the setup page until setup is completed.

## Variables
Handles parsing CLI parameters and assigning values to Components.js variables.
Some parts of the configuration contains variables that can be set as arguments on the command-line.
That way, you don't have to edit the configuration files for small changes,
such as starting the server with a different hostname.
Here, you can customize the mapping from CLI arguments into values for those variables.
* *default*: Assigns CLI parameters for all variables defined in `/config/util/variables/default.json`
67 changes: 67 additions & 0 deletions config/app/variables/cli/cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^2.0.0/components/context.jsonld",
"@graph": [
{
"comment": "Extracts CLI arguments into a key/value object. Config and mainModulePath are only defined here so their description is returned.",
"@id": "urn:solid-server-app-setup:default:CliExtractor",
"@type": "YargsCliExtractor",
"parameters": {
"config": {
"alias": "c",
"requiresArg": true,
"type": "string",
"describe": "The configuration for the server. The default only stores data in memory; to persist to your filesystem, use @css:config/file.json."
},
"mainModulePath": {
"alias": "m",
"requiresArg": true,
"type": "string",
"describe": "Path from where Components.js will start its lookup when initializing configurations."
},
"loggingLevel": {
"alias": "l",
"requiresArg": true,
"type": "string",
"describe": "The detail level of logging; useful for debugging problems."
},
"baseUrl": {
"alias": "b",
"requiresArg": true,
"type": "string",
"describe": "The public URL of your server."
},
"port": {
"alias": "p",
"requiresArg": true,
"type": "number",
"describe": "The TCP port on which the server runs."
},
"rootFilePath": {
"alias": "f",
"requiresArg": true,
"type": "string",
"describe": "Root folder of the server, when using a file-based configuration."
},
"showStackTrace": {
"alias": "t",
"type": "boolean",
"describe": "Enables detailed logging on error pages."
},
"sparqlEndpoint": {
"alias": "s",
"requiresArg": true,
"type": "string",
"describe": "URL of the SPARQL endpoint, when using a quadstore-based configuration."
},
"podConfigJson": {
"requiresArg": true,
"type": "string",
"describe": "Path to the file that keeps track of dynamic Pod configurations."
}
},
"options": {
"usage": "node ./bin/server.js [args]"
}
}
]
}
16 changes: 16 additions & 0 deletions config/app/variables/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^2.0.0/components/context.jsonld",
"import": [
"files-scs:config/app/variables/cli/cli.json",
"files-scs:config/app/variables/resolver/resolver.json"
],
"@graph": [
{
"comment": "Combines a CliExtractor and SettingsResolver to be used by the AppRunner.",
"@id": "urn:solid-server-app-setup:default:CliResolver",
"@type": "CliResolver",
"cliExtractor": { "@id": "urn:solid-server-app-setup:default:CliExtractor" },
"settingsResolver": { "@id": "urn:solid-server-app-setup:default:SettingsResolver" }
}
]
}
65 changes: 65 additions & 0 deletions config/app/variables/resolver/resolver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^2.0.0/components/context.jsonld",
"@graph": [
{
"comment": "Converts an input key/value object into an object mapping values to Components.js variables",
"@id": "urn:solid-server-app-setup:default:SettingsResolver",
"@type": "CombinedSettingsResolver",
"computers": [
{
"CombinedSettingsResolver:_computers_key": "urn:solid-server:default:variable:baseUrl",
"CombinedSettingsResolver:_computers_value": {
"@type": "BaseUrlExtractor"
}
},
{
"CombinedSettingsResolver:_computers_key": "urn:solid-server:default:variable:loggingLevel",
"CombinedSettingsResolver:_computers_value": {
"@type": "KeyExtractor",
"key": "loggingLevel",
"defaultValue": "info"
}
},
{
"CombinedSettingsResolver:_computers_key": "urn:solid-server:default:variable:port",
"CombinedSettingsResolver:_computers_value": {
"@type": "KeyExtractor",
"key": "port",
"defaultValue": 3000
}
},
{
"CombinedSettingsResolver:_computers_key": "urn:solid-server:default:variable:rootFilePath",
"CombinedSettingsResolver:_computers_value": {
"@type": "AssetPathExtractor",
"key": "rootFilePath",
"defaultPath": "./"
}
},
{
"CombinedSettingsResolver:_computers_key": "urn:solid-server:default:variable:sparqlEndpoint",
"CombinedSettingsResolver:_computers_value": {
"@type": "KeyExtractor",
"key": "sparqlEndpoint"
}
},
{
"CombinedSettingsResolver:_computers_key": "urn:solid-server:default:variable:showStackTrace",
"CombinedSettingsResolver:_computers_value": {
"@type": "KeyExtractor",
"key": "showStackTrace",
"defaultValue": false
}
},
{
"CombinedSettingsResolver:_computers_key": "urn:solid-server:default:variable:AssetPathResolver",
"CombinedSettingsResolver:_computers_value": {
"@type": "AssetPathExtractor",
"key": "podConfigJson",
"defaultPath": "./pod-config.json"
}
}
]
}
]
}
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/initialize-prefilled-root.json",
"files-scs:config/app/setup/optional.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",
"files-scs:config/http/server-factory/websockets.json",
Expand Down
1 change: 1 addition & 0 deletions config/dynamic.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/default.json",
"files-scs:config/app/setup/required.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",
"files-scs:config/http/server-factory/websockets.json",
Expand Down
1 change: 1 addition & 0 deletions config/example-https-file.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/default.json",
"files-scs:config/app/setup/required.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",

Expand Down
1 change: 1 addition & 0 deletions config/file-no-setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/initialize-root.json",
"files-scs:config/app/setup/disabled.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",
"files-scs:config/http/server-factory/websockets.json",
Expand Down
1 change: 1 addition & 0 deletions config/file.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/default.json",
"files-scs:config/app/setup/required.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",
"files-scs:config/http/server-factory/websockets.json",
Expand Down
1 change: 1 addition & 0 deletions config/memory-subdomains.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/initialize-root.json",
"files-scs:config/app/setup/optional.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",
"files-scs:config/http/server-factory/websockets.json",
Expand Down
1 change: 1 addition & 0 deletions config/path-routing.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/initialize-root.json",
"files-scs:config/app/setup/disabled.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",
"files-scs:config/http/server-factory/websockets.json",
Expand Down
1 change: 1 addition & 0 deletions config/restrict-idp.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/default.json",
"files-scs:config/app/setup/disabled.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",
"files-scs:config/http/server-factory/websockets.json",
Expand Down
1 change: 1 addition & 0 deletions config/sparql-endpoint-no-setup.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/initialize-root.json",
"files-scs:config/app/setup/disabled.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",
"files-scs:config/http/server-factory/websockets.json",
Expand Down
1 change: 1 addition & 0 deletions config/sparql-endpoint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files-scs:config/app/main/default.json",
"files-scs:config/app/init/default.json",
"files-scs:config/app/setup/required.json",
"files-scs:config/app/variables/default.json",
"files-scs:config/http/handler/default.json",
"files-scs:config/http/middleware/websockets.json",
"files-scs:config/http/server-factory/websockets.json",
Expand Down
2 changes: 1 addition & 1 deletion config/util/variables/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@type": "Variable"
},
{
"comment": "Needs to be set to the base URL of the server for authnetication and authorization to function.",
"comment": "Needs to be set to the base URL of the server for authentication and authorization to function.",
"@id": "urn:solid-server:default:variable:baseUrl",
"@type": "Variable"
},
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"@types/url-join": "^4.0.0",
"@types/uuid": "^8.3.0",
"@types/ws": "^8.2.0",
"@types/yargs": "^17.0.0",
"@types/yargs": "^17.0.8",
"arrayify-stream": "^1.0.0",
"async-lock": "^1.3.0",
"bcrypt": "^5.0.1",
Expand Down
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,24 @@ export * from './init/final/ParallelFinalizer';
// Init/Setup
export * from './init/setup/SetupHttpHandler';

// Init/Cli
export * from './init/cli/CliExtractor';
export * from './init/cli/YargsCliExtractor';

// Init/Variables/Extractors
export * from './init/variables/extractors/KeyExtractor';
export * from './init/variables/extractors/AssetPathExtractor';
export * from './init/variables/extractors/BaseUrlExtractor';
export * from './init/variables/extractors/SettingsExtractor';

// Init/Variables
export * from './init/variables/CombinedSettingsResolver';
export * from './init/variables/SettingsResolver';

// Init
export * from './init/App';
export * from './init/AppRunner';
export * from './init/CliResolver';
export * from './init/ConfigPodInitializer';
export * from './init/ContainerInitializer';
export * from './init/Initializer';
Expand Down
Loading

0 comments on commit c216efd

Please sign in to comment.