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