Helpers and common tools for the hpi school-cloud.
Configuration is a singleton that can be reused to hold a configuration that is validated by JSON Schema. A JSON-Schema has to be defined as default.schema.json inside a config folder.
default.schema.json
default.json (values have to be defined here, for properties required in the schema too beside the schema default)
NODE_ENV.json from config folder (defaults to development.json, if NODE_ENV is not defined - the file existence is optionally)
NODE_ENV by default, SC_INSTANCE.
.env file from execution/project root directory
"additionalProperties": false
__ (double underscore) is supported as separator due to the dependency dotenv and bad support of . (single dot) in many terminals.
printHierarchy() to print the whole hierarchy of a configuration. For security reasons, by default all values of string typed properties having secret or key in their name will be replaced with a hash-id. Same hashes identify same original values.
SECRET_ in their name and use type string.
SERVICE_REQUIRES_OTHER rule is activated in the allOf block.
definitions block.
SERVICE_PROPERTY is set to VALUE_OF_SERVICE we also require that OTHER_PROPERTY is set.
SERVICE_PROPERTY to avoid passing undefined to an if keyword.
any | console | a logger instance |
boolean | true | enable throwing an error when an undefined configuration value is requested |
any | null | if throwOnError is not set true, an alternate default value may returned |
string | config | directory where schema and configuration files are located |
string | default.schema.json | default schema file name |
string | process.cwd() | path to folder where configDir is located |
object | removeAdditional: 'true' useDefaults: true coerceTypes: 'array' | Schema Parser Options, see boolean | true | enables dot notation for parsing environment variables (not json files!) and exporting the current config using has, get, and toObject. |
string | 'utf8' | set file encoding for imported schema and configuration files |
string[] | ['NODE_ENV'] | defines the order of configuration files loaded by specified environment values filename must have json extension like NODE_ENV.json |
boolean | false | executes printHierarchy() right after initialization |
boolean | false | by default, secrets are replaced by hashes which are equal for same values using printHierarchy function. Set this true to print configuration values of keys containing secret or key. |
string[] | ['SECRET', 'KEY', 'SALT', 'PASSWORD'] | properties matching these expressions (flags added are /gi) are handled as secrets and will be hashed before printing |