@mimik/configuration 1.3.5 → 4.4.1
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/.eslintrc +20 -3
- package/.husky/pre-commit +4 -0
- package/.husky/pre-push +4 -0
- package/.nycrc +4 -0
- package/Gulpfile.js +7 -7
- package/README.md +78 -37
- package/index.js +274 -170
- package/lib/common.js +29 -18
- package/package.json +23 -16
package/.eslintrc
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
// Use this file as a starting point for your project's .eslintrc.
|
|
2
|
-
// Copy this file, and add rule overrides as needed.
|
|
3
1
|
{
|
|
2
|
+
"plugins": [
|
|
3
|
+
"@mimik/document-env",
|
|
4
|
+
"@mimik/dependencies"
|
|
5
|
+
],
|
|
4
6
|
"env": {
|
|
5
7
|
"node": true
|
|
6
8
|
},
|
|
9
|
+
"parserOptions": {
|
|
10
|
+
"ecmaVersion": 2020
|
|
11
|
+
},
|
|
7
12
|
"extends": "airbnb",
|
|
8
13
|
"rules": {
|
|
14
|
+
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
|
|
9
15
|
"brace-style": [1, "stroustrup", {"allowSingleLine": true}],
|
|
10
16
|
"no-confusing-arrow": [0], // arrow isnt confusing
|
|
11
17
|
"max-len": [1, 180, { "ignoreComments": true }],
|
|
12
18
|
"linebreak-style": 0,
|
|
13
19
|
"quotes": [1, "single"],
|
|
14
|
-
"semi": [1, "always"]
|
|
20
|
+
"semi": [1, "always"],
|
|
21
|
+
"no-process-env": ["error"],
|
|
22
|
+
"@mimik/document-env/validate-document-env": 2,
|
|
23
|
+
"@mimik/dependencies/case-sensitive": 2,
|
|
24
|
+
"@mimik/dependencies/no-cycles": 2,
|
|
25
|
+
"@mimik/dependencies/no-unresolved": 2,
|
|
26
|
+
"@mimik/dependencies/require-json-ext": 2
|
|
27
|
+
},
|
|
28
|
+
"settings":{
|
|
29
|
+
"react": {
|
|
30
|
+
"version": "latest"
|
|
31
|
+
}
|
|
15
32
|
},
|
|
16
33
|
"globals": {
|
|
17
34
|
"module": true,
|
package/.husky/pre-push
ADDED
package/.nycrc
ADDED
package/Gulpfile.js
CHANGED
|
@@ -9,25 +9,25 @@ const jsdoc2md = require('jsdoc-to-markdown');
|
|
|
9
9
|
const files = [
|
|
10
10
|
'index.js',
|
|
11
11
|
'Gulpfile.js',
|
|
12
|
-
'test
|
|
12
|
+
'test/**.js',
|
|
13
13
|
'lib/**.js',
|
|
14
14
|
];
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const createDocs = (done) => {
|
|
17
17
|
jsdoc2md.render({ files: 'index.js' })
|
|
18
18
|
.then((output) => fs.writeFileSync('README.md', output))
|
|
19
|
-
.catch((err) => log.error('docs creation failed:', err.message))
|
|
20
|
-
|
|
19
|
+
.catch((err) => log.error('docs creation failed:', err.message))
|
|
20
|
+
.finally(() => done());
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
const lint = () => gulp.src(files)
|
|
24
24
|
.pipe(eslint({}))
|
|
25
|
-
.pipe(eslint.format())
|
|
26
|
-
.pipe(eslint.failOnError());
|
|
25
|
+
.pipe(eslint.format());
|
|
27
26
|
|
|
28
27
|
const add = () => gulp.src('README.md')
|
|
29
28
|
.pipe(git.add({ quiet: true }));
|
|
30
29
|
|
|
30
|
+
const docs = gulp.series(createDocs, add);
|
|
31
|
+
|
|
31
32
|
gulp.task('docs', docs);
|
|
32
33
|
gulp.task('lint', lint);
|
|
33
|
-
gulp.task('add', add);
|
package/README.md
CHANGED
|
@@ -5,6 +5,25 @@
|
|
|
5
5
|
```js
|
|
6
6
|
const config = require('@mimik/configuration');
|
|
7
7
|
```
|
|
8
|
+
|
|
9
|
+
* [configuration](#module_configuration)
|
|
10
|
+
* [~isProd()](#module_configuration..isProd) ⇒ <code>boolean</code>
|
|
11
|
+
* [~setConfig(pack, options)](#module_configuration..setConfig) ⇒ <code>object</code>
|
|
12
|
+
|
|
13
|
+
<a name="module_configuration..isProd"></a>
|
|
14
|
+
|
|
15
|
+
### configuration~isProd() ⇒ <code>boolean</code>
|
|
16
|
+
Indicates if the environment is prod
|
|
17
|
+
|
|
18
|
+
**Kind**: inner method of [<code>configuration</code>](#module_configuration)
|
|
19
|
+
**Returns**: <code>boolean</code> - `true` if the environment is `prod` or `production`.
|
|
20
|
+
|
|
21
|
+
The following environment variables are used
|
|
22
|
+
|
|
23
|
+
| Env variable name | Description | Value | Comments |
|
|
24
|
+
| ----------------- | ----------- | ----- | -------- |
|
|
25
|
+
| NODE_ENV | environnment of the microservice |
|
|
26
|
+
**Category**: sync
|
|
8
27
|
<a name="module_configuration..setConfig"></a>
|
|
9
28
|
|
|
10
29
|
### configuration~setConfig(pack, options) ⇒ <code>object</code>
|
|
@@ -15,19 +34,22 @@ Set the configuration of the micro-service.
|
|
|
15
34
|
**Category**: sync
|
|
16
35
|
**Throws**:
|
|
17
36
|
|
|
18
|
-
- Will trow an error if a mandatory value is missing.
|
|
37
|
+
- <code>configuration.serverSettings.type</code> Will trow an error if a mandatory value is missing.
|
|
19
38
|
|
|
20
39
|
The following environment variables are being setup:
|
|
21
40
|
|
|
22
41
|
| Env variable name | Description | Value | Comments |
|
|
23
42
|
| ----------------- | ----------- | ----- | -------- |
|
|
24
|
-
| SERVER_VERSION | version of the software for the micro-service| package.version |
|
|
25
|
-
| SERVER_NAME | name of the micro-service | package.
|
|
26
|
-
| SERVER_TYPE | type of the micro-service | package.type |
|
|
27
|
-
| SWAGGER_FILE_VERSION | version of the swagger file for the API | package.swaggerFile.version |
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
43
|
+
| SERVER_VERSION | version of the software for the micro-service | package.version | serverSettings.version
|
|
44
|
+
| SERVER_NAME | name of the micro-service | package.name | serverSettings.name
|
|
45
|
+
| SERVER_TYPE | type of the micro-service | package.mimik.type | serverSettings.type
|
|
46
|
+
| SWAGGER_FILE_VERSION | version of the swagger file for the API | package.swaggerFile.version | serverSettings.swaggerFileVersion
|
|
47
|
+
| SWAGGER_FILE_ACCOUNT | account associated with the API | package.swaggerFile.account |
|
|
48
|
+
| SWAGGER_FILE_NAME | name of the API | package.swaggerFile.name |
|
|
49
|
+
| SERVER_LOCAL_IPV4 | IP address of the micro-service | ip.address() | serverSettings.ip.local
|
|
50
|
+
| CONSOLE_LEVEL | log level for console output | debug | logInfo.consoleLevel
|
|
51
|
+
| LOG_LEVEL | log level for console output | debug | logInfo.logLevel
|
|
52
|
+
| AWS_LOCAL_PROPERTIES | internal ip address to access aws insrance properties | 169.254.169.254
|
|
31
53
|
|
|
32
54
|
The following environement variables are being used for the configuration:
|
|
33
55
|
|
|
@@ -37,46 +59,42 @@ The following environement variables are being used for the configuration:
|
|
|
37
59
|
| LOCATION_PROVIDER | location provider URL to use for ip location or `noPublic` or `environment` | noPublic | locationProvider.url or locationProvider | `see public-helper`
|
|
38
60
|
| LOCATION_PROVIDER_KEY | location provider key to use to access the location provider | null | locationProvider.key | see `public-helper`
|
|
39
61
|
| CLOUD_PROVIDER | cloud provider running the service | noCloud | cloudProvider | see `public-helper`
|
|
40
|
-
| AWS_ACCESS_KEY_ID | aws access key id for the account | ----noAccessKeyId---- | aws.accessKeyId |
|
|
41
|
-
| AWS_SECRET_ACCESS_KEY | secret for the aws access key id for the account | ----noAccessKey---- | aws.secretAccessKey |
|
|
42
|
-
| AWS_REGION | aws region for the account | ----noRegion---- | aws.region |
|
|
43
62
|
| SERVER_ID | service id | uuid.v4() | serverSettings.id |
|
|
63
|
+
| CUSTOMER_CODE | customer code associated with the service instance | '' | serverSettings.customerCode | empty string
|
|
44
64
|
| SWAGGER_FILE_DIRECTORY | directory where the api definition is located | ./api | serverSettings.api | [1]
|
|
65
|
+
| SWAGGER_API_KEY | key on swagger hub for provate api access | | serverSettings.apiKey
|
|
45
66
|
| SERVER_SECURITY_SET | switch to enable or disable the token interpretation | on | serverSettings.securitySet | only active if environment is `local`
|
|
46
67
|
| INTERCEPT_ERROR | switch to use or not the errorIntercept option | on | serverSettings.interceptError | must be set to off for mID
|
|
47
68
|
| SERVER_PORT | port of the server | | serverSettings.port |
|
|
48
|
-
| SERVER_NAME | name of the micro-service | | serverSettings.[]()name | see setup environment variable
|
|
49
|
-
| SERVER_TYPE | type of the micro-service | | serverSettings.type | see setup environment variable
|
|
50
|
-
| SERVER_VERSION | version of the software for the micro-service | | serverSettings.version | see setup environment variable
|
|
51
|
-
| SWAGGER_FILE_VERSION | version of the swagger file for the API | | serverSettings.swaggerFileVersion | see setup environment variable
|
|
52
|
-
| SERVER_LOCAL_IPV4 | ip address of the server | | serverSettings.ip.local | see setup environment variable
|
|
53
69
|
| SERVER_PUBLIC_PROTOCOL | protocol used to defined the domain address of the sevice | http: | serverSettings.public.protocol |
|
|
54
70
|
| SERVER_PUBLIC_DOMAIN_NAME | domain name used to define the domain address of the service | null | serverSettings.public.domainName |
|
|
55
71
|
| ADMIN_EXTERNAL_ID | external id of the admin role to be chacked in the token | admin | security.admin.externalId |
|
|
56
|
-
| OAUTH_CLIENT_ID | security id of the service | | security.server.
|
|
72
|
+
| OAUTH_CLIENT_ID | security id of the service | | security.server.id | [2]
|
|
57
73
|
| OAUTH_CLIENT_SECRET | secret of the service | | security.server.secret | [2]
|
|
58
74
|
| OAUTH_CLIENT_ACCESS_KEY | key for token signature | | security.server.accessKey | [2]
|
|
59
75
|
| OAUTH_CLIENT_AUDIENCE | url representing the server to mST | | security.server.audience | [2]
|
|
60
76
|
| OAUTH_ISSUER | token url of mST | | security.server.issuer | [2]
|
|
61
77
|
| OAUTH_GENERIC_KEY | key for token signature provided when a generic for this service type is defined | noGeneric | security.generic.key | [2]
|
|
78
|
+
| OAUTH_GENERIC_PREVIOUS_KEY | key for the token signature before change the public key | | security.generic.previousKey | [2]
|
|
62
79
|
| OAUTH_GENERIC_AUDIENCE | url representing the generic of the service type to mST | noGeneric | security.generic.audience | [2]
|
|
63
|
-
|
|
|
64
|
-
| LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all
|
|
65
|
-
|
|
|
80
|
+
| API_KEYS | list of API Keys which a test against in case of APIKey security | [] |
|
|
81
|
+
| LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, 'awsKinesis'
|
|
82
|
+
| NO_STACK | disable the inclusion of a the stack in all logs | yes | logInfo.noStack
|
|
66
83
|
| FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
|
|
67
84
|
| EXIT_DELAY | delay to allow the log transports to flush | 2000 | logInfo.exitDelay | in milliseconds
|
|
68
85
|
| CLUSTER_MANAGEMENT | switch to enable cluster communication | off | cluster.management | can be `on` or `off`
|
|
69
86
|
| REQUEST_TIMEOUT | timeout for intra cluster http request | 10000 | cluster.timeout | in milliseconds
|
|
70
87
|
| CACHE_SET | switch to enable use of cache | off | cache.set | can be `on`, `off`
|
|
71
88
|
| TOPIC_SET | switch to enable use of event topic | off | topic.set | can be `on`, `off`, `mock`
|
|
89
|
+
| ENCRYPTION_SET | switch to enable use of mongodb encryption | off | encryption.set | can be `on`, or `off`
|
|
72
90
|
| MIT_URL | url for reaching mIT | | dependencies.mIT.url |
|
|
73
91
|
| MIT_AUDIENCE | audience of mIT | | dependencies.mIT.audience | [2]
|
|
74
92
|
| REGISTRATION_SET | swicht to enable user of registration | on | registration.set | can be `on` or `off`
|
|
75
93
|
| REGISTRATION_RETRY | retry time for registering to mIT | 3000 | registration.retry | in milliseconds
|
|
76
|
-
|
|
|
77
|
-
|
|
|
94
|
+
| `$_URL`.toUpperCase() | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
|
|
95
|
+
| `${configuration.serverSettings.type}_AUDIENCE`.toUpperCase() | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
|
|
78
96
|
|
|
79
|
-
[1]: `/(
|
|
97
|
+
[1]: `/(SWAGGER_FILE_ACCOUNT)_(SERVER_TYPE)_(SWAGGER_FILE_VERSION)_swagger.json` is added to the `serverSettings.api` property
|
|
80
98
|
|
|
81
99
|
[2]: defined when registering to mST
|
|
82
100
|
|
|
@@ -103,8 +121,8 @@ When `on` is used for `TOPIC_SET` the following environment variables are used f
|
|
|
103
121
|
|
|
104
122
|
| Env variable name | Description | Default | Comments |
|
|
105
123
|
| ----------------- | ----------- | ------- | -------- |
|
|
106
|
-
| SNS_AWS_ACCESS_KEY_ID | access key id for AWS SNS |
|
|
107
|
-
| SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS |
|
|
124
|
+
| SNS_AWS_ACCESS_KEY_ID | access key id for AWS SNS | |
|
|
125
|
+
| SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS | |
|
|
108
126
|
| SNS_AWS_REGION | region where the topic is | ----noRegion---- |
|
|
109
127
|
|
|
110
128
|
When `mongodb` is used the following environment variables are used for the configuration:
|
|
@@ -116,32 +134,55 @@ When `mongodb` is used the following environment variables are used for the conf
|
|
|
116
134
|
| DATABASE_USER | user to access the database | null | if missing no user/password will be used
|
|
117
135
|
| DATABASE_PASSWORD | password to access the database | null | if missing no user/password will be used
|
|
118
136
|
| DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
|
|
137
|
+
| DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
|
|
138
|
+
| MONGO_USE_SRV | to use srv connection url set to `yes` | `no` |
|
|
139
|
+
| MONGO_AUTH_DATABASE | the auth database where users exists | |
|
|
119
140
|
| MONGO_MAX_POOL_SIZE | the minimum number of connections in the connection pool | 5 |
|
|
120
141
|
| MONGO_MIN_POOL_SIZE | the maximum number of connections in the connection pool | 10 |
|
|
121
142
|
| MONGO_MAX_IDLE_TIME | the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed | 3000 | in milliseconds
|
|
122
|
-
|
|
|
123
|
-
|
|
|
143
|
+
| MONGO_RETRY_WRITES | defines if the transaction should be tried again to write set to true or false | |
|
|
144
|
+
| MONGO_WRITE_CONCERN | accepts a number or `majority` | |
|
|
145
|
+
| MONGO_SSL | uses ssl connection if `yes` | `no` |
|
|
146
|
+
| MONGO_SSL_VALIDATE | validates mongod server certificate against ca if set to `yes` | `yes` | `yes` if MONGO_SSL is also `yes`
|
|
147
|
+
| MONGO_SSL_ALLOW_INVALID_HOSTNAMES | set to yes to allows invalid hostnames | |
|
|
124
148
|
| MONGO_REPLICAT_SET | specifies the name of the replica set, if the mongod is a member of a replica set | | not mandatory
|
|
125
149
|
| MONGO_WAIT_QUEUE_MULTIPLE | a number that the driver multiples the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the pool | | no mandatory
|
|
126
150
|
| MONGO_WAIT_QUEUE_TIMEOUT | the maximum time in milliseconds that a thread can wait for a connection to become available | | not mandatory
|
|
127
|
-
|
|
|
128
|
-
|
|
|
129
|
-
|
|
|
130
|
-
|
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
134
|
-
|
|
151
|
+
| MONGO_KEEP_ALIVE | pall th kep the connection with the database alive | true |
|
|
152
|
+
| MONGO_KEEP_ALIVE_INITIAL_DELAY | is the number of milliseconds to wait before initiating keepAlive on the socket | 300000 | in milliseconds
|
|
153
|
+
| MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | 20000 | in milliseconds
|
|
154
|
+
| MONGO_FAMILY | IP address family | 4 | 4 -> IPV4, 6 -> IPV6
|
|
155
|
+
| MONGO_SERVER_SELECTION_TIMEOUT | the MongoDB driver will try to find a server to send any given operation to, and keep retrying for serverSelectionTimeoutMS milliseconds | 30000 | in milliseconds
|
|
156
|
+
| MONGO_HEARTBEAT_FREQUENCY | the MongoDB driver sends a heartbeat every heartbeatFrequencyMS to check on the status of the connection | 10000 | in milliseconds
|
|
157
|
+
|
|
158
|
+
When `on` is used for `ENCRYPTION_SET` the following environment variables are used for the configuration:
|
|
159
|
+
|
|
160
|
+
| Env variable name | Description | Default | Comments |
|
|
161
|
+
| ----------------- | ----------- | ------- | -------- |
|
|
162
|
+
| ENCRYPTION_DATABASE | database name where data encryption keyvault exists | admin |
|
|
163
|
+
| KEY_VAULT_TABLE | collection name which has data encryption keys | keystore |
|
|
164
|
+
| KMS_PROVIDER | Key Management service provider for master key | local |
|
|
165
|
+
| MASTER_KEY_AWS_REGION | if KMS is aws region where master key exists | ----noRegion---- |
|
|
166
|
+
| MASTER_KEY_ARN | if KMS is aws ARN of master key | |
|
|
167
|
+
| ENCRYPTION_ACCESS_KEY_ID | if KMS is aws, accessKeyId to connect KMS | |
|
|
168
|
+
| ENCRYPTION_SECRET_ACCESS_KEY | if KMS is aws, secretAccessKey to connect KMS | |
|
|
169
|
+
| LOCAL_MASTER_KEY | if KMS is local, masterkey to encrypt data keys | |
|
|
170
|
+
|
|
135
171
|
When `dynamodb` is used the following environement variables are used for the configuration:
|
|
136
172
|
|
|
137
173
|
| Env variable name | Description | Default | Comments |
|
|
138
174
|
| ----------------- | ----------- | ------- | -------- |
|
|
139
|
-
| DYNAMODB_AWS_ACCESS_KEY_ID | access key id for AWS dynamodb |
|
|
140
|
-
| DYNAMODB_AWS_SECRET_ACCESS_KEY | secret access key for AWS dynamodb |
|
|
175
|
+
| DYNAMODB_AWS_ACCESS_KEY_ID | access key id for AWS dynamodb | |
|
|
176
|
+
| DYNAMODB_AWS_SECRET_ACCESS_KEY | secret access key for AWS dynamodb | |
|
|
141
177
|
| DYNAMODB_AWS_REGION | region where dynamodb is | ----noRegion---- |
|
|
142
178
|
| DYNAMODB_LOCAL_URL | url access the locally deploy dynamodb | http://localhost:8000 |
|
|
143
179
|
| DYNAMO_THROUGHPUT_READ | throughput read for dynamodb index | 1 |
|
|
144
180
|
| DYNAMO_THROUGHPUT_WRITE | throughput write for dynamodb index | 1 |
|
|
181
|
+
| DYNAMO_SCHEMA_THROUGHPUT_READ | throughput read for dynamodb schema | 1 |
|
|
182
|
+
| DYNAMO_SCHEMA_THROUGHPUT_WRITE | throughput write for dynamodb schema | 1 |
|
|
183
|
+
| DYNAMO_SCHEMA_THROUGHPUT | throughput for dynamodb schema |
|
|
184
|
+
|
|
185
|
+
`DYNAMO_SCHEMA_THROUGHPUT` takes precedence over `DYNAMO_SCHEMA_THROUGHPUT_READ` and `DYNAMO_SCHEMA_THROUGHPUT_WRITE`. If DYNAMO_SCHEMA_THROUGHPUT is set to `ON_DEMAND` then index throughput wont apply, and if DYNAMO_SCHEMA_THROUGHPUT is not set to a number the value will be 1.
|
|
145
186
|
|
|
146
187
|
When `redis` is used the following environement variables are used for the configuration:
|
|
147
188
|
|
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/* eslint no-process-env: "off" */
|
|
1
2
|
const _ = require('lodash');
|
|
2
3
|
const ip = require('ip');
|
|
3
4
|
const uuid = require('uuid');
|
|
4
5
|
const querystring = require('querystring');
|
|
5
6
|
|
|
6
7
|
const logger = require('@mimik/sumologic-winston-logger');
|
|
8
|
+
const { getCorrelationId } = require('@mimik/request-helper');
|
|
7
9
|
/**
|
|
8
10
|
* @module configuration
|
|
9
11
|
* @example
|
|
@@ -20,11 +22,15 @@ const {
|
|
|
20
22
|
ENV_VARIABLE,
|
|
21
23
|
REDIS_BASE_URL,
|
|
22
24
|
MONGO_BASE_URL,
|
|
25
|
+
MONGO_BASE_URL_SRV,
|
|
23
26
|
SWAGGER_EXT,
|
|
24
27
|
SWAGGER_SEP,
|
|
28
|
+
CUSTOMER_CODE_SEP,
|
|
25
29
|
DEFAULT_ENV,
|
|
30
|
+
PRODUCTIONS,
|
|
26
31
|
DEFAULT_LOCATION_PROVIDER,
|
|
27
32
|
DEFAULT_CLOUD_PROVIDER,
|
|
33
|
+
DEFAULT_CUSTOMER_CODE,
|
|
28
34
|
DEFAULT_CACHE_IP,
|
|
29
35
|
DEFAULT_CACHE_PASSWORD,
|
|
30
36
|
DEFAULT_CACHE_CONNECTION_TIMEOUT,
|
|
@@ -37,27 +43,28 @@ const {
|
|
|
37
43
|
DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
|
|
38
44
|
DEFAULT_REDIS_SOCKET_KEEPALIVE,
|
|
39
45
|
DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
|
|
40
|
-
DEFAULT_AWS_ACCESS_KEY_ID,
|
|
41
|
-
DEFAULT_AWS_SECRET_ACCESS_KEY,
|
|
42
46
|
DEFAULT_AWS_REGION,
|
|
47
|
+
DEFAULT_AWS_LOCAL_PROPERTIES,
|
|
43
48
|
DEFAULT_DYNAMODB_LOCAL_URL,
|
|
44
49
|
DEFAULT_DYNAMO_THROUGHPUT_READ,
|
|
45
50
|
DEFAULT_DYNAMO_THROUGHPUT_WRITE,
|
|
51
|
+
DEFAULT_DYNAMO_THROUGHPUT,
|
|
46
52
|
DEFAULT_MONGO_MAX_POOL_SIZE,
|
|
47
53
|
DEFAULT_MONGO_MIN_POOL_SIZE,
|
|
48
54
|
DEFAULT_MONGO_MAX_IDLE_TIME,
|
|
49
|
-
DEFAULT_MONGO_AUTO_RECONNECT,
|
|
50
|
-
DEFAULT_MONGO_RECONNECT_TRIES,
|
|
51
|
-
DEFAULT_MONGO_RECONNECT_INTERVAL,
|
|
52
55
|
DEFAULT_MONGO_KEEP_ALIVE,
|
|
53
|
-
|
|
54
|
-
DEFAULT_MONGO_BUFFER_COMMANDS,
|
|
55
|
-
DEFAULT_MONGO_CONNECT_TIMEOUT,
|
|
56
|
+
DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY,
|
|
56
57
|
DEFAULT_MONGO_SOCKET_TIMEOUT,
|
|
58
|
+
DEFAULT_MONGO_FAMILY,
|
|
59
|
+
DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
|
|
60
|
+
DEFAULT_MONGO_HEARTBEAT_FREQUENCY,
|
|
57
61
|
DEFAULT_DATABASE_IP,
|
|
58
62
|
DEFAULT_DATABASE_USER,
|
|
59
63
|
DEFAULT_DATABASE_PASSWORD,
|
|
60
64
|
DEFAULT_DATABASE_CONNECTION_TIMEOUT,
|
|
65
|
+
DEFAULT_DATABASE_RECONNECTION_OFFSET,
|
|
66
|
+
DEFAULT_ENCRYPTION_SET,
|
|
67
|
+
DEFAULT_KMS_PROVIDER,
|
|
61
68
|
DEFAULT_LOG_LEVEL,
|
|
62
69
|
DEFAULT_FILTER_FILE,
|
|
63
70
|
DEFAULT_EXIT_DELAY,
|
|
@@ -79,7 +86,7 @@ const {
|
|
|
79
86
|
DEFAULT_INTERCEPT_ERROR,
|
|
80
87
|
} = require('./lib/common');
|
|
81
88
|
|
|
82
|
-
const
|
|
89
|
+
const correlationIdStart = getCorrelationId('config-start');
|
|
83
90
|
let display = true;
|
|
84
91
|
const locParams = [NO_PUBLIC_PROVIDER, ENV_VARIABLE];
|
|
85
92
|
|
|
@@ -107,8 +114,8 @@ const setupRedis = () => {
|
|
|
107
114
|
}
|
|
108
115
|
if (opts.error && opts.error.code === 'ECONNREFUSED') {
|
|
109
116
|
if (display) {
|
|
110
|
-
logger.error('Fatal error: Could not connect to cache', { type: 'redis', error: opts.error.code },
|
|
111
|
-
logger.flushAndExit(
|
|
117
|
+
logger.error('Fatal error: Could not connect to cache', { type: 'redis', error: opts.error.code }, `redis-cache-start@0/${new Date().toISOString()}`);
|
|
118
|
+
logger.flushAndExit(1);
|
|
112
119
|
}
|
|
113
120
|
display = false;
|
|
114
121
|
}
|
|
@@ -131,17 +138,31 @@ const setupRedis = () => {
|
|
|
131
138
|
|
|
132
139
|
const setupDynamo = (dbOpts) => {
|
|
133
140
|
const dbConfig = {
|
|
134
|
-
accessKeyId: process.env.DYNAMODB_AWS_ACCESS_KEY_ID || DEFAULT_AWS_ACCESS_KEY_ID,
|
|
135
|
-
secretAccessKey: process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY || DEFAULT_AWS_SECRET_ACCESS_KEY,
|
|
136
141
|
region: process.env.DYNAMODB_AWS_REGION || DEFAULT_AWS_REGION,
|
|
137
142
|
url: process.env.DYNAMODB_LOCAL_URL || DEFAULT_DYNAMODB_LOCAL_URL,
|
|
138
143
|
throughput: {
|
|
139
144
|
read: parseInt(process.env.DYNAMO_THROUGHPUT_READ, 10) || DEFAULT_DYNAMO_THROUGHPUT_READ,
|
|
140
145
|
write: parseInt(process.env.DYNAMO_THROUGHPUT_WRITE, 10) || DEFAULT_DYNAMO_THROUGHPUT_WRITE,
|
|
141
146
|
},
|
|
147
|
+
schemaThroughput: {
|
|
148
|
+
read: parseInt(process.env.DYNAMO_SCHEMA_THROUGHPUT_READ, 10) || DEFAULT_DYNAMO_THROUGHPUT_READ,
|
|
149
|
+
write: parseInt(process.env.DYNAMO_SCHEMA_THROUGHPUT_WRITE, 10) || DEFAULT_DYNAMO_THROUGHPUT_WRITE,
|
|
150
|
+
},
|
|
142
151
|
tableName: dbOpts.table,
|
|
143
152
|
};
|
|
153
|
+
if (!_.isNil(process.env.DYNAMODB_AWS_ACCESS_KEY_ID)) dbConfig.accessKeyId = process.env.DYNAMODB_AWS_ACCESS_KEY_ID;
|
|
154
|
+
if (!_.isNil(process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY)) dbConfig.secretAccessKey = process.env.DYNAMODB_AWS_SECRET_ACCESS_KEY;
|
|
155
|
+
|
|
156
|
+
if (process.env.DYNAMO_SCHEMA_THROUGHPUT === 'ON_DEMAND') {
|
|
157
|
+
dbConfig.schemaThroughput = process.env.DYNAMO_SCHEMA_THROUGHPUT;
|
|
158
|
+
delete dbConfig.throughput;
|
|
159
|
+
}
|
|
160
|
+
else if (!_.isNil(process.env.DYNAMO_SCHEMA_THROUGHPUT)) {
|
|
161
|
+
const throughput = parseInt(process.env.DYNAMO_SCHEMA_THROUGHPUT, 10);
|
|
144
162
|
|
|
163
|
+
if (_.isNil(throughput) || _.isNaN(throughput)) dbConfig.schemaThroughput = DEFAULT_DYNAMO_THROUGHPUT;
|
|
164
|
+
else dbConfig.schemaThroughput = throughput;
|
|
165
|
+
}
|
|
145
166
|
return dbConfig;
|
|
146
167
|
};
|
|
147
168
|
|
|
@@ -156,8 +177,12 @@ const setupMongo = (dbOpts) => {
|
|
|
156
177
|
// string variables without default
|
|
157
178
|
if (process.env.MONGO_SSL === 'yes') stringOptions.ssl = true; // default value of mongo driver is false
|
|
158
179
|
if (process.env.MONGO_SSL_VALIDATE === 'no') stringOptions.sslValidate = false; // default value of mongo driver is true, if ssl is true
|
|
180
|
+
if (process.env.MONGO_SSL_ALLOW_INVALID_HOSTNAMES === 'yes') stringOptions.allowInvalidHostnames = true;
|
|
159
181
|
// if (process.env.MONGO_SSL_CA) stringOptions.sslCA = process.env.MONGO_SSL_CA; // commented out for now as we're not using a pem file at the moment
|
|
160
182
|
if (process.env.MONGO_REPLICAT_SET) stringOptions.replicaSet = process.env.MONGO_REPLICAT_SET;
|
|
183
|
+
if (process.env.MONGO_AUTH_DATABASE) stringOptions.authSource = process.env.MONGO_AUTH_DATABASE;
|
|
184
|
+
if (process.env.MONGO_WRITE_CONCERN) stringOptions.w = process.env.MONGO_WRITE_CONCERN;
|
|
185
|
+
if (process.env.MONGO_RETRY_WRITES) stringOptions.retryWrites = process.env.MONGO_RETRY_WRITES;
|
|
161
186
|
if (process.env.MONGO_WAIT_QUEUE_MULTIPLE) stringOptions.waitQueueMultiple = parseInt(process.env.MONGO_WAIT_QUEUE_MULTIPLE, 10);
|
|
162
187
|
if (process.env.MONGO_WAIT_QUEUE_TIMEOUT) stringOptions.waitQueueTimeoutMS = parseInt(process.env.MONGO_WAIT_QUEUE_TIMEOUT, 10); // in ms
|
|
163
188
|
return stringOptions ? querystring.stringify(stringOptions) : null;
|
|
@@ -170,7 +195,7 @@ const setupMongo = (dbOpts) => {
|
|
|
170
195
|
const user = process.env.DATABASE_USER || DEFAULT_DATABASE_USER;
|
|
171
196
|
const password = process.env.DATABASE_PASSWORD || DEFAULT_DATABASE_PASSWORD;
|
|
172
197
|
const qs = processStringOptions();
|
|
173
|
-
let url = MONGO_BASE_URL;
|
|
198
|
+
let url = (process.env.MONGO_USE_SRV === 'yes') ? MONGO_BASE_URL_SRV : MONGO_BASE_URL;
|
|
174
199
|
|
|
175
200
|
if (user && password) url = `${url}${user}:${password}@`;
|
|
176
201
|
url = `${url}${domain}/${database}`;
|
|
@@ -181,21 +206,21 @@ const setupMongo = (dbOpts) => {
|
|
|
181
206
|
user,
|
|
182
207
|
password,
|
|
183
208
|
connectTimeout: parseInt(process.env.DATABASE_CONNECTION_TIMEOUT, 10) || DEFAULT_DATABASE_CONNECTION_TIMEOUT,
|
|
209
|
+
reconnectOffset: parseInt(process.env.DATABASE_RECONNECTION_OFFSET, 10) || DEFAULT_DATABASE_RECONNECTION_OFFSET,
|
|
184
210
|
replicat: !!process.env.MONGO_REPLICAT_SET,
|
|
185
211
|
stringOptions: qs,
|
|
186
212
|
table: dbOpts.table,
|
|
187
213
|
url,
|
|
188
214
|
options: {
|
|
189
215
|
useNewUrlParser: true,
|
|
216
|
+
useUnifiedTopology: true,
|
|
190
217
|
useCreateIndex: true,
|
|
191
|
-
|
|
192
|
-
reconnectTries: parseInt(process.env.MONGO_RECONNECT_TRIES, 10) || DEFAULT_MONGO_RECONNECT_TRIES,
|
|
193
|
-
reconnectInterval: parseInt(process.env.MONGO_RECONNECT_INTERVAL, 10) || DEFAULT_MONGO_RECONNECT_INTERVAL,
|
|
218
|
+
family: parseInt(process.env.MONGO_FAMILY, 10) || DEFAULT_MONGO_FAMILY,
|
|
194
219
|
keepAlive: process.env.MONGO_KEEP_ALIVE || DEFAULT_MONGO_KEEP_ALIVE,
|
|
195
|
-
|
|
196
|
-
bufferCommands: process.env.MONGO_BUFFER_COMMANDS || DEFAULT_MONGO_BUFFER_COMMANDS,
|
|
197
|
-
connectTimeoutMS: parseInt(process.env.MONGO_CONNECT_TIMEOUT, 10) || DEFAULT_MONGO_CONNECT_TIMEOUT,
|
|
220
|
+
keepAliveInitialDelay: parseInt(process.env.MONGO_KEEP_ALIVE_INITIAL_DELAY, 10) || DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY,
|
|
198
221
|
socketTimeoutMS: parseInt(process.env.MONGO_SOCKET_TIMEOUT, 10) || DEFAULT_MONGO_SOCKET_TIMEOUT,
|
|
222
|
+
serverSelectionTimeoutMS: parseInt(process.env.MONGO_SERVER_SELECTION_TIMEOUT, 10) || DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
|
|
223
|
+
heartbeatFrequencyMS: parseInt(process.env.MONGO_HEARTBEAT_FREQUENCY, 10) || DEFAULT_MONGO_HEARTBEAT_FREQUENCY,
|
|
199
224
|
},
|
|
200
225
|
};
|
|
201
226
|
};
|
|
@@ -231,29 +256,53 @@ const setupLog = () => {
|
|
|
231
256
|
}
|
|
232
257
|
if (logInfo.mode === AWS_S3 || logInfo.mode === ALL) {
|
|
233
258
|
logInfo[AWS_S3] = {
|
|
234
|
-
accessKeyId: process.env.S3_AWS_ACCESS_KEY_ID,
|
|
235
|
-
secretAccessKey: process.env.S3_AWS_SECRET_ACCESS_KEY,
|
|
236
259
|
region: process.env.S3_AWS_REGION,
|
|
237
260
|
bucketname: process.env.S3_AWS_BUCKET_NAME,
|
|
238
261
|
timeout: parseInt(process.env.S3_AWS_TIMEOUT, 10) || DEFAULT_S3_AWS_TIMEOUT,
|
|
239
262
|
maxSize: parseInt(process.env.S3_AWS_MAX_SIZE, 10) || DEFAULT_S3_AWS_MAX_SIZE,
|
|
240
263
|
maxEvents: parseInt(process.env.S3_AWS_MAX_EVENTS, 10) || DEFAULT_S3_AWS_MAX_EVENTS,
|
|
241
264
|
};
|
|
265
|
+
if (!_.isNil(process.env.S3_AWS_ACCESS_KEY_ID)) logInfo[AWS_S3].accessKeyId = process.env.S3_AWS_ACCESS_KEY_ID;
|
|
266
|
+
if (!_.isNil(process.env.S3_AWS_SECRET_ACCESS_KEY)) logInfo[AWS_S3].secretAccessKey = process.env.S3_AWS_SECRET_ACCESS_KEY;
|
|
242
267
|
}
|
|
243
268
|
return logInfo;
|
|
244
269
|
};
|
|
245
270
|
|
|
246
271
|
const setupTopic = (topicOpts) => {
|
|
247
272
|
const topicConfig = {
|
|
248
|
-
accessKeyId: process.env.SNS_AWS_ACCESS_KEY_ID || DEFAULT_AWS_ACCESS_KEY_ID,
|
|
249
|
-
secretAccessKey: process.env.SNS_AWS_SECRET_ACCESS_KEY || DEFAULT_AWS_SECRET_ACCESS_KEY,
|
|
250
273
|
region: process.env.SNS_AWS_REGION || DEFAULT_AWS_REGION,
|
|
251
274
|
name: topicOpts.name,
|
|
252
275
|
};
|
|
253
276
|
|
|
277
|
+
if (!_.isNil(process.env.SNS_AWS_ACCESS_KEY_ID)) topicConfig.accessKeyId = process.env.SNS_AWS_ACCESS_KEY_ID;
|
|
278
|
+
if (!_.isNil(process.env.SNS_AWS_SECRET_ACCESS_KEY)) topicConfig.secretAccessKey = process.env.SNS_AWS_SECRET_ACCESS_KEY;
|
|
279
|
+
|
|
254
280
|
return topicConfig;
|
|
255
281
|
};
|
|
256
282
|
|
|
283
|
+
const setupEncryption = (encryptionOpts) => {
|
|
284
|
+
const encryptionConfig = {
|
|
285
|
+
set: encryptionOpts.set,
|
|
286
|
+
database: process.env.ENCRYPTION_DATABASE,
|
|
287
|
+
keyVaultTable: process.env.KEY_VAULT_TABLE,
|
|
288
|
+
kmsProvider: process.env.KMS_PROVIDER || DEFAULT_KMS_PROVIDER,
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
if (encryptionConfig.kmsProvider.toLowerCase() === 'aws') {
|
|
292
|
+
encryptionConfig.aws = {};
|
|
293
|
+
encryptionConfig.region = process.env.MASTER_KEY_AWS_REGION || DEFAULT_AWS_REGION;
|
|
294
|
+
encryptionConfig.masterKeyARN = process.env.MASTER_KEY_ARN;
|
|
295
|
+
|
|
296
|
+
if (!_.isNil(process.env.ENCRYPTION_ACCESS_KEY_ID)) encryptionConfig.aws.accessKeyId = process.env.ENCRYPTION_ACCESS_KEY_ID;
|
|
297
|
+
if (!_.isNil(process.env.ENCRYPTION_SECRET_ACCESS_KEY)) encryptionConfig.aws.secretAccessKey = process.env.ENCRYPTION_SECRET_ACCESS_KEY;
|
|
298
|
+
}
|
|
299
|
+
else encryptionConfig.localMasterKey = process.env.LOCAL_MASTER_KEY;
|
|
300
|
+
|
|
301
|
+
if (Object.keys(encryptionOpts.keys).length > 0) encryptionConfig.keys = encryptionOpts.keys;
|
|
302
|
+
|
|
303
|
+
return encryptionConfig;
|
|
304
|
+
};
|
|
305
|
+
|
|
257
306
|
const checkConfig = (config) => {
|
|
258
307
|
const errs = [];
|
|
259
308
|
|
|
@@ -270,11 +319,101 @@ const checkConfig = (config) => {
|
|
|
270
319
|
if (errs.length > 0) {
|
|
271
320
|
const error = new Error('Missing values');
|
|
272
321
|
|
|
273
|
-
logger.error(error, { values: errs },
|
|
322
|
+
logger.error(error, { values: errs }, correlationIdStart);
|
|
274
323
|
throw error;
|
|
275
324
|
}
|
|
276
325
|
};
|
|
277
326
|
|
|
327
|
+
/**
|
|
328
|
+
* Indicates if the environment is prod
|
|
329
|
+
*
|
|
330
|
+
* @function isProd
|
|
331
|
+
* @category sync
|
|
332
|
+
* @return {boolean} `true` if the environment is `prod` or `production`.
|
|
333
|
+
*
|
|
334
|
+
* The following environment variables are used
|
|
335
|
+
*
|
|
336
|
+
* | Env variable name | Description | Value | Comments |
|
|
337
|
+
* | ----------------- | ----------- | ----- | -------- |
|
|
338
|
+
* | NODE_ENV | environnment of the microservice |
|
|
339
|
+
*/
|
|
340
|
+
const isProd = () => {
|
|
341
|
+
if (_.isString(process.env.NODE_ENV)) return _.includes(PRODUCTIONS, process.env.NODE_ENV.toLowerCase());
|
|
342
|
+
return false;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
process.env.SERVER_LOCAL_IPV4 = ip.address();
|
|
346
|
+
process.env.AWS_LOCAL_PROPERTIES = DEFAULT_AWS_LOCAL_PROPERTIES;
|
|
347
|
+
process.env.CONSOLE_LEVEL = process.env.CONSOLE_LEVEL || DEFAULT_LOG_LEVEL;
|
|
348
|
+
process.env.LOG_LEVEL = process.env.LOG_LEVEL || DEFAULT_LOG_LEVEL;
|
|
349
|
+
process.env.SERVER_ID = process.env.SERVER_ID || uuid.v4();
|
|
350
|
+
|
|
351
|
+
const configuration = {
|
|
352
|
+
nodeEnvironment: process.env.NODE_ENV || DEFAULT_ENV,
|
|
353
|
+
locationProvider: process.env.LOCATION_PROVIDER || DEFAULT_LOCATION_PROVIDER,
|
|
354
|
+
cloudProvider: process.env.CLOUD_PROVIDER || DEFAULT_CLOUD_PROVIDER,
|
|
355
|
+
serverSettings: {
|
|
356
|
+
id: process.env.SERVER_ID,
|
|
357
|
+
customerCode: process.env.CUSTOMER_CODE || DEFAULT_CUSTOMER_CODE,
|
|
358
|
+
customerCodeSep: process.env.CUSTOMER_CODE ? CUSTOMER_CODE_SEP : '',
|
|
359
|
+
securitySet: process.env.SERVER_SECURITY_SET || DEFAULT_SERVER_SECURITY_SET,
|
|
360
|
+
port: process.env.SERVER_PORT,
|
|
361
|
+
interceptError: process.env.INTERCEPT_ERROR || DEFAULT_INTERCEPT_ERROR,
|
|
362
|
+
ip: {
|
|
363
|
+
local: process.env.SERVER_LOCAL_IPV4,
|
|
364
|
+
},
|
|
365
|
+
public: {
|
|
366
|
+
protocol: process.env.SERVER_PUBLIC_PROTOCOL || DEFAULT_SERVER_PUBLIC_PROTOCOL,
|
|
367
|
+
domainName: process.env.SERVER_PUBLIC_DOMAIN_NAME || DEFAULT_SERVER_PUBLIC_DOMAIN_NAME,
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
security: {
|
|
371
|
+
admin: {
|
|
372
|
+
externalId: process.env.ADMIN_EXTERNAL_ID || DEFAULT_ADMIN_EXTERNAL_ID,
|
|
373
|
+
},
|
|
374
|
+
server: {
|
|
375
|
+
id: process.env.OAUTH_CLIENT_ID,
|
|
376
|
+
secret: process.env.OAUTH_CLIENT_SECRET,
|
|
377
|
+
accessKey: process.env.OAUTH_CLIENT_ACCESS_KEY,
|
|
378
|
+
audience: process.env.OAUTH_CLIENT_AUDIENCE,
|
|
379
|
+
issuer: process.env.OAUTH_ISSUER,
|
|
380
|
+
},
|
|
381
|
+
generic: {
|
|
382
|
+
key: process.env.OAUTH_GENERIC_KEY || NO_GENERIC,
|
|
383
|
+
audience: process.env.OAUTH_GENERIC_AUDIENCE || NO_GENERIC,
|
|
384
|
+
},
|
|
385
|
+
apiKeys: process.env.API_KEYS ? _.split(_.trim(process.env.API_KEYS), /\s*,\s*/) : [],
|
|
386
|
+
},
|
|
387
|
+
cluster: {
|
|
388
|
+
management: process.env.CLUSTER_MANAGEMENT || DEFAULT_CLUSTER_MANAGEMENT,
|
|
389
|
+
timeout: parseInt(process.env.REQUEST_TIMEOUT, 10) || DEFAULT_REQUEST_TIMEOUT,
|
|
390
|
+
},
|
|
391
|
+
cache: {
|
|
392
|
+
set: process.env.CACHE_SET || DEFAULT_CACHE_SET,
|
|
393
|
+
},
|
|
394
|
+
encryption: {
|
|
395
|
+
set: process.env.ENCRYPTION_SET || DEFAULT_ENCRYPTION_SET,
|
|
396
|
+
},
|
|
397
|
+
topic: {
|
|
398
|
+
set: process.env.TOPIC_SET || DEFAULT_TOPIC_SET,
|
|
399
|
+
},
|
|
400
|
+
dependencies: { // everyserver will resport to mIT
|
|
401
|
+
mIT: {
|
|
402
|
+
url: process.env.MIT_URL,
|
|
403
|
+
audience: process.env.MIT_AUDIENCE,
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
registration: {
|
|
407
|
+
set: process.env.REGISTRATION_SET || DEFAULT_REGISTRATION_SET,
|
|
408
|
+
retry: parseInt(process.env.REGISTRATION_RETRY, 10) || DEFAULT_REGISTRATION_RETRY,
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
if (process.env.OAUTH_GENERIC_PREVIOUS_KEY) configuration.security.generic.previousKey = process.env.OAUTH_GENERIC_PREVIOUS_KEY;
|
|
413
|
+
if (process.env.SWAGGER_API_KEY) configuration.serverSettings.apiKey = process.env.SWAGGER_API_KEY;
|
|
414
|
+
configuration.logInfo = setupLog();
|
|
415
|
+
configuration.locationProvider = setupLocationProvider();
|
|
416
|
+
|
|
278
417
|
/**
|
|
279
418
|
* Set the configuration of the micro-service.
|
|
280
419
|
*
|
|
@@ -291,13 +430,16 @@ const checkConfig = (config) => {
|
|
|
291
430
|
*
|
|
292
431
|
* | Env variable name | Description | Value | Comments |
|
|
293
432
|
* | ----------------- | ----------- | ----- | -------- |
|
|
294
|
-
* | SERVER_VERSION | version of the software for the micro-service| package.version |
|
|
295
|
-
* | SERVER_NAME | name of the micro-service | package.
|
|
296
|
-
* | SERVER_TYPE | type of the micro-service | package.type |
|
|
297
|
-
* | SWAGGER_FILE_VERSION | version of the swagger file for the API | package.swaggerFile.version |
|
|
298
|
-
* |
|
|
299
|
-
* |
|
|
300
|
-
* |
|
|
433
|
+
* | SERVER_VERSION | version of the software for the micro-service | package.version | serverSettings.version
|
|
434
|
+
* | SERVER_NAME | name of the micro-service | package.name | serverSettings.name
|
|
435
|
+
* | SERVER_TYPE | type of the micro-service | package.mimik.type | serverSettings.type
|
|
436
|
+
* | SWAGGER_FILE_VERSION | version of the swagger file for the API | package.swaggerFile.version | serverSettings.swaggerFileVersion
|
|
437
|
+
* | SWAGGER_FILE_ACCOUNT | account associated with the API | package.swaggerFile.account |
|
|
438
|
+
* | SWAGGER_FILE_NAME | name of the API | package.swaggerFile.name |
|
|
439
|
+
* | SERVER_LOCAL_IPV4 | IP address of the micro-service | ip.address() | serverSettings.ip.local
|
|
440
|
+
* | CONSOLE_LEVEL | log level for console output | debug | logInfo.consoleLevel
|
|
441
|
+
* | LOG_LEVEL | log level for console output | debug | logInfo.logLevel
|
|
442
|
+
* | AWS_LOCAL_PROPERTIES | internal ip address to access aws insrance properties | 169.254.169.254
|
|
301
443
|
*
|
|
302
444
|
* The following environement variables are being used for the configuration:
|
|
303
445
|
*
|
|
@@ -307,46 +449,42 @@ const checkConfig = (config) => {
|
|
|
307
449
|
* | LOCATION_PROVIDER | location provider URL to use for ip location or `noPublic` or `environment` | noPublic | locationProvider.url or locationProvider | `see public-helper`
|
|
308
450
|
* | LOCATION_PROVIDER_KEY | location provider key to use to access the location provider | null | locationProvider.key | see `public-helper`
|
|
309
451
|
* | CLOUD_PROVIDER | cloud provider running the service | noCloud | cloudProvider | see `public-helper`
|
|
310
|
-
* | AWS_ACCESS_KEY_ID | aws access key id for the account | ----noAccessKeyId---- | aws.accessKeyId |
|
|
311
|
-
* | AWS_SECRET_ACCESS_KEY | secret for the aws access key id for the account | ----noAccessKey---- | aws.secretAccessKey |
|
|
312
|
-
* | AWS_REGION | aws region for the account | ----noRegion---- | aws.region |
|
|
313
452
|
* | SERVER_ID | service id | uuid.v4() | serverSettings.id |
|
|
453
|
+
* | CUSTOMER_CODE | customer code associated with the service instance | '' | serverSettings.customerCode | empty string
|
|
314
454
|
* | SWAGGER_FILE_DIRECTORY | directory where the api definition is located | ./api | serverSettings.api | [1]
|
|
455
|
+
* | SWAGGER_API_KEY | key on swagger hub for provate api access | | serverSettings.apiKey
|
|
315
456
|
* | SERVER_SECURITY_SET | switch to enable or disable the token interpretation | on | serverSettings.securitySet | only active if environment is `local`
|
|
316
457
|
* | INTERCEPT_ERROR | switch to use or not the errorIntercept option | on | serverSettings.interceptError | must be set to off for mID
|
|
317
458
|
* | SERVER_PORT | port of the server | | serverSettings.port |
|
|
318
|
-
* | SERVER_NAME | name of the micro-service | | serverSettings.[]()name | see setup environment variable
|
|
319
|
-
* | SERVER_TYPE | type of the micro-service | | serverSettings.type | see setup environment variable
|
|
320
|
-
* | SERVER_VERSION | version of the software for the micro-service | | serverSettings.version | see setup environment variable
|
|
321
|
-
* | SWAGGER_FILE_VERSION | version of the swagger file for the API | | serverSettings.swaggerFileVersion | see setup environment variable
|
|
322
|
-
* | SERVER_LOCAL_IPV4 | ip address of the server | | serverSettings.ip.local | see setup environment variable
|
|
323
459
|
* | SERVER_PUBLIC_PROTOCOL | protocol used to defined the domain address of the sevice | http: | serverSettings.public.protocol |
|
|
324
460
|
* | SERVER_PUBLIC_DOMAIN_NAME | domain name used to define the domain address of the service | null | serverSettings.public.domainName |
|
|
325
461
|
* | ADMIN_EXTERNAL_ID | external id of the admin role to be chacked in the token | admin | security.admin.externalId |
|
|
326
|
-
* | OAUTH_CLIENT_ID | security id of the service | | security.server.
|
|
462
|
+
* | OAUTH_CLIENT_ID | security id of the service | | security.server.id | [2]
|
|
327
463
|
* | OAUTH_CLIENT_SECRET | secret of the service | | security.server.secret | [2]
|
|
328
464
|
* | OAUTH_CLIENT_ACCESS_KEY | key for token signature | | security.server.accessKey | [2]
|
|
329
465
|
* | OAUTH_CLIENT_AUDIENCE | url representing the server to mST | | security.server.audience | [2]
|
|
330
466
|
* | OAUTH_ISSUER | token url of mST | | security.server.issuer | [2]
|
|
331
467
|
* | OAUTH_GENERIC_KEY | key for token signature provided when a generic for this service type is defined | noGeneric | security.generic.key | [2]
|
|
468
|
+
* | OAUTH_GENERIC_PREVIOUS_KEY | key for the token signature before change the public key | | security.generic.previousKey | [2]
|
|
332
469
|
* | OAUTH_GENERIC_AUDIENCE | url representing the generic of the service type to mST | noGeneric | security.generic.audience | [2]
|
|
333
|
-
* |
|
|
334
|
-
* | LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all
|
|
335
|
-
* |
|
|
470
|
+
* | API_KEYS | list of API Keys which a test against in case of APIKey security | [] |
|
|
471
|
+
* | LOG_MODE | collector the be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, 'awsKinesis'
|
|
472
|
+
* | NO_STACK | disable the inclusion of a the stack in all logs | yes | logInfo.noStack
|
|
336
473
|
* | FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
|
|
337
474
|
* | EXIT_DELAY | delay to allow the log transports to flush | 2000 | logInfo.exitDelay | in milliseconds
|
|
338
475
|
* | CLUSTER_MANAGEMENT | switch to enable cluster communication | off | cluster.management | can be `on` or `off`
|
|
339
476
|
* | REQUEST_TIMEOUT | timeout for intra cluster http request | 10000 | cluster.timeout | in milliseconds
|
|
340
477
|
* | CACHE_SET | switch to enable use of cache | off | cache.set | can be `on`, `off`
|
|
341
478
|
* | TOPIC_SET | switch to enable use of event topic | off | topic.set | can be `on`, `off`, `mock`
|
|
479
|
+
* | ENCRYPTION_SET | switch to enable use of mongodb encryption | off | encryption.set | can be `on`, or `off`
|
|
342
480
|
* | MIT_URL | url for reaching mIT | | dependencies.mIT.url |
|
|
343
481
|
* | MIT_AUDIENCE | audience of mIT | | dependencies.mIT.audience | [2]
|
|
344
482
|
* | REGISTRATION_SET | swicht to enable user of registration | on | registration.set | can be `on` or `off`
|
|
345
483
|
* | REGISTRATION_RETRY | retry time for registering to mIT | 3000 | registration.retry | in milliseconds
|
|
346
|
-
* |
|
|
347
|
-
* |
|
|
484
|
+
* | `${configuration.serverSettings.type}_URL`.toUpperCase() | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
|
|
485
|
+
* | `${configuration.serverSettings.type}_AUDIENCE`.toUpperCase() | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
|
|
348
486
|
*
|
|
349
|
-
* [1]: `/(
|
|
487
|
+
* [1]: `/(SWAGGER_FILE_ACCOUNT)_(SERVER_TYPE)_(SWAGGER_FILE_VERSION)_swagger.json` is added to the `serverSettings.api` property
|
|
350
488
|
*
|
|
351
489
|
* [2]: defined when registering to mST
|
|
352
490
|
*
|
|
@@ -373,148 +511,110 @@ const checkConfig = (config) => {
|
|
|
373
511
|
*
|
|
374
512
|
* | Env variable name | Description | Default | Comments |
|
|
375
513
|
* | ----------------- | ----------- | ------- | -------- |
|
|
376
|
-
* | SNS_AWS_ACCESS_KEY_ID | access key id for AWS SNS |
|
|
377
|
-
* | SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS |
|
|
514
|
+
* | SNS_AWS_ACCESS_KEY_ID | access key id for AWS SNS | |
|
|
515
|
+
* | SNS_AWS_SECRET_ACCESS_KEY | secret access key for AWS SNS | |
|
|
378
516
|
* | SNS_AWS_REGION | region where the topic is | ----noRegion---- |
|
|
379
517
|
*
|
|
380
518
|
* When `mongodb` is used the following environment variables are used for the configuration:
|
|
381
519
|
*
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
520
|
+
* | Env variable name | Description | Default | Comments |
|
|
521
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
522
|
+
* | DATABASE_NAME | name of the database to store the information | |
|
|
523
|
+
* | DATABASE_IP | ip address of the database | localhost |
|
|
524
|
+
* | DATABASE_USER | user to access the database | null | if missing no user/password will be used
|
|
525
|
+
* | DATABASE_PASSWORD | password to access the database | null | if missing no user/password will be used
|
|
526
|
+
* | DATABASE_CONNECTION_TIMEOUT | the time to connect to the database before error is generated | 30 | in seconds
|
|
527
|
+
* | DATABASE_RECONNECTION_OFFSET | offset for the time to reconnect to the database before error is generated | 5 | in seconds
|
|
528
|
+
* | MONGO_USE_SRV | to use srv connection url set to `yes` | `no` |
|
|
529
|
+
* | MONGO_AUTH_DATABASE | the auth database where users exists | |
|
|
530
|
+
* | MONGO_MAX_POOL_SIZE | the minimum number of connections in the connection pool | 5 |
|
|
531
|
+
* | MONGO_MIN_POOL_SIZE | the maximum number of connections in the connection pool | 10 |
|
|
532
|
+
* | MONGO_MAX_IDLE_TIME | the maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed | 3000 | in milliseconds
|
|
533
|
+
* | MONGO_RETRY_WRITES | defines if the transaction should be tried again to write set to true or false | |
|
|
534
|
+
* | MONGO_WRITE_CONCERN | accepts a number or `majority` | |
|
|
535
|
+
* | MONGO_SSL | uses ssl connection if `yes` | `no` |
|
|
536
|
+
* | MONGO_SSL_VALIDATE | validates mongod server certificate against ca if set to `yes` | `yes` | `yes` if MONGO_SSL is also `yes`
|
|
537
|
+
* | MONGO_SSL_ALLOW_INVALID_HOSTNAMES | set to yes to allows invalid hostnames | |
|
|
538
|
+
* | MONGO_REPLICAT_SET | specifies the name of the replica set, if the mongod is a member of a replica set | | not mandatory
|
|
539
|
+
* | MONGO_WAIT_QUEUE_MULTIPLE | a number that the driver multiples the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the pool | | no mandatory
|
|
540
|
+
* | MONGO_WAIT_QUEUE_TIMEOUT | the maximum time in milliseconds that a thread can wait for a connection to become available | | not mandatory
|
|
541
|
+
* | MONGO_KEEP_ALIVE | pall th kep the connection with the database alive | true |
|
|
542
|
+
* | MONGO_KEEP_ALIVE_INITIAL_DELAY | is the number of milliseconds to wait before initiating keepAlive on the socket | 300000 | in milliseconds
|
|
543
|
+
* | MONGO_SOCKET_TIMEOUT | The time in milliseconds to attempt a send or receive on a socket before the attempt times out | 20000 | in milliseconds
|
|
544
|
+
* | MONGO_FAMILY | IP address family | 4 | 4 -> IPV4, 6 -> IPV6
|
|
545
|
+
* | MONGO_SERVER_SELECTION_TIMEOUT | the MongoDB driver will try to find a server to send any given operation to, and keep retrying for serverSelectionTimeoutMS milliseconds | 30000 | in milliseconds
|
|
546
|
+
* | MONGO_HEARTBEAT_FREQUENCY | the MongoDB driver sends a heartbeat every heartbeatFrequencyMS to check on the status of the connection | 10000 | in milliseconds
|
|
547
|
+
*
|
|
548
|
+
* When `on` is used for `ENCRYPTION_SET` the following environment variables are used for the configuration:
|
|
549
|
+
*
|
|
550
|
+
* | Env variable name | Description | Default | Comments |
|
|
551
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
552
|
+
* | ENCRYPTION_DATABASE | database name where data encryption keyvault exists | admin |
|
|
553
|
+
* | KEY_VAULT_TABLE | collection name which has data encryption keys | keystore |
|
|
554
|
+
* | KMS_PROVIDER | Key Management service provider for master key | local |
|
|
555
|
+
* | MASTER_KEY_AWS_REGION | if KMS is aws region where master key exists | ----noRegion---- |
|
|
556
|
+
* | MASTER_KEY_ARN | if KMS is aws ARN of master key | |
|
|
557
|
+
* | ENCRYPTION_ACCESS_KEY_ID | if KMS is aws, accessKeyId to connect KMS | |
|
|
558
|
+
* | ENCRYPTION_SECRET_ACCESS_KEY | if KMS is aws, secretAccessKey to connect KMS | |
|
|
559
|
+
* | LOCAL_MASTER_KEY | if KMS is local, masterkey to encrypt data keys | |
|
|
560
|
+
*
|
|
406
561
|
* When `dynamodb` is used the following environement variables are used for the configuration:
|
|
407
562
|
*
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
563
|
+
* | Env variable name | Description | Default | Comments |
|
|
564
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
565
|
+
* | DYNAMODB_AWS_ACCESS_KEY_ID | access key id for AWS dynamodb | |
|
|
566
|
+
* | DYNAMODB_AWS_SECRET_ACCESS_KEY | secret access key for AWS dynamodb | |
|
|
567
|
+
* | DYNAMODB_AWS_REGION | region where dynamodb is | ----noRegion---- |
|
|
568
|
+
* | DYNAMODB_LOCAL_URL | url access the locally deploy dynamodb | http://localhost:8000 |
|
|
569
|
+
* | DYNAMO_THROUGHPUT_READ | throughput read for dynamodb index | 1 |
|
|
570
|
+
* | DYNAMO_THROUGHPUT_WRITE | throughput write for dynamodb index | 1 |
|
|
571
|
+
* | DYNAMO_SCHEMA_THROUGHPUT_READ | throughput read for dynamodb schema | 1 |
|
|
572
|
+
* | DYNAMO_SCHEMA_THROUGHPUT_WRITE | throughput write for dynamodb schema | 1 |
|
|
573
|
+
* | DYNAMO_SCHEMA_THROUGHPUT | throughput for dynamodb schema |
|
|
574
|
+
*
|
|
575
|
+
* `DYNAMO_SCHEMA_THROUGHPUT` takes precedence over `DYNAMO_SCHEMA_THROUGHPUT_READ` and `DYNAMO_SCHEMA_THROUGHPUT_WRITE`. If DYNAMO_SCHEMA_THROUGHPUT is set to `ON_DEMAND` then index throughput wont apply, and if DYNAMO_SCHEMA_THROUGHPUT is not set to a number the value will be 1.
|
|
416
576
|
*
|
|
417
577
|
* When `redis` is used the following environement variables are used for the configuration:
|
|
418
578
|
*
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
579
|
+
* | Env variable name | Description | Default | Comments |
|
|
580
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
581
|
+
* | CACHE_IP | domain of the redis server to use | localhost:6379 |
|
|
582
|
+
* | CACHE_PASSWORD | password if the redis service is protected (requirepass in redis.conf) | null |
|
|
583
|
+
* | CACHE_CONNECTION_TIMEOUT | time the server will wait at start to connect to the cache | 20 | in seconds
|
|
584
|
+
* | CACHE_REQUEST_TTL | request time to live in cache | 10 | in seconds
|
|
585
|
+
* | CACHE_API_ID_TTL | API request time to live for main resource | 20 | in seconds
|
|
586
|
+
* | CACHE_API_OPTION_TTL | API request time to live for option | 5 | in seconds
|
|
587
|
+
* | REDIS_RECONNECT_TRIES | number of tries to restablish a connection | 100 |
|
|
588
|
+
* | REDIS_RECONNECT_INTERVAL | time to wait before retry | 500 | in milliseconds
|
|
589
|
+
* | REDIS_REQUEST_MAX_MEMORY | maximum memory size of the request cache | 10 | in megabytes
|
|
590
|
+
* | REDIS_REQUEST_MAX_MEMORY_POLICY | eviction policy of the request cache | allkeys-lru |
|
|
591
|
+
* | REDIS_SOCKET_KEEPALIVE | keep alive for long running connections | yes |
|
|
592
|
+
* | REDIS_ENABLE_OFFLINE_QUEUE | queuing event when not connected | yes |
|
|
433
593
|
*/
|
|
434
594
|
const setConfig = (pack, options) => {
|
|
435
595
|
process.env.SERVER_VERSION = pack.version;
|
|
436
596
|
process.env.SERVER_NAME = pack.name;
|
|
437
|
-
process.env.SERVER_TYPE = pack.type;
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
region: process.env.AWS_REGION || DEFAULT_AWS_REGION,
|
|
453
|
-
},
|
|
454
|
-
serverSettings: {
|
|
455
|
-
id: process.env.SERVER_ID || uuid.v4(),
|
|
456
|
-
api: `${process.env.SWAGGER_FILE_DIRECTORY || DEFAULT_SWAGGER_DIR}/${process.env.SERVER_NAME}${SWAGGER_SEP}${process.env.SWAGGER_FILE_VERSION}${SWAGGER_SEP}${SWAGGER_EXT}`,
|
|
457
|
-
securitySet: process.env.SERVER_SECURITY_SET || DEFAULT_SERVER_SECURITY_SET,
|
|
458
|
-
port: process.env.SERVER_PORT,
|
|
459
|
-
name: process.env.SERVER_NAME,
|
|
460
|
-
type: process.env.SERVER_TYPE,
|
|
461
|
-
version: process.env.SERVER_VERSION,
|
|
462
|
-
swaggerFileVersion: process.env.SWAGGER_FILE_VERSION,
|
|
463
|
-
interceptError: process.env.INTERCEPT_ERROR || DEFAULT_INTERCEPT_ERROR,
|
|
464
|
-
ip: {
|
|
465
|
-
local: process.env.SERVER_LOCAL_IPV4,
|
|
466
|
-
},
|
|
467
|
-
public: {
|
|
468
|
-
protocol: process.env.SERVER_PUBLIC_PROTOCOL || DEFAULT_SERVER_PUBLIC_PROTOCOL,
|
|
469
|
-
domainName: process.env.SERVER_PUBLIC_DOMAIN_NAME || DEFAULT_SERVER_PUBLIC_DOMAIN_NAME,
|
|
470
|
-
},
|
|
471
|
-
},
|
|
472
|
-
security: {
|
|
473
|
-
admin: {
|
|
474
|
-
externalId: process.env.ADMIN_EXTERNAL_ID || DEFAULT_ADMIN_EXTERNAL_ID,
|
|
475
|
-
},
|
|
476
|
-
server: {
|
|
477
|
-
id: process.env.OAUTH_CLIENT_ID,
|
|
478
|
-
secret: process.env.OAUTH_CLIENT_SECRET,
|
|
479
|
-
accessKey: process.env.OAUTH_CLIENT_ACCESS_KEY,
|
|
480
|
-
audience: process.env.OAUTH_CLIENT_AUDIENCE,
|
|
481
|
-
issuer: process.env.OAUTH_ISSUER,
|
|
482
|
-
},
|
|
483
|
-
generic: {
|
|
484
|
-
key: process.env.OAUTH_GENERIC_KEY || NO_GENERIC,
|
|
485
|
-
audience: process.env.OAUTH_GENERIC_AUDIENCE || NO_GENERIC,
|
|
486
|
-
},
|
|
487
|
-
},
|
|
488
|
-
cluster: {
|
|
489
|
-
management: process.env.CLUSTER_MANAGEMENT || DEFAULT_CLUSTER_MANAGEMENT,
|
|
490
|
-
timeout: parseInt(process.env.REQUEST_TIMEOUT, 10) || DEFAULT_REQUEST_TIMEOUT,
|
|
491
|
-
},
|
|
492
|
-
cache: {
|
|
493
|
-
set: process.env.CACHE_SET || DEFAULT_CACHE_SET,
|
|
494
|
-
},
|
|
495
|
-
topic: {
|
|
496
|
-
set: process.env.TOPIC_SET || DEFAULT_TOPIC_SET,
|
|
497
|
-
},
|
|
498
|
-
dependencies: { // everyserver will resport to mIT
|
|
499
|
-
mIT: {
|
|
500
|
-
url: process.env.MIT_URL,
|
|
501
|
-
audience: process.env.MIT_AUDIENCE,
|
|
502
|
-
},
|
|
503
|
-
},
|
|
504
|
-
registration: {
|
|
505
|
-
set: process.env.REGISTRATION_SET || DEFAULT_REGISTRATION_SET,
|
|
506
|
-
retry: parseInt(process.env.REGISTRATION_RETRY, 10) || DEFAULT_REGISTRATION_RETRY,
|
|
507
|
-
},
|
|
508
|
-
};
|
|
509
|
-
// setup the log configuration
|
|
510
|
-
configuration.logInfo = setupLog();
|
|
597
|
+
if (pack.mimik) process.env.SERVER_TYPE = pack.mimik.type;
|
|
598
|
+
if (pack.swaggerFile) {
|
|
599
|
+
process.env.SWAGGER_FILE_VERSION = pack.swaggerFile.version;
|
|
600
|
+
process.env.SWAGGER_FILE_ACCOUNT = pack.swaggerFile.account;
|
|
601
|
+
process.env.SWAGGER_FILE_NAME = pack.swaggerFile.name;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const apiFilename = `${process.env.SWAGGER_FILE_ACCOUNT}${SWAGGER_SEP}${process.env.SWAGGER_FILE_NAME}${SWAGGER_SEP}${process.env.SWAGGER_FILE_VERSION}${SWAGGER_SEP}${SWAGGER_EXT}`;
|
|
605
|
+
|
|
606
|
+
configuration.serverSettings.name = process.env.SERVER_NAME;
|
|
607
|
+
configuration.serverSettings.type = process.env.SERVER_TYPE;
|
|
608
|
+
configuration.serverSettings.version = process.env.SERVER_VERSION;
|
|
609
|
+
configuration.serverSettings.api = `${process.env.SWAGGER_FILE_DIRECTORY || DEFAULT_SWAGGER_DIR}/${apiFilename}`;
|
|
610
|
+
configuration.serverSettings.swaggerFileVersion = process.env.SWAGGER_FILE_VERSION;
|
|
611
|
+
|
|
511
612
|
// default for every server for cluster management
|
|
512
613
|
configuration.dependencies[configuration.serverSettings.type] = {
|
|
513
614
|
url: process.env[`${configuration.serverSettings.type}_URL`.toUpperCase()] || 'self', // this url should never be needed
|
|
514
615
|
audience: process.env[`${configuration.serverSettings.type}_AUDIENCE`.toUpperCase()],
|
|
515
616
|
};
|
|
516
617
|
|
|
517
|
-
configuration.locationProvider = setupLocationProvider();
|
|
518
618
|
if (options.database) {
|
|
519
619
|
if (options.database.type === 'mongodb') {
|
|
520
620
|
configuration.mongoSettings = setupMongo(options.database);
|
|
@@ -543,6 +643,9 @@ const setConfig = (pack, options) => {
|
|
|
543
643
|
if (options.topic && configuration.topic.set === SET_ON) {
|
|
544
644
|
configuration.topicSettings = setupTopic(options.topic);
|
|
545
645
|
}
|
|
646
|
+
if (options.encryption && configuration.encryption.set === SET_ON) {
|
|
647
|
+
configuration.encryption = setupEncryption(options.encryption);
|
|
648
|
+
}
|
|
546
649
|
if (options.dependencies) {
|
|
547
650
|
Object.keys(options.dependencies).forEach((dependency) => {
|
|
548
651
|
configuration.dependencies[dependency] = options.dependencies[dependency];
|
|
@@ -571,4 +674,5 @@ const setConfig = (pack, options) => {
|
|
|
571
674
|
|
|
572
675
|
module.exports = {
|
|
573
676
|
setConfig,
|
|
677
|
+
isProd,
|
|
574
678
|
};
|
package/lib/common.js
CHANGED
|
@@ -8,12 +8,16 @@ const NO_PUBLIC_PROVIDER = 'noPublic';
|
|
|
8
8
|
const ENV_VARIABLE = 'environment';
|
|
9
9
|
const REDIS_BASE_URL = 'redis://';
|
|
10
10
|
const MONGO_BASE_URL = 'mongodb://';
|
|
11
|
+
const MONGO_BASE_URL_SRV = 'mongodb+srv://';
|
|
11
12
|
const SWAGGER_EXT = 'swagger.json';
|
|
12
13
|
const SWAGGER_SEP = '_';
|
|
14
|
+
const CUSTOMER_CODE_SEP = '__';
|
|
15
|
+
const PRODUCTIONS = ['prod', 'production'];
|
|
13
16
|
|
|
14
17
|
const DEFAULT_ENV = 'local';
|
|
15
18
|
const DEFAULT_LOCATION_PROVIDER = NO_PUBLIC_PROVIDER;
|
|
16
19
|
const DEFAULT_CLOUD_PROVIDER = 'noCloud';
|
|
20
|
+
const DEFAULT_CUSTOMER_CODE = '';
|
|
17
21
|
|
|
18
22
|
const DEFAULT_CACHE_IP = 'localhost:6379';
|
|
19
23
|
const DEFAULT_CACHE_PASSWORD = null;
|
|
@@ -29,30 +33,32 @@ const DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY = 'allkeys-lru';
|
|
|
29
33
|
const DEFAULT_REDIS_SOCKET_KEEPALIVE = true;
|
|
30
34
|
const DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE = true;
|
|
31
35
|
|
|
32
|
-
const DEFAULT_AWS_ACCESS_KEY_ID = '---noAccessKeyId---';
|
|
33
|
-
const DEFAULT_AWS_SECRET_ACCESS_KEY = '---noSecretAccessKey---';
|
|
34
36
|
const DEFAULT_AWS_REGION = '---noRegion--';
|
|
37
|
+
const DEFAULT_AWS_LOCAL_PROPERTIES = '169.254.169.254'; // to access properties of the instance on AWS
|
|
35
38
|
|
|
36
39
|
const DEFAULT_DYNAMODB_LOCAL_URL = 'http://localhost:8000';
|
|
37
40
|
const DEFAULT_DYNAMO_THROUGHPUT_READ = 1;
|
|
38
41
|
const DEFAULT_DYNAMO_THROUGHPUT_WRITE = 1;
|
|
42
|
+
const DEFAULT_DYNAMO_THROUGHPUT = 1;
|
|
39
43
|
|
|
40
44
|
const DEFAULT_MONGO_MAX_POOL_SIZE = 10;
|
|
41
45
|
const DEFAULT_MONGO_MIN_POOL_SIZE = 5;
|
|
42
46
|
const DEFAULT_MONGO_MAX_IDLE_TIME = 3000; // in ms
|
|
43
|
-
const DEFAULT_MONGO_AUTO_RECONNECT = true;
|
|
44
|
-
const DEFAULT_MONGO_RECONNECT_TRIES = 100;
|
|
45
|
-
const DEFAULT_MONGO_RECONNECT_INTERVAL = 500; // in ms
|
|
46
47
|
const DEFAULT_MONGO_KEEP_ALIVE = true;
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
48
|
+
const DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY = 300000; // in ms
|
|
49
|
+
const DEFAULT_MONGO_SOCKET_TIMEOUT = 20000; // in ms
|
|
50
|
+
const DEFAULT_MONGO_FAMILY = 4; // 4 -> ipv4, 6 -> ipv6
|
|
51
|
+
const DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT = 30000; // in ms
|
|
52
|
+
const DEFAULT_MONGO_HEARTBEAT_FREQUENCY = 10000; // in ms
|
|
51
53
|
|
|
52
54
|
const DEFAULT_DATABASE_IP = 'localhost';
|
|
53
55
|
const DEFAULT_DATABASE_USER = null;
|
|
54
56
|
const DEFAULT_DATABASE_PASSWORD = null;
|
|
55
57
|
const DEFAULT_DATABASE_CONNECTION_TIMEOUT = 30; // in seconds
|
|
58
|
+
const DEFAULT_DATABASE_RECONNECTION_OFFSET = 5; // in seconds
|
|
59
|
+
|
|
60
|
+
const DEFAULT_ENCRYPTION_SET = SET_OFF;
|
|
61
|
+
const DEFAULT_KMS_PROVIDER = 'local';
|
|
56
62
|
|
|
57
63
|
const DEFAULT_LOG_LEVEL = 'debug';
|
|
58
64
|
const DEFAULT_FILTER_FILE = 'not set';
|
|
@@ -78,20 +84,24 @@ const DEFAULT_SERVER_PUBLIC_DOMAIN_NAME = null;
|
|
|
78
84
|
|
|
79
85
|
const DEFAULT_ADMIN_EXTERNAL_ID = 'admin';
|
|
80
86
|
|
|
81
|
-
const DEFAULT_SWAGGER_DIR = '
|
|
87
|
+
const DEFAULT_SWAGGER_DIR = '../api';
|
|
82
88
|
|
|
83
89
|
module.exports = {
|
|
84
90
|
SUMOLOGIC,
|
|
85
91
|
AWS_S3,
|
|
86
92
|
ALL,
|
|
87
93
|
SET_ON,
|
|
94
|
+
CUSTOMER_CODE_SEP,
|
|
88
95
|
NO_PUBLIC_PROVIDER,
|
|
89
96
|
NO_GENERIC,
|
|
90
97
|
ENV_VARIABLE,
|
|
98
|
+
DEFAULT_CUSTOMER_CODE,
|
|
91
99
|
REDIS_BASE_URL,
|
|
92
100
|
MONGO_BASE_URL,
|
|
101
|
+
MONGO_BASE_URL_SRV,
|
|
93
102
|
SWAGGER_EXT,
|
|
94
103
|
SWAGGER_SEP,
|
|
104
|
+
PRODUCTIONS,
|
|
95
105
|
DEFAULT_ENV,
|
|
96
106
|
DEFAULT_LOCATION_PROVIDER,
|
|
97
107
|
DEFAULT_CLOUD_PROVIDER,
|
|
@@ -107,27 +117,28 @@ module.exports = {
|
|
|
107
117
|
DEFAULT_REDIS_REQUEST_MAX_MEMORY_POLICY,
|
|
108
118
|
DEFAULT_REDIS_SOCKET_KEEPALIVE,
|
|
109
119
|
DEFAULT_REDIS_ENABLE_OFFLINE_QUEUE,
|
|
110
|
-
DEFAULT_AWS_ACCESS_KEY_ID,
|
|
111
|
-
DEFAULT_AWS_SECRET_ACCESS_KEY,
|
|
112
120
|
DEFAULT_AWS_REGION,
|
|
121
|
+
DEFAULT_AWS_LOCAL_PROPERTIES,
|
|
113
122
|
DEFAULT_DYNAMODB_LOCAL_URL,
|
|
114
123
|
DEFAULT_DYNAMO_THROUGHPUT_READ,
|
|
115
124
|
DEFAULT_DYNAMO_THROUGHPUT_WRITE,
|
|
125
|
+
DEFAULT_DYNAMO_THROUGHPUT,
|
|
116
126
|
DEFAULT_MONGO_MAX_POOL_SIZE,
|
|
117
127
|
DEFAULT_MONGO_MIN_POOL_SIZE,
|
|
118
128
|
DEFAULT_MONGO_MAX_IDLE_TIME,
|
|
119
|
-
DEFAULT_MONGO_AUTO_RECONNECT,
|
|
120
|
-
DEFAULT_MONGO_RECONNECT_TRIES,
|
|
121
|
-
DEFAULT_MONGO_RECONNECT_INTERVAL,
|
|
122
129
|
DEFAULT_MONGO_KEEP_ALIVE,
|
|
123
|
-
|
|
124
|
-
DEFAULT_MONGO_BUFFER_COMMANDS,
|
|
125
|
-
DEFAULT_MONGO_CONNECT_TIMEOUT,
|
|
130
|
+
DEFAULT_MONGO_KEEP_ALIVE_INITIAL_DELAY,
|
|
126
131
|
DEFAULT_MONGO_SOCKET_TIMEOUT,
|
|
132
|
+
DEFAULT_MONGO_FAMILY,
|
|
133
|
+
DEFAULT_MONGO_SERVER_SELECTION_TIMEOUT,
|
|
134
|
+
DEFAULT_MONGO_HEARTBEAT_FREQUENCY,
|
|
127
135
|
DEFAULT_DATABASE_IP,
|
|
128
136
|
DEFAULT_DATABASE_USER,
|
|
129
137
|
DEFAULT_DATABASE_PASSWORD,
|
|
130
138
|
DEFAULT_DATABASE_CONNECTION_TIMEOUT,
|
|
139
|
+
DEFAULT_DATABASE_RECONNECTION_OFFSET,
|
|
140
|
+
DEFAULT_ENCRYPTION_SET,
|
|
141
|
+
DEFAULT_KMS_PROVIDER,
|
|
131
142
|
DEFAULT_LOG_LEVEL,
|
|
132
143
|
DEFAULT_FILTER_FILE,
|
|
133
144
|
DEFAULT_EXIT_DELAY,
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/configuration",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "Common configuration for mimik services",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "gulp lint",
|
|
8
8
|
"docs": "gulp docs",
|
|
9
|
-
"test": "exit 0"
|
|
9
|
+
"test": "exit 0",
|
|
10
|
+
"prepublishOnly": "gulp docs; gulp lint; npm run test",
|
|
11
|
+
"commit-ready": "gulp docs; gulp lint; npm run test",
|
|
12
|
+
"prepare": "husky install"
|
|
10
13
|
},
|
|
11
14
|
"husky": {
|
|
12
15
|
"hooks": {
|
|
13
|
-
"pre-commit": "npm run
|
|
14
|
-
"pre-push": "npm run
|
|
16
|
+
"pre-commit": "npm run commit-ready",
|
|
17
|
+
"pre-push": "npm run test"
|
|
15
18
|
}
|
|
16
19
|
},
|
|
17
20
|
"keywords": [
|
|
@@ -19,29 +22,33 @@
|
|
|
19
22
|
"microservice",
|
|
20
23
|
"config"
|
|
21
24
|
],
|
|
22
|
-
"author": "mimik",
|
|
25
|
+
"author": "mimik technology inc <support@mimik.com> (https://developer.mimik.com/)",
|
|
23
26
|
"license": "Apache-2.0",
|
|
24
27
|
"repository": {
|
|
25
28
|
"type": "git",
|
|
26
29
|
"url": "https://bitbucket.org/mimiktech/configuration"
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
29
|
-
"@mimik/
|
|
32
|
+
"@mimik/request-helper": "^1.7.3",
|
|
33
|
+
"@mimik/sumologic-winston-logger": "^1.6.6",
|
|
30
34
|
"ip": "1.1.5",
|
|
31
|
-
"lodash": "4.17.
|
|
32
|
-
"uuid": "
|
|
35
|
+
"lodash": "4.17.21",
|
|
36
|
+
"uuid": "8.3.2"
|
|
33
37
|
},
|
|
34
38
|
"devDependencies": {
|
|
35
|
-
"eslint": "
|
|
36
|
-
"eslint-
|
|
37
|
-
"eslint
|
|
38
|
-
"eslint-
|
|
39
|
-
"eslint-plugin-
|
|
39
|
+
"@mimik/eslint-plugin-dependencies": "^2.4.1",
|
|
40
|
+
"@mimik/eslint-plugin-document-env": "^1.0.0",
|
|
41
|
+
"eslint": "8.4.1",
|
|
42
|
+
"eslint-config-airbnb": "18.2.1",
|
|
43
|
+
"eslint-plugin-import": "2.25.3",
|
|
44
|
+
"eslint-plugin-jsx-a11y": "6.5.1",
|
|
45
|
+
"eslint-plugin-react": "7.27.1",
|
|
46
|
+
"eslint-plugin-react-hooks": "4.3.0",
|
|
40
47
|
"fancy-log": "1.3.3",
|
|
41
48
|
"gulp": "4.0.2",
|
|
42
49
|
"gulp-eslint": "6.0.0",
|
|
43
|
-
"gulp-git": "2.
|
|
44
|
-
"husky": "
|
|
45
|
-
"jsdoc-to-markdown": "
|
|
50
|
+
"gulp-git": "2.10.1",
|
|
51
|
+
"husky": "7.0.4",
|
|
52
|
+
"jsdoc-to-markdown": "7.1.0"
|
|
46
53
|
}
|
|
47
54
|
}
|