@nsshunt/stsconfig 1.12.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/stsconfig.js CHANGED
@@ -16,7 +16,9 @@ require('dotenv').config({ path: envfile });
16
16
  const defconfig =
17
17
  {
18
18
  // Node runtime environment
19
- isProduction: (process.env.NODE_ENV === undefined ? false : process.env.NODE_ENV === 'production')
19
+ isProduction: (process.env.NODE_ENV === undefined ? false : (process.env.NODE_ENV === 'production' ? true : false))
20
+ // Node runtime environment
21
+ ,isTest: (process.env.NODE_ENV === undefined ? false : (process.env.NODE_ENV === 'test' ? true : false))
20
22
  // Log error messages to the console within the microservice
21
23
  ,consoleLogErrors: (process.env.CONSOLE_LOG_ERRORS === undefined ? false : (process.env.CONSOLE_LOG_ERRORS === "true" ? true : false ))
22
24
  // Database username.
@@ -44,7 +46,7 @@ const defconfig =
44
46
  // Automatically re-spawn a worker thread if one dies.
45
47
  ,respawnOnFail: (process.env.RESPAWN === undefined ? false : (process.env.RESPAWN === "true" ? true : false ))
46
48
  // Default number of entries to create for a fresh database.
47
- ,defaultDatabaseEntries: (process.env.DEFAULT_DB_ENTRIES === undefined ? 10000 : process.env.DEFAULT_DB_ENTRIES)
49
+ ,defaultDatabaseEntries: (process.env.DEFAULT_DB_ENTRIES === undefined ? 10000 : parseInt(process.env.DEFAULT_DB_ENTRIES))
48
50
  // Microservice listen port.
49
51
  ,useRedis: (process.env.USE_REDIS === undefined ? false : (process.env.USE_REDIS === "true" ? true : false ))
50
52
  // Use redis for Microservice.
@@ -70,6 +72,10 @@ const defconfig =
70
72
  ,rest01port: (process.env.REST01_PORT === undefined ? "3003" : process.env.REST01_PORT)
71
73
  // STSREST01 Server endpoint
72
74
  ,rest01apiroot: (process.env.REST01_APIROOT === undefined ? "/stsrest01/v1" : process.env.REST01_APIROOT)
75
+ // STSREST01 API Identifier. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
76
+ ,rest01apiidentifier: process.env.REST01_API_IDENTIFIER
77
+ // STSREST01 API Identifier file. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
78
+ ,rest01apiidentifierfile: process.env.REST01_API_IDENTIFIER_FILE
73
79
  // STSREST01 Prometheus metric support
74
80
  ,rest01prometheussupport: (process.env.REST01_PROM_SUPPORT === undefined ? true : (process.env.REST01_PROM_SUPPORT === "true" ? true : false))
75
81
  // STSREST01 Cluster Server port (port used for cluster prometheus scrapes). Service will listen on this port at mount point /metrics
@@ -78,14 +84,16 @@ const defconfig =
78
84
  ,rest01servicename: (process.env.REST01_SERVICE_NAME === undefined ? "STSRest01" : process.env.REST01_SERVICE_NAME)
79
85
  // STSREST01 Service Version
80
86
  ,rest01serviceversion: (process.env.REST01_SERVICE_VERSION === undefined ? "1.0.0" : process.env.REST01_SERVICE_VERSION)
81
- // STSREST01 Service Credentials
82
- // -----------------------------
83
- // STSREST01 Server username email
84
- ,rest01email: (process.env.REST01_EMAIL === undefined ? "K6TestUser@sts" : process.env.REST01_EMAIL)
85
- // STSREST01 Server username password
86
- ,rest01password: (process.env.REST01_PASSWORD === undefined ? "K6TestUserPassword" : process.env.REST01_PASSWORD)
87
- // STSREST01 Server username password file
88
- ,rest01passwordfile: process.env.REST01_PASSWORD_FILE
87
+ // STSREST01 Server client ID. Used for oauth2 client credentials flow.
88
+ // Ref: https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow
89
+ // Ref: https://auth0.com/docs/get-started/authentication-and-authorization-flow/call-your-api-using-the-client-credentials-flow
90
+ ,rest01clientid: process.env.REST01_CLIENT_ID
91
+ // STSREST01 Server client ID file. Used for oauth2 client credentials flow.
92
+ ,rest01clientidfile: process.env.REST01_CLIENT_ID_FILE
93
+ // STSREST01 Server client secret. Used for oauth2 client credentials flow.
94
+ ,rest01clientsecret: process.env.REST01_CLIENT_SECRET
95
+ // STSREST01 Server client secret file. Used for oauth2 client credentials flow.
96
+ ,rest01clientsecretfile: process.env.REST01_CLIENT_SECRET_FILE
89
97
 
90
98
  // STS Instrument Manager Service endpoint
91
99
  ,imendpoint: (process.env.IM_ENDPOINT === undefined ? "http://localhost" : process.env.IM_ENDPOINT)
@@ -95,6 +103,10 @@ const defconfig =
95
103
  ,import: (process.env.IM_PORT === undefined ? "3001" : process.env.IM_PORT)
96
104
  // STS Instrument Manager Service endpoint
97
105
  ,imapiroot: (process.env.IM_APIROOT === undefined ? "/stsinstrumentmanager/v1" : process.env.IM_APIROOT)
106
+ // Instrument Manager API Identifier. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
107
+ ,imapiidentifier: process.env.IM_API_IDENTIFIER
108
+ // Instrument Manager API Identifier file. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
109
+ ,imapiidentifierfile: process.env.IM_API_IDENTIFIER_FILE
98
110
  // STS Instrument Manager Prometheus metric support
99
111
  ,imprometheussupport: (process.env.IM_PROM_SUPPORT === undefined ? true : (process.env.IM_PROM_SUPPORT === "true" ? true : false ))
100
112
  // STS Instrument Manager Cluster Server port (port used for cluster prometheus scrapes)
@@ -103,14 +115,14 @@ const defconfig =
103
115
  ,imservicename: (process.env.IM_SERVICE_NAME === undefined ? "STSInstrumentManager" : process.env.IM_SERVICE_NAME)
104
116
  // STS Instrument Manager Service Version
105
117
  ,imserviceversion: (process.env.IM_SERVICE_VERSION === undefined ? "1.0.0" : process.env.IM_SERVICE_VERSION)
106
- // STS Instrument Manager Service Credentials
107
- // ------------------------------------------
108
- // STS Instrument Manager Service username email
109
- ,imemail: (process.env.IM_EMAIL === undefined ? "K6TestUser@sts" : process.env.IM_EMAIL)
110
- // STS Instrument Manager Service username password
111
- ,impassword: (process.env.IM_PASSWORD === undefined ? "K6TestUserPassword" : process.env.IM_PASSWORD)
112
- // STS Instrument Manager Service username password file
113
- ,impasswordfile: process.env.IM_PASSWORD_FILE
118
+ // STS Instrument Manager Server client ID. Used for oauth2 client credentials flow.
119
+ ,imclientid: process.env.IM_CLIENT_ID
120
+ // STS Instrument Manager Server client ID file. Used for oauth2 client credentials flow.
121
+ ,imclientidfile: process.env.IM_CLIENT_ID_FILE
122
+ // STS Instrument Manager Server client secret. Used for oauth2 client credentials flow.
123
+ ,imclientsecret: process.env.IM_CLIENT_SECRET
124
+ // STS Instrument Manager Server client secret file. Used for oauth2 client credentials flow.
125
+ ,imclientsecretfile: process.env.IM_CLIENT_SECRET_FILE
114
126
 
115
127
  // STS Test Orchestrator Service endpoint
116
128
  ,toendpoint: (process.env.TO_ENDPOINT === undefined ? "http://localhost" : process.env.TO_ENDPOINT)
@@ -120,6 +132,10 @@ const defconfig =
120
132
  ,toport: (process.env.TO_PORT === undefined ? "3004" : process.env.TO_PORT)
121
133
  // STS Test Orchestrator Service endpoint
122
134
  ,toapiroot: (process.env.TO_APIROOT === undefined ? "/ststestorchestrator/v1" : process.env.TO_APIROOT)
135
+ // Test Orchestrator API Identifier. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
136
+ ,toapiidentifier: process.env.TO_API_IDENTIFIER
137
+ // Test Orchestrator API Identifier file. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
138
+ ,toapiidentifierfile: process.env.TO_API_IDENTIFIER_FILE
123
139
  // STS Test Orchestrator Prometheus metric support
124
140
  ,toprometheussupport: (process.env.TO_PROM_SUPPORT === undefined ? true : (process.env.TO_PROM_SUPPORT === "true" ? true : false ))
125
141
  // STS Test Orchestrator Cluster Server port (port used for cluster prometheus scrapes)
@@ -128,15 +144,19 @@ const defconfig =
128
144
  ,toservicename: (process.env.TO_SERVICE_NAME === undefined ? "STSTestOrchestrator" : process.env.TO_SERVICE_NAME)
129
145
  // STS Test Orchestrator Service Version
130
146
  ,toserviceversion: (process.env.TO_SERVICE_VERSION === undefined ? "1.0.0" : process.env.TO_SERVICE_VERSION)
131
- // STS Test Orchestrator Service Credentials
132
- // ------------------------------------------
133
- // STS Test Orchestrator Service username email
134
- ,toemail: (process.env.TO_EMAIL === undefined ? "K6TestUser@sts" : process.env.TO_EMAIL)
135
- // STS Test Orchestrator Service username password
136
- ,topassword: (process.env.TO_PASSWORD === undefined ? "K6TestUserPassword" : process.env.TO_PASSWORD)
137
- // STS Test Orchestrator Service username password file
138
- ,topasswordfile: process.env.TO_PASSWORD_FILE
147
+ // STS Test Orchestrator Server client ID. Used for oauth2 client credentials flow.
148
+ ,toclientid: process.env.TO_CLIENT_ID
149
+ // STS Test Orchestrator Server client ID file. Used for oauth2 client credentials flow.
150
+ ,toclientidfile: process.env.TO_CLIENT_ID_FILE
151
+ // STS Test Orchestrator Server client secret. Used for oauth2 client credentials flow.
152
+ ,toclientsecret: process.env.TO_CLIENT_SECRET
153
+ // STS Test Orchestrator Server client secret file. Used for oauth2 client credentials flow.
154
+ ,toclientsecretfile: process.env.TO_CLIENT_SECRET_FILE
139
155
 
156
+ // STS Auth Server
157
+ // ---------------
158
+ // The auth server assumes the roles as an Identify Provider ([TODO]) and Token Server (OAuth2.0).
159
+ //
140
160
  // Auth Server endpoint
141
161
  ,asendpoint: (process.env.AS_ENDPOINT === undefined ? "http://localhost" : process.env.AS_ENDPOINT)
142
162
  // Auth Server host port (listen port for the service)
@@ -145,6 +165,10 @@ const defconfig =
145
165
  ,asport: (process.env.AS_PORT === undefined ? "3002" : process.env.AS_PORT)
146
166
  // Auth Server endpoint
147
167
  ,asapiroot: (process.env.AS_APIROOT === undefined ? "/stsauth/v1" : process.env.AS_APIROOT)
168
+ // Auth Server API Identifier. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
169
+ ,asapiidentifier: process.env.AS_API_IDENTIFIER
170
+ // Auth Server API Identifier file. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
171
+ ,asapiidentifierfile: process.env.AS_API_IDENTIFIER_FILE
148
172
  // Auth Server Prometheus metric support
149
173
  ,asprometheussupport: (process.env.AS_PROM_SUPPORT === undefined ? true : (process.env.AS_PROM_SUPPORT === "true" ? true : false ))
150
174
  // Auth Prometheus Cluster Server port (port used for cluster prometheus scrapes)
@@ -153,19 +177,32 @@ const defconfig =
153
177
  ,asservicename: (process.env.AS_SERVICE_NAME === undefined ? "STSAuth" : process.env.AS_SERVICE_NAME)
154
178
  // STSAuth Service Version
155
179
  ,asserviceversion: (process.env.AS_SERVICE_VERSION === undefined ? "1.0.0" : process.env.AS_SERVICE_VERSION)
156
- // STS Auth Service Credentials
157
- // ----------------------------
158
- // Auth Server username email
159
- ,asemail: (process.env.AS_EMAIL === undefined ? "K6TestUser@sts" : process.env.AS_EMAIL)
160
- // Auth Server username password
161
- ,aspassword: (process.env.AS_PASSWORD === undefined ? "K6TestUserPassword" : process.env.AS_PASSWORD)
162
- // Auth Server username password file
163
- ,aspasswordfile: process.env.AS_PASSWORD_FILE
164
- // Auth Server - Private Key (when using JWT)
180
+ // STS Auth Server client ID. Used for oauth2 client credentials flow.
181
+ ,asclientid: process.env.AS_CLIENT_ID
182
+ // STS Auth Server client ID file. Used for oauth2 client credentials flow.
183
+ ,asclientidfile: process.env.AS_CLIENT_ID_FILE
184
+ // STS Auth Server client secret. Used for oauth2 client credentials flow.
185
+ ,asclientsecret: process.env.AS_CLIENT_SECRET
186
+ // STS Auth Server client secret file. Used for oauth2 client credentials flow.
187
+ ,asclientsecretfile: process.env.AS_CLIENT_SECRET_FILE
188
+ // Auth Server - JWKS Public End Point.
189
+ ,asjwksjsonpath: (process.env.AS_JWKS_JSON_PATH === undefined ? "/.well-known/jwks.json" : process.env.AS_JWKS_JSON_PATH)
190
+ // Auth Server - JWKS key rotation time (seconds).
191
+ ,asjwkskeyrotationtime: (process.env.AS_JWKS_KEY_ROTATION_TIME === undefined ? 86400 : parseInt(process.env.AS_JWKS_KEY_ROTATION_TIME)) // 24 Hour default
192
+ // Auth Server - JWKS key purge time offset (seconds). Old keys (current keys are considered 'old' immediately after a key rotation) will be kept
193
+ // for asaccesstokenexpire + asjwkskeypurgetimeoffset seconds before purging from the JWKS.
194
+ ,asjwkskeypurgetimeoffset: (process.env.AS_JWKS_KEY_PURGE_TIME_OFFSET === undefined ? 300 : parseInt(process.env.AS_JWKS_KEY_PURGE_TIME_OFFSET)) // 5 Minutes
195
+ // Auth Server - JWKS key count. Defines the number of active keys within the JWKS. Note that the actual key count may be double this value as current
196
+ // keys are rotated to old keys prior to old key purge. Old keys will be kept for asaccesstokenexpire + asjwkskeypurgetimeoffset seconds before removal from the JWKS.
197
+ // This is to ensure that any tokens signed by a current key that is then expired can still be validated within the life of the issued token.
198
+ ,asjwkskeycount: (process.env.AS_JWKS_KEY_COUNT === undefined ? 4 : parseInt(process.env.AS_JWKS_KEY_COUNT))
199
+ // Auth Server - JWKS Access token timeout.
200
+ ,asaccesstokenexpire: (process.env.AS_ACCESS_TOKEN_EXPIRE === undefined ? 43200 : parseInt(process.env.AS_ACCESS_TOKEN_EXPIRE)) // 12 Hour default
201
+ // Auth Server - [DEPRECATED] Private Key (when using JWT)
165
202
  ,asprivatekeypath: (process.env.AS_PRIVATE_KEY_PATH === undefined ? "/var/lib/sts/stsglobalresources/keys/private.key" : process.env.AS_PRIVATE_KEY_PATH)
166
- // Auth Server - Public Key (when using JWT)
203
+ // Auth Server - [DEPRECATED] Public Key (when using JWT)
167
204
  ,aspublickeypath: (process.env.AS_PUBLIC_KEY_PATH === undefined ? "/var/lib/sts/stsglobalresources/keys/public.key" : process.env.AS_PUBLIC_KEY_PATH)
168
-
205
+
169
206
  // STS Test Runner Prometheus metric support
170
207
  ,trprometheussupport: (process.env.TR_PROM_SUPPORT === undefined ? true : (process.env.TR_PROM_SUPPORT === "true" ? true : false ))
171
208
  // STS Test Runner Cluster Server port (port used for cluster prometheus scrapes)
@@ -174,14 +211,14 @@ const defconfig =
174
211
  ,trservicename: (process.env.TR_SERVICE_NAME === undefined ? "STSRestRunner" : process.env.TR_SERVICE_NAME)
175
212
  // STS Test Runner Service Version
176
213
  ,trserviceversion: (process.env.TR_SERVICE_VERSION === undefined ? "1.0.0" : process.env.TR_SERVICE_VERSION)
177
- // STS Test Runner Credentials
178
- // ----------------------------
179
- // STS Test Runner username email
180
- ,tremail: (process.env.TR_EMAIL === undefined ? "K6TestUser@sts" : process.env.TR_EMAIL)
181
- // STS Test Runner password
182
- ,trpassword: (process.env.TR_PASSWORD === undefined ? "K6TestUserPassword" : process.env.TR_PASSWORD)
183
- // STS Test Runner password file
184
- ,trpasswordfile: process.env.TR_PASSWORD_FILE
214
+ // STS Test Runner Server client ID. Used for oauth2 client credentials flow.
215
+ ,trclientid: process.env.TR_CLIENT_ID
216
+ // STS Test Runner Server client ID file. Used for oauth2 client credentials flow.
217
+ ,trclientidfile: process.env.TR_CLIENT_ID_FILE
218
+ // STS Test Runner Server client secret. Used for oauth2 client credentials flow.
219
+ ,trclientsecret: process.env.TR_CLIENT_SECRET
220
+ // STS Test Runner Server client secret file. Used for oauth2 client credentials flow.
221
+ ,trclientsecretfile: process.env.TR_CLIENT_SECRET_FILE
185
222
 
186
223
  // Duration (in ms) between each publish event.
187
224
  ,publishinterval: (process.env.PUBLISH_INTERVAL === undefined ? 1000 : parseInt(process.env.PUBLISH_INTERVAL))
@@ -194,7 +231,7 @@ const defconfig =
194
231
  ,publishdebug: (process.env.PUBLISH_DEBUG === undefined ? false : (process.env.PUBLISH_DEBUG === "true" ? true : false ))
195
232
 
196
233
  // Transport(s) to use for sending instrumentation data to the instrumentation server
197
- ,transport: (process.env.TRANSPORT === undefined ? 0 : process.env.TRANSPORT)
234
+ ,transport: (process.env.TRANSPORT === undefined ? 'RESTAPI' : process.env.TRANSPORT)
198
235
 
199
236
  /*
200
237
  // Instrument Defaults
@@ -215,31 +252,31 @@ const defconfig =
215
252
  // This setting will be ignore for production mode. In production mode services will always use secure cookies.
216
253
  ,useSecureCookies: (process.env.USE_SECURE_COOKIES === undefined ? false : (process.env.USE_SECURE_COOKIES === "true" ? true : false ))
217
254
 
218
- ,keepAlive: (process.env.KEEP_ALIVE === undefined ? true : (process.env.KEEP_ALIVE === "true" ? true : false ))
219
- // Reference: https://nodejs.org/api/http.html#class-httpagent
220
255
  // keepAlive <boolean> Keep sockets around even when there are no outstanding requests, so they can be used for future requests without having to reestablish a
221
256
  // TCP connection. Not to be confused with the keep-alive value of the Connection header. The Connection: keep-alive header is always sent when using an agent
222
257
  // except when the Connection header is explicitly specified or when the keepAlive and maxSockets options are respectively set to false and Infinity, in which
223
258
  // case Connection: close will be used. Default: false.
224
-
225
- ,maxSockets: (process.env.MAX_SOCKETS === undefined ? 10 : parseInt(process.env.MAX_SOCKETS))
226
259
  // Reference: https://nodejs.org/api/http.html#class-httpagent
260
+ ,keepAlive: (process.env.KEEP_ALIVE === undefined ? true : (process.env.KEEP_ALIVE === "true" ? true : false ))
261
+
227
262
  // maxSockets <number> Maximum number of sockets to allow per host. If the same host opens multiple concurrent connections, each request will use new socket until the
228
263
  // maxSockets value is reached. If the host attempts to open more connections than maxSockets, the additional requests will enter into a pending request queue, and will
229
264
  // enter active connection state when an existing connection terminates. This makes sure there are at most maxSockets active connections at any point in time,
230
265
  // from a given host. Default: Infinity.
231
-
232
- ,maxTotalSockets: (process.env.MAX_TOTAL_SOCKETS === undefined ? 20 : parseInt(process.env.MAX_TOTAL_SOCKETS))
233
266
  // Reference: https://nodejs.org/api/http.html#class-httpagent
234
- // maxTotalSockets <number> Maximum number of sockets allowed for all hosts in total. Each request will use a new socket until the maximum is reached. Default: Infinity.
267
+ ,maxSockets: (process.env.MAX_SOCKETS === undefined ? 10 : parseInt(process.env.MAX_SOCKETS))
235
268
 
236
- ,maxFreeSockets: (process.env.MAX_FREE_SOCKETS === undefined ? 256 : parseInt(process.env.MAX_FREE_SOCKETS))
269
+ // maxTotalSockets <number> Maximum number of sockets allowed for all hosts in total. Each request will use a new socket until the maximum is reached. Default: Infinity.
237
270
  // Reference: https://nodejs.org/api/http.html#class-httpagent
238
- // maxFreeSockets <number> Maximum number of sockets per host to leave open in a free state. Only relevant if keepAlive is set to true. Default: 256.
271
+ ,maxTotalSockets: (process.env.MAX_TOTAL_SOCKETS === undefined ? 20 : parseInt(process.env.MAX_TOTAL_SOCKETS))
239
272
 
240
- ,timeout: (process.env.TIMEOUT === undefined ? 10000 : parseInt(process.env.TIMEOUT))
273
+ // maxFreeSockets <number> Maximum number of sockets per host to leave open in a free state. Only relevant if keepAlive is set to true. Default: 256.
241
274
  // Reference: https://nodejs.org/api/http.html#class-httpagent
275
+ ,maxFreeSockets: (process.env.MAX_FREE_SOCKETS === undefined ? 256 : parseInt(process.env.MAX_FREE_SOCKETS))
276
+
242
277
  // timeout <number> Socket timeout in milliseconds. This will set the timeout when the socket is created.
278
+ // Reference: https://nodejs.org/api/http.html#class-httpagent
279
+ ,timeout: (process.env.TIMEOUT === undefined ? 10000 : parseInt(process.env.TIMEOUT))
243
280
 
244
281
  // Maximum payload size allowed for express server calls
245
282
  ,maxPayloadSize: (process.env.MAX_PAYLOAD_SIZE === undefined ? '50mb' : process.env.MAX_PAYLOAD_SIZE)
@@ -288,7 +325,7 @@ const defconfig =
288
325
  */
289
326
  }
290
327
 
291
- const ReadPasswordFile = (passwordFile) => {
328
+ const ReadFile = (passwordFile) => {
292
329
  try {
293
330
  accessSync(passwordFile, constants.R_OK);
294
331
  const data = readFileSync(passwordFile, 'utf8');
@@ -300,35 +337,33 @@ const ReadPasswordFile = (passwordFile) => {
300
337
  }
301
338
  }
302
339
 
303
- // Database password file
304
- if (defconfig.dbpasswordfile !== undefined) {
305
- defconfig.dbpassword = ReadPasswordFile(defconfig.dbpasswordfile);
306
- }
307
-
308
- // Auth Server username password file
309
- if (defconfig.aspasswordfile !== undefined) {
310
- defconfig.aspassword = ReadPasswordFile(defconfig.aspasswordfile);
311
- }
312
-
313
- // STSREST01 Server username password file
314
- if (defconfig.rest01passwordfile !== undefined) {
315
- defconfig.rest01password = ReadPasswordFile(defconfig.rest01passwordfile);
316
- }
317
-
318
- // STS Test Runner password file
319
- if (defconfig.trpasswordfile !== undefined) {
320
- defconfig.trpassword = ReadPasswordFile(defconfig.trpasswordfile);
321
- }
322
-
323
- // STS Test Orchestrator Service username password file
324
- if (defconfig.topasswordfile !== undefined) {
325
- defconfig.topassword = ReadPasswordFile(defconfig.topasswordfile);
326
- }
327
-
328
- // STS Instrument Manager Service username password file
329
- if (defconfig.impasswordfile !== undefined) {
330
- defconfig.impassword = ReadPasswordFile(defconfig.impasswordfile);
331
- }
340
+ // File based configuration settings. If a file is specified for a setting, this will be used. The non file version (if specified) will be ignored.
341
+ const fileconfig = [
342
+ { fileprop: 'dbpasswordfile', prop: 'dbpassword' },
343
+ // API identifier file processing
344
+ { fileprop: 'asapiidentifierfile', prop: 'asapiidentifier' },
345
+ { fileprop: 'rest01apiidentifierfile', prop: 'rest01apiidentifier' },
346
+ { fileprop: 'toapiidentifierfile', prop: 'toapiidentifier' },
347
+ { fileprop: 'imapiidentifierfile', prop: 'imapiidentifier' },
348
+ // Client ID file processing
349
+ { fileprop: 'asclientidfile', prop: 'asclientid' },
350
+ { fileprop: 'rest01clientidfile', prop: 'rest01clientid' },
351
+ { fileprop: 'toclientidfile', prop: 'toclientid' },
352
+ { fileprop: 'imclientidfile', prop: 'imclientid' },
353
+ { fileprop: 'trclientidfile', prop: 'trclientid' },
354
+ // Client secret file processing
355
+ { fileprop: 'asclientsecretfile', prop: 'asclientsecret' },
356
+ { fileprop: 'rest01clientsecretfile', prop: 'rest01clientsecret' },
357
+ { fileprop: 'toclientsecretfile', prop: 'toclientsecret' },
358
+ { fileprop: 'imclientsecretfile', prop: 'imclientsecret' },
359
+ { fileprop: 'trclientsecretfile', prop: 'trclientsecret' },
360
+ ]
361
+
362
+ fileconfig.forEach((v) => {
363
+ if (defconfig[v.fileprop] !== undefined) {
364
+ defconfig[v.prop] = ReadFile(defconfig[v.fileprop]);
365
+ }
366
+ });
332
367
 
333
368
  // Preference order is YAML file then .env file
334
369
  const $options = {
@@ -0,0 +1 @@
1
+ testapiidentifierfilecontents
@@ -0,0 +1 @@
1
+ testclientidfilecontents
@@ -0,0 +1 @@
1
+ testclientsecretfilecontents
@@ -0,0 +1 @@
1
+ testfilepassword
package/stsconfig.test.js DELETED
@@ -1,85 +0,0 @@
1
-
2
- describe("Test", () =>
3
- {
4
- beforeAll(async () =>
5
- {
6
-
7
- });
8
-
9
- afterAll(async () =>
10
- {
11
-
12
- });
13
-
14
- test('Checking default config items', async () =>
15
- {
16
- expect.assertions(21);
17
-
18
- process.env.STSENVFILE = './.env-test-file-1'; // Empty environment file
19
- let goptions = require('./stsconfig.js').$options;
20
-
21
- expect(goptions.isProduction).toEqual(false);
22
- expect(goptions.consoleLogErrors).toEqual(false);
23
- expect(goptions.dbuser).toEqual('postgres');
24
- expect(goptions.dbpassword).toEqual('password');
25
- expect(goptions.dbpasswordfile).toEqual(undefined);
26
- expect(goptions.dbhost).toEqual('localhost');
27
- expect(goptions.dbport).toEqual('5432');
28
- expect(goptions.database).toEqual('stsrestmsdb01');
29
- expect(goptions.databaseUrl).toEqual(undefined);
30
- expect(goptions.databasescriptfolder).toEqual('/var/lib/sts/stsglobalresources/db-scripts');
31
-
32
- expect(goptions.poolSize).toEqual(500);
33
- expect(goptions.useCPUs).toEqual(-1);
34
- expect(goptions.respawnOnFail).toEqual(false);
35
- expect(goptions.defaultDatabaseEntries).toEqual(10000);
36
- expect(goptions.useRedis).toEqual(false);
37
- expect(goptions.endFlush).toEqual(false);
38
- expect(goptions.redisPort).toEqual('6379');
39
- expect(goptions.redisServer).toEqual('localhost');
40
- expect(goptions.k6ScriptPath).toEqual('.');
41
- expect(goptions.defaultDatabaseMinExtraDataSize).toEqual(0);
42
- expect(goptions.defaultDatabaseMaxExtraDataSize).toEqual(2000);
43
- });
44
-
45
- test('Checking default rest01 service config', async () =>
46
- {
47
- expect.assertions(11);
48
-
49
- process.env.STSENVFILE = './.env-test-file-1'; // Empty environment file
50
- let goptions = require('./stsconfig.js').$options;
51
-
52
- expect(goptions.rest01endpoint).toEqual('http://localhost');
53
- expect(goptions.rest01hostport).toEqual('3003');
54
- expect(goptions.rest01port).toEqual('3003');
55
- expect(goptions.rest01apiroot).toEqual('/stsrest01/v1');
56
- expect(goptions.rest01prometheussupport).toEqual(true);
57
- expect(goptions.rest01prometheusclusterport).toEqual('3013');
58
- expect(goptions.rest01servicename).toEqual('STSRest01');
59
- expect(goptions.rest01serviceversion).toEqual('1.0.0');
60
- expect(goptions.rest01email).toEqual('K6TestUser@sts');
61
- expect(goptions.rest01password).toEqual('K6TestUserPassword');
62
- expect(goptions.rest01passwordfile).toEqual(undefined);
63
- });
64
-
65
- test('Checking default instrument manager service config', async () =>
66
- {
67
- expect.assertions(11);
68
-
69
- process.env.STSENVFILE = './.env-test-file-1'; // Empty environment file
70
- let goptions = require('./stsconfig.js').$options;
71
-
72
- expect(goptions.imendpoint).toEqual('http://localhost');
73
- expect(goptions.imhostport).toEqual('3001');
74
- expect(goptions.import).toEqual('3001');
75
- expect(goptions.imapiroot).toEqual('/stsinstrumentmanager/v1');
76
- expect(goptions.imprometheussupport).toEqual(true);
77
- expect(goptions.imprometheusclusterport).toEqual('3011');
78
- expect(goptions.imservicename).toEqual('STSInstrumentManager');
79
- expect(goptions.imserviceversion).toEqual('1.0.0');
80
- expect(goptions.imemail).toEqual('K6TestUser@sts');
81
- expect(goptions.impassword).toEqual('K6TestUserPassword');
82
- expect(goptions.impasswordfile).toEqual(undefined);
83
- });
84
- });
85
-