@nsshunt/stsconfig 1.19.0 → 1.22.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/.env-default +17 -4
- package/.env-test-file-2 +15 -2
- package/.eslintrc.json +16 -9
- package/.github/workflows/npm-publish.yml +1 -0
- package/babel.config.json +6 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/jest/setEnvVars.js +4 -0
- package/dist/jest/setEnvVars.js.map +1 -0
- package/dist/jest.config.js +143 -0
- package/dist/jest.config.js.map +1 -0
- package/dist/stsconfig-01.test.js +195 -0
- package/dist/stsconfig-01.test.js.map +1 -0
- package/dist/stsconfig-02.test.js +195 -0
- package/dist/stsconfig-02.test.js.map +1 -0
- package/dist/stsconfig-default.test.js +195 -0
- package/dist/stsconfig-default.test.js.map +1 -0
- package/dist/stsconfig.js +587 -0
- package/dist/stsconfig.js.map +1 -0
- package/index.ts +821 -0
- package/jest/setEnvVars.js +4 -0
- package/jest.config.js +197 -0
- package/package.json +14 -7
- package/{stsconfig-01.test.js → stsconfig-01.test.ts} +37 -32
- package/stsconfig-02.test.js +36 -31
- package/stsconfig-default.test.js +36 -31
- package/{stsconfig.js → stsconfig.ts} +118 -56
- package/tsconfig.json +16 -0
- package/types/index.d.ts +604 -0
- package/types/index.d.ts.map +1 -0
- package/types/jest/setEnvVars.d.ts +1 -0
- package/types/jest/setEnvVars.d.ts.map +1 -0
- package/types/jest.config.d.ts +3 -0
- package/types/jest.config.d.ts.map +1 -0
- package/types/stsconfig-01.test.d.ts +2 -0
- package/types/stsconfig-01.test.d.ts.map +1 -0
- package/types/stsconfig-02.test.d.ts +2 -0
- package/types/stsconfig-02.test.d.ts.map +1 -0
- package/types/stsconfig-default.test.d.ts +2 -0
- package/types/stsconfig-default.test.d.ts.map +1 -0
- package/types/stsconfig.d.ts +4 -0
- package/types/stsconfig.d.ts.map +1 -0
- package/.babelrc +0 -1
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { accessSync, constants, readFileSync } from 'fs'
|
|
2
|
+
|
|
3
|
+
import Debug from "debug";
|
|
4
|
+
const debug = Debug(`proc:${process.pid}`);
|
|
5
|
+
|
|
6
|
+
import dotenv from 'dotenv'
|
|
7
|
+
import 'colors'
|
|
8
|
+
|
|
9
|
+
import { STSOptions } from './index'
|
|
10
|
+
|
|
11
|
+
let envOptions = null;
|
|
4
12
|
|
|
5
13
|
// Order for config settings
|
|
6
14
|
// -------------------------
|
|
@@ -8,12 +16,16 @@ require('colors');
|
|
|
8
16
|
// Use password specified within a database password file (if present)
|
|
9
17
|
// Fall back to use a password from an environment variable
|
|
10
18
|
|
|
11
|
-
|
|
12
|
-
let envfile = (process.env.STSENVFILE === undefined ? '/.env' : process.env.STSENVFILE);
|
|
19
|
+
function SetupConfig(): STSOptions {
|
|
13
20
|
|
|
14
|
-
require
|
|
21
|
+
// Add tthe STSENVFILE to script run commands in order to use the require .env file for configuration
|
|
22
|
+
const envfile = (process.env.STSENVFILE === undefined ? '/.env' : process.env.STSENVFILE);
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
//require('dotenv').config({ path: envfile });
|
|
25
|
+
|
|
26
|
+
dotenv.config({ path: envfile })
|
|
27
|
+
|
|
28
|
+
const defconfig: STSOptions =
|
|
17
29
|
{
|
|
18
30
|
// Node runtime environment
|
|
19
31
|
isProduction: (process.env.NODE_ENV === undefined ? false : (process.env.NODE_ENV === 'production' ? true : false))
|
|
@@ -24,7 +36,7 @@ const defconfig =
|
|
|
24
36
|
// Database username.
|
|
25
37
|
,dbuser: (process.env.DB_USER === undefined ? 'postgres' : process.env.DB_USER)
|
|
26
38
|
// Database password.
|
|
27
|
-
,dbpassword: (process.env.DB_PASSWORD === undefined ? '
|
|
39
|
+
,dbpassword: (process.env.DB_PASSWORD === undefined ? 'postgres' : process.env.DB_PASSWORD)
|
|
28
40
|
// Database password file
|
|
29
41
|
,dbpasswordfile: process.env.DB_PASSWORD_FILE
|
|
30
42
|
// Database host
|
|
@@ -210,11 +222,41 @@ const defconfig =
|
|
|
210
222
|
,asjwkskeycount: (process.env.AS_JWKS_KEY_COUNT === undefined ? 4 : parseInt(process.env.AS_JWKS_KEY_COUNT))
|
|
211
223
|
// Auth Server - JWKS Access token timeout.
|
|
212
224
|
,asaccesstokenexpire: (process.env.AS_ACCESS_TOKEN_EXPIRE === undefined ? 43200 : parseInt(process.env.AS_ACCESS_TOKEN_EXPIRE)) // 12 Hour default
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
|
|
225
|
+
|
|
226
|
+
// STS Broker Server
|
|
227
|
+
// ---------------
|
|
228
|
+
// The STS broker server is a BFF service used for STS SPAs. The service will use 1st party secured cookies for session management.
|
|
229
|
+
// The service also provides proxy API access to other STS and/or external services.
|
|
230
|
+
//
|
|
231
|
+
// STSBroker Server endpoint
|
|
232
|
+
,brokerendpoint: (process.env.BROKER_ENDPOINT === undefined ? "http://localhost" : process.env.BROKER_ENDPOINT)
|
|
233
|
+
// STSBroker Server port (listen port for the service)
|
|
234
|
+
,brokerhostport: (process.env.BROKER_HOST_PORT === undefined ? "3006" : process.env.BROKER_HOST_PORT)
|
|
235
|
+
// STSBroker Server port (client port to access the service)
|
|
236
|
+
,brokerport: (process.env.BROKER_PORT === undefined ? "3006" : process.env.BROKER_PORT)
|
|
237
|
+
// STSBroker Server endpoint
|
|
238
|
+
,brokerapiroot: (process.env.BROKER_APIROOT === undefined ? "/stsbroker/v1.0" : process.env.BROKER_APIROOT)
|
|
239
|
+
// STSBroker API Identifier. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
|
|
240
|
+
,brokerapiidentifier: process.env.BROKER_API_IDENTIFIER
|
|
241
|
+
// STSBroker API Identifier file. This value will be used as the audience parameter on authorization calls (OAuth2 client credentials flow).
|
|
242
|
+
,brokerapiidentifierfile: process.env.BROKER_API_IDENTIFIER_FILE
|
|
243
|
+
// STSBroker Prometheus metric support
|
|
244
|
+
,brokerprometheussupport: (process.env.BROKER_PROM_SUPPORT === undefined ? true : (process.env.BROKER_PROM_SUPPORT === "true" ? true : false))
|
|
245
|
+
// STSBroker Cluster Server port (port used for cluster prometheus scrapes). Service will listen on this port at mount point /metrics
|
|
246
|
+
,brokerprometheusclusterport: (process.env.BROKER_PROM_CLUSTER_PORT === undefined ? "3016" : process.env.BROKER_PROM_CLUSTER_PORT)
|
|
247
|
+
// STSBroker Service Name
|
|
248
|
+
,brokerservicename: (process.env.BROKER_SERVICE_NAME === undefined ? "STSBroker" : process.env.BROKER_SERVICE_NAME)
|
|
249
|
+
// STSBroker Service Version
|
|
250
|
+
,brokerserviceversion: (process.env.BROKER_SERVICE_VERSION === undefined ? "1.0.0" : process.env.BROKER_SERVICE_VERSION)
|
|
251
|
+
// STSBroker Server client ID. Used for oauth2 client credentials flow.
|
|
252
|
+
,brokerclientid: process.env.BROKER_CLIENT_ID
|
|
253
|
+
// STSBroker Server client ID file. Used for oauth2 client credentials flow.
|
|
254
|
+
,brokerclientidfile: process.env.BROKER_CLIENT_ID_FILE
|
|
255
|
+
// STSBroker Server client secret. Used for oauth2 client credentials flow.
|
|
256
|
+
,brokerclientsecret: process.env.BROKER_CLIENT_SECRET
|
|
257
|
+
// STSBroker Server client secret file. Used for oauth2 client credentials flow.
|
|
258
|
+
,brokerclientsecretfile: process.env.BROKER_CLIENT_SECRET_FILE
|
|
259
|
+
|
|
218
260
|
// STS Test Runner Prometheus metric support
|
|
219
261
|
,trprometheussupport: (process.env.TR_PROM_SUPPORT === undefined ? true : (process.env.TR_PROM_SUPPORT === "true" ? true : false ))
|
|
220
262
|
// STS Test Runner Cluster Server port (port used for cluster prometheus scrapes)
|
|
@@ -377,57 +419,77 @@ const defconfig =
|
|
|
377
419
|
,jwksAuthConfigTimeout: (process.env.JWKS_AUTH_CONFIG_TIMEOUT === undefined ? 30000 : parseInt(process.env.JWKS_AUTH_CONFIG_TIMEOUT))
|
|
378
420
|
}
|
|
379
421
|
|
|
380
|
-
const ReadFile = (passwordFile) => {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
422
|
+
const ReadFile = (passwordFile) => {
|
|
423
|
+
try {
|
|
424
|
+
accessSync(passwordFile, constants.R_OK);
|
|
425
|
+
const data = readFileSync(passwordFile, 'utf8');
|
|
426
|
+
debug(`Successfully loaded password file: [${passwordFile}]`.green);
|
|
427
|
+
return data;
|
|
428
|
+
} catch (err) {
|
|
429
|
+
debug(`Problem loading password file: [${passwordFile}], Error: [${err}]`.red);
|
|
430
|
+
return "";
|
|
431
|
+
}
|
|
389
432
|
}
|
|
433
|
+
|
|
434
|
+
// 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.
|
|
435
|
+
const fileconfig = [
|
|
436
|
+
{ fileprop: 'dbpasswordfile', prop: 'dbpassword' },
|
|
437
|
+
// API identifier file processing
|
|
438
|
+
{ fileprop: 'asapiidentifierfile', prop: 'asapiidentifier' },
|
|
439
|
+
{ fileprop: 'asoauthapiidentifierfile', prop: 'asoauthapiidentifier' },
|
|
440
|
+
{ fileprop: 'asadminapiidentifierfile', prop: 'asadminapiidentifier' },
|
|
441
|
+
{ fileprop: 'rest01apiidentifierfile', prop: 'rest01apiidentifier' },
|
|
442
|
+
{ fileprop: 'brokerapiidentifierfile', prop: 'brokerapiidentifier' },
|
|
443
|
+
{ fileprop: 'toapiidentifierfile', prop: 'toapiidentifier' },
|
|
444
|
+
{ fileprop: 'imapiidentifierfile', prop: 'imapiidentifier' },
|
|
445
|
+
// Client ID file processing
|
|
446
|
+
{ fileprop: 'asclientidfile', prop: 'asclientid' },
|
|
447
|
+
{ fileprop: 'rest01clientidfile', prop: 'rest01clientid' },
|
|
448
|
+
{ fileprop: 'brokerclientidfile', prop: 'brokerclientid' },
|
|
449
|
+
{ fileprop: 'toclientidfile', prop: 'toclientid' },
|
|
450
|
+
{ fileprop: 'imclientidfile', prop: 'imclientid' },
|
|
451
|
+
{ fileprop: 'trclientidfile', prop: 'trclientid' },
|
|
452
|
+
// Client secret file processing
|
|
453
|
+
{ fileprop: 'asclientsecretfile', prop: 'asclientsecret' },
|
|
454
|
+
{ fileprop: 'rest01clientsecretfile', prop: 'rest01clientsecret' },
|
|
455
|
+
{ fileprop: 'brokerclientsecretfile', prop: 'brokerclientsecret' },
|
|
456
|
+
{ fileprop: 'toclientsecretfile', prop: 'toclientsecret' },
|
|
457
|
+
{ fileprop: 'imclientsecretfile', prop: 'imclientsecret' },
|
|
458
|
+
{ fileprop: 'trclientsecretfile', prop: 'trclientsecret' },
|
|
459
|
+
// JWKS secret file processing
|
|
460
|
+
{ fileprop: 'tsjwksstorepathfile', prop: 'tsjwksstorepath' },
|
|
461
|
+
]
|
|
462
|
+
|
|
463
|
+
fileconfig.forEach((v) => {
|
|
464
|
+
if (defconfig[v.fileprop] !== undefined) {
|
|
465
|
+
defconfig[v.prop] = ReadFile(defconfig[v.fileprop]);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
return defconfig;
|
|
470
|
+
|
|
390
471
|
}
|
|
391
472
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
// Client ID file processing
|
|
403
|
-
{ fileprop: 'asclientidfile', prop: 'asclientid' },
|
|
404
|
-
{ fileprop: 'rest01clientidfile', prop: 'rest01clientid' },
|
|
405
|
-
{ fileprop: 'toclientidfile', prop: 'toclientid' },
|
|
406
|
-
{ fileprop: 'imclientidfile', prop: 'imclientid' },
|
|
407
|
-
{ fileprop: 'trclientidfile', prop: 'trclientid' },
|
|
408
|
-
// Client secret file processing
|
|
409
|
-
{ fileprop: 'asclientsecretfile', prop: 'asclientsecret' },
|
|
410
|
-
{ fileprop: 'rest01clientsecretfile', prop: 'rest01clientsecret' },
|
|
411
|
-
{ fileprop: 'toclientsecretfile', prop: 'toclientsecret' },
|
|
412
|
-
{ fileprop: 'imclientsecretfile', prop: 'imclientsecret' },
|
|
413
|
-
{ fileprop: 'trclientsecretfile', prop: 'trclientsecret' },
|
|
414
|
-
// JWKS secret file processing
|
|
415
|
-
{ fileprop: 'tsjwksstorepathfile', prop: 'tsjwksstorepath' },
|
|
416
|
-
]
|
|
417
|
-
|
|
418
|
-
fileconfig.forEach((v) => {
|
|
419
|
-
if (defconfig[v.fileprop] !== undefined) {
|
|
420
|
-
defconfig[v.prop] = ReadFile(defconfig[v.fileprop]);
|
|
473
|
+
export function $Options(): STSOptions {
|
|
474
|
+
if (envOptions === null) {
|
|
475
|
+
const defconfig = SetupConfig();
|
|
476
|
+
envOptions = {
|
|
477
|
+
...defconfig
|
|
478
|
+
// Computed connection string to be used in development mode.
|
|
479
|
+
,connectionString: `postgresql://${defconfig.dbuser}:${defconfig.dbpassword}@${defconfig.dbhost}:${defconfig.dbport}/${defconfig.database}`
|
|
480
|
+
// Default computed connection string for postgres. Database name = postgres. Used by utilites that create and/or update the STS database(s).
|
|
481
|
+
,defaultDatabaseConnectionString: `postgresql://${defconfig.dbuser}:${defconfig.dbpassword}@${defconfig.dbhost}:${defconfig.dbport}/postgres`
|
|
482
|
+
}
|
|
421
483
|
}
|
|
422
|
-
|
|
423
|
-
|
|
484
|
+
return envOptions;
|
|
485
|
+
}
|
|
486
|
+
/*
|
|
424
487
|
// Preference order is YAML file then .env file
|
|
425
|
-
const $options = {
|
|
488
|
+
export const $options = {
|
|
426
489
|
...defconfig
|
|
427
490
|
// Computed connection string to be used in development mode.
|
|
428
491
|
,connectionString: `postgresql://${defconfig.dbuser}:${defconfig.dbpassword}@${defconfig.dbhost}:${defconfig.dbport}/${defconfig.database}`
|
|
429
492
|
// Default computed connection string for postgres. Database name = postgres. Used by utilites that create and/or update the STS database(s).
|
|
430
493
|
,defaultDatabaseConnectionString: `postgresql://${defconfig.dbuser}:${defconfig.dbpassword}@${defconfig.dbhost}:${defconfig.dbport}/postgres`
|
|
431
494
|
}
|
|
432
|
-
|
|
433
|
-
module.exports = { $options }
|
|
495
|
+
*/
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"target": "es6",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"sourceMap": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationDir": "./types",
|
|
12
|
+
"declarationMap": true
|
|
13
|
+
},
|
|
14
|
+
"lib": ["es2015"]
|
|
15
|
+
}
|
|
16
|
+
|