@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.
Files changed (43) hide show
  1. package/.env-default +17 -4
  2. package/.env-test-file-2 +15 -2
  3. package/.eslintrc.json +16 -9
  4. package/.github/workflows/npm-publish.yml +1 -0
  5. package/babel.config.json +6 -0
  6. package/dist/index.js +18 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/jest/setEnvVars.js +4 -0
  9. package/dist/jest/setEnvVars.js.map +1 -0
  10. package/dist/jest.config.js +143 -0
  11. package/dist/jest.config.js.map +1 -0
  12. package/dist/stsconfig-01.test.js +195 -0
  13. package/dist/stsconfig-01.test.js.map +1 -0
  14. package/dist/stsconfig-02.test.js +195 -0
  15. package/dist/stsconfig-02.test.js.map +1 -0
  16. package/dist/stsconfig-default.test.js +195 -0
  17. package/dist/stsconfig-default.test.js.map +1 -0
  18. package/dist/stsconfig.js +587 -0
  19. package/dist/stsconfig.js.map +1 -0
  20. package/index.ts +821 -0
  21. package/jest/setEnvVars.js +4 -0
  22. package/jest.config.js +197 -0
  23. package/package.json +14 -7
  24. package/{stsconfig-01.test.js → stsconfig-01.test.ts} +37 -32
  25. package/stsconfig-02.test.js +36 -31
  26. package/stsconfig-default.test.js +36 -31
  27. package/{stsconfig.js → stsconfig.ts} +118 -56
  28. package/tsconfig.json +16 -0
  29. package/types/index.d.ts +604 -0
  30. package/types/index.d.ts.map +1 -0
  31. package/types/jest/setEnvVars.d.ts +1 -0
  32. package/types/jest/setEnvVars.d.ts.map +1 -0
  33. package/types/jest.config.d.ts +3 -0
  34. package/types/jest.config.d.ts.map +1 -0
  35. package/types/stsconfig-01.test.d.ts +2 -0
  36. package/types/stsconfig-01.test.d.ts.map +1 -0
  37. package/types/stsconfig-02.test.d.ts +2 -0
  38. package/types/stsconfig-02.test.d.ts.map +1 -0
  39. package/types/stsconfig-default.test.d.ts +2 -0
  40. package/types/stsconfig-default.test.d.ts.map +1 -0
  41. package/types/stsconfig.d.ts +4 -0
  42. package/types/stsconfig.d.ts.map +1 -0
  43. package/.babelrc +0 -1
@@ -1,6 +1,14 @@
1
- const { accessSync, constants, readFileSync } = require('fs');
2
- const debug = require('debug')(`proc:${process.pid}`);
3
- require('colors');
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
- // Add tthe STSENVFILE to script run commands in order to use the require .env file for configuration
12
- let envfile = (process.env.STSENVFILE === undefined ? '/.env' : process.env.STSENVFILE);
19
+ function SetupConfig(): STSOptions {
13
20
 
14
- require('dotenv').config({ path: envfile });
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
- const defconfig =
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 ? 'password' : process.env.DB_PASSWORD)
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
- // Auth Server - [DEPRECATED] Private Key (when using JWT)
214
- ,asprivatekeypath: (process.env.AS_PRIVATE_KEY_PATH === undefined ? "/var/lib/sts/stsglobalresources/keys/private.key" : process.env.AS_PRIVATE_KEY_PATH)
215
- // Auth Server - [DEPRECATED] Public Key (when using JWT)
216
- ,aspublickeypath: (process.env.AS_PUBLIC_KEY_PATH === undefined ? "/var/lib/sts/stsglobalresources/keys/public.key" : process.env.AS_PUBLIC_KEY_PATH)
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
- try {
382
- accessSync(passwordFile, constants.R_OK);
383
- const data = readFileSync(passwordFile, 'utf8');
384
- debug(`Successfully loaded password file: [${passwordFile}]`.green);
385
- return data;
386
- } catch (err) {
387
- debug(`Problem loading password file: [${passwordFile}], Error: [${err}]`.red);
388
- return "";
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
- // 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.
393
- const fileconfig = [
394
- { fileprop: 'dbpasswordfile', prop: 'dbpassword' },
395
- // API identifier file processing
396
- { fileprop: 'asapiidentifierfile', prop: 'asapiidentifier' },
397
- { fileprop: 'asoauthapiidentifierfile', prop: 'asoauthapiidentifier' },
398
- { fileprop: 'asadminapiidentifierfile', prop: 'asadminapiidentifier' },
399
- { fileprop: 'rest01apiidentifierfile', prop: 'rest01apiidentifier' },
400
- { fileprop: 'toapiidentifierfile', prop: 'toapiidentifier' },
401
- { fileprop: 'imapiidentifierfile', prop: 'imapiidentifier' },
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
+