This repository has been archived by the owner on Sep 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
system_schema.js
107 lines (96 loc) · 2.87 KB
/
system_schema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'use strict';
const _ = require('lodash');
const { getPlugin } = require('./lib/utils');
const schema = {
shutdown_timeout: {
doc: 'seconds util force shutdown will occur when exiting the app',
default: 60
},
port: {
doc: 'port which the server will listen to',
default: 8000
},
ssl_path: {
doc: 'path to directory where the ssl certs are located',
default: '/app/config/ssl'
},
elasticsearch_sessions: {
doc: 'enable elasticsearch sessions',
default: true
},
ttl: {
doc: 'session time to live duration',
default: 1000 * 60 * 60 * 24
},
plugins: {
names: {
doc: 'list of plugins that will be uploaded into TeraServer',
default: ['teranaut']
},
path: {
doc: 'Location of service plugins',
default: '/app/api/plugins'
}
},
static_assets: {
doc: 'Location of static HTTP assets',
default: '/app/api/public'
},
name: {
doc: 'Name for the cluster itself, its used for naming log files/indices',
default: 'teraserver',
format: (val) => {
if (val && typeof val !== 'string') {
throw new Error('This field is required and must by of type string');
}
},
},
connection: {
doc: 'Elasticsearch cluster where session state is stored',
default: 'default',
format(val) {
if (typeof val !== 'string') {
throw new Error('connection parameter must be of type String as the value');
}
}
},
request_timeout: {
doc: 'How long in milliseconds HTTP requests will wait before timing out.',
default: 120000
},
};
function getPluginSchema(plugin) {
let pluginSchemaDict = {};
if (plugin.config_schema) {
if (typeof plugin.config_schema === 'function') {
pluginSchemaDict = plugin.config_schema();
} else if (typeof plugin.config_schema === 'object') {
pluginSchemaDict = plugin.config_schema;
}
}
return pluginSchemaDict;
}
function pluginSchema(config) {
const schemaDict = {};
const { plugins } = config.teraserver;
if (plugins && plugins.names.length > 0) {
plugins.names.forEach((name) => {
const plugin = getPlugin(name, config);
schemaDict[name] = getPluginSchema(plugin);
});
}
return schemaDict;
}
function configSchema(config) {
if (!config.teraserver) {
// eslint-disable-next-line no-console
console.error('No configuration specified, use -c or the TERAFOUNDATION_CONFIG environment');
process.exit(1);
}
const paritialSchema = pluginSchema(config);
return _.merge({ teraserver: schema }, paritialSchema);
}
module.exports = {
configSchema,
schema
};