@mimik/local 1.6.0 → 4.4.2
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 +6 -7
- package/README.md +164 -17
- package/configuration/config.js +4 -4
- package/index.js +365 -94
- package/lib/common.js +55 -3
- package/lib/commonExt.js +29 -21
- package/lib/helpers.js +81 -40
- package/lib/rp-axios-wrapper.js +36 -0
- package/lib/tasks.js +225 -94
- package/manual-test/getAPI.js +1 -1
- package/manual-test/retrieve.js +5 -3
- package/manual-test/start-example.json +46 -0
- package/manual-test/startTest-example.json +8 -0
- package/manual-test/test.json +46 -0
- package/manual-test/testMerge.js +66 -0
- package/manual-test/testString.js +7 -0
- package/package.json +28 -20
- package/package.json.bak +0 -57
package/index.js
CHANGED
|
@@ -8,28 +8,35 @@ const eslint = require('gulp-eslint');
|
|
|
8
8
|
const git = require('gulp-git');
|
|
9
9
|
const jsdoc2md = require('jsdoc-to-markdown');
|
|
10
10
|
const mocha = require('gulp-spawn-mocha');
|
|
11
|
+
const _ = require('lodash');
|
|
12
|
+
|
|
13
|
+
const { commitCheckMsg } = require('@mimik/git-hooks');
|
|
11
14
|
|
|
12
15
|
const {
|
|
13
16
|
colors,
|
|
14
17
|
exitError,
|
|
15
|
-
retrieve,
|
|
16
18
|
start2env,
|
|
17
19
|
start2shell,
|
|
20
|
+
baseUrl,
|
|
18
21
|
} = require('./lib/helpers');
|
|
19
22
|
const {
|
|
20
|
-
testStartFile,
|
|
21
|
-
exampleStartFile,
|
|
22
|
-
startFile,
|
|
23
23
|
defaultDirectory,
|
|
24
24
|
testJsonFile,
|
|
25
25
|
shellFile,
|
|
26
|
+
DUMMY_CUSTOMER_CODE,
|
|
27
|
+
LITERAL,
|
|
28
|
+
SYSTEM_NAME,
|
|
29
|
+
TEST,
|
|
30
|
+
IGNORE,
|
|
26
31
|
} = require('./lib/common');
|
|
27
32
|
const {
|
|
33
|
+
getStartParams,
|
|
28
34
|
init,
|
|
29
35
|
startSetup,
|
|
30
36
|
getAPI,
|
|
31
37
|
getAdminToken,
|
|
32
38
|
settingUpDummyServer,
|
|
39
|
+
gettingSystemCustomer,
|
|
33
40
|
settingUpServer,
|
|
34
41
|
settingUpCustomer,
|
|
35
42
|
settingUpAdminClient,
|
|
@@ -42,7 +49,6 @@ colors.setTheme({
|
|
|
42
49
|
info: ['grey', 'bold'],
|
|
43
50
|
});
|
|
44
51
|
|
|
45
|
-
const system = 'System';
|
|
46
52
|
/**
|
|
47
53
|
* @module local
|
|
48
54
|
* @example
|
|
@@ -51,7 +57,7 @@ const system = 'System';
|
|
|
51
57
|
* @description Set of function for local deployment.
|
|
52
58
|
*
|
|
53
59
|
* The following files are expected to exist:
|
|
54
|
-
* In the directory above the server root directory:
|
|
60
|
+
* In the directory above the server root directory: `mSTConfig.json`, `mIDConfig.json`, `mITConfig.json`,`sumoLog.json`, `kinesisLog.json`, ``s3Log.json`, `customerConfig.json`, 'key.json`, `locationConfig.json` are being set. If they don't exist at the launch of the script, default will be setup.
|
|
55
61
|
* - for `mSTConfig.json`:
|
|
56
62
|
* ``` javascript
|
|
57
63
|
* {
|
|
@@ -59,6 +65,7 @@ const system = 'System';
|
|
|
59
65
|
* "protocol": "protocol for the mST server, for example: `http:`, by default `http:`",
|
|
60
66
|
* "domainName": "domain name of the mST server",
|
|
61
67
|
* "port": "port for the mST server, for example: `8025`",
|
|
68
|
+
* "passphrase": "passphrase to be used to generate public private key pair, if not present mST will user regular key",
|
|
62
69
|
* "update": "switch to indicate if mST needs to be updated, default is `false`. If the address is localhost, mST will be updated"
|
|
63
70
|
* "admin": {
|
|
64
71
|
* "clientId": "id or the client in order to get an admin token for mST, for example: `12345`",
|
|
@@ -91,7 +98,7 @@ const system = 'System';
|
|
|
91
98
|
* }
|
|
92
99
|
* ```
|
|
93
100
|
* Similar properties than for mSTConfig on `domainName` and `port` apply.
|
|
94
|
-
* - for `
|
|
101
|
+
* - for `sumoLog.json`:
|
|
95
102
|
* ``` javascript
|
|
96
103
|
* {
|
|
97
104
|
* "<serverType>": {
|
|
@@ -103,10 +110,50 @@ const system = 'System';
|
|
|
103
110
|
* "code": "code for sumologic, everything after the last / in the sumologic URL"
|
|
104
111
|
* }
|
|
105
112
|
* ```
|
|
106
|
-
*
|
|
113
|
+
* - for `kinesisLog.json`:
|
|
114
|
+
* ``` javascript
|
|
115
|
+
* {
|
|
116
|
+
* "region": "region of the Kinesis implementation",
|
|
117
|
+
* "accessKeyId": "access key id of Kinesis",
|
|
118
|
+
* "secretAccessKey": "secret access key for Kinesis",
|
|
119
|
+
* "streamNameInfo": "name of the kiniesis stream for info",
|
|
120
|
+
* "streamNameError": "name of the kiniesis stream for error",
|
|
121
|
+
* "streamNameOther": "name of the kiniesis stream for all the other levels"
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
* - for `s3Log.json`:
|
|
125
|
+
* ``` javascript
|
|
126
|
+
* {
|
|
127
|
+
* "region": "region of the S3 implementation",
|
|
128
|
+
* "accessKeyId": "Access key id for S3",
|
|
129
|
+
* "secretAccessKey": "secret access key for S3",
|
|
130
|
+
* "bucketname": "name of the S3 bucket used to store the information",
|
|
131
|
+
* "maxEvents": "number of events buffered before sending to S3 (integer)",
|
|
132
|
+
* "timeout": "number of seconds before timeout to send to S3 (integer)",
|
|
133
|
+
* "maxSize": "max size in Bytes before sending to S3 (integer)"
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
* - for `key.json`:
|
|
137
|
+
* ``` javascript
|
|
138
|
+
* {
|
|
139
|
+
* "apiKey": "key to access API definition on the API provider"
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
* - for `locationConfig.json`:
|
|
143
|
+
* ``` javascript
|
|
144
|
+
* {
|
|
145
|
+
* "url": "url of the location provider"
|
|
146
|
+
* "key": "key to make request to the location provider"
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
* A property may be defined for each `serverType` involved. If the serverType does not exist the default will be picked.
|
|
107
150
|
* - for `customerConfig.json`:
|
|
108
151
|
* See `mST` `README.md` file for an example of a customer configuration. This may have to be updated to reflect the new servers.
|
|
109
|
-
* - in the `local` directory of the server root directory: two files `start.json` and `testStart.json` may exit
|
|
152
|
+
* - in the `local` directory of the server root directory: two files `start.json` and `testStart.json` may exit. `start.json` is used when `npm start` is executed, `testStart.json` is used when `npm test` is executed.
|
|
153
|
+
* If the files don't exist `exampe-start.json` is used to create `start.json` and `testStart.json`.
|
|
154
|
+
* Additionally `example-testStart.json` is used when to create `testStart.json`. The values in `example-testStart.json` take precedence over the values in `example-start.json`.
|
|
155
|
+
* The configuration of these files depends on the configuration parameters of the server. If the files
|
|
156
|
+
* The following is an example of start.json file for `mIT`:
|
|
110
157
|
* ``` javascript
|
|
111
158
|
* {
|
|
112
159
|
* "NODE_ENV": "local",
|
|
@@ -124,6 +171,7 @@ const system = 'System';
|
|
|
124
171
|
* There are reserved environement variable used by the library for configuration:
|
|
125
172
|
* - `oauthImplicitNeeded`: if the service handles user token the implicit configuration is needed
|
|
126
173
|
* - `mIDNeeded`: if the service has mID as a target
|
|
174
|
+
* - `locationNeeded`: if location translation is needed
|
|
127
175
|
* - `standAlone`: if the service need to be operated without other service. If the service has targets most likely 500 errors will be generated
|
|
128
176
|
*
|
|
129
177
|
* If SERVER_ID is not set in the start.json or testStart.json file, SERVER_ID will be assigned with a uuid.v4.
|
|
@@ -146,38 +194,21 @@ const system = 'System';
|
|
|
146
194
|
*/
|
|
147
195
|
|
|
148
196
|
const mSTInit = (confType) => {
|
|
149
|
-
|
|
150
|
-
let startConfig;
|
|
151
|
-
|
|
152
|
-
process.stdout.write(regType);
|
|
153
|
-
if (confType === 'test') {
|
|
154
|
-
const test = 'for ' + 'test '.info;
|
|
155
|
-
|
|
156
|
-
process.stdout.write(test);
|
|
157
|
-
regType += test;
|
|
158
|
-
startConfig = retrieve(regType, testStartFile, { sourceFilename: exampleStartFile, altFilename: startFile });
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
startConfig = retrieve(regType, startFile, { sourceFilename: exampleStartFile });
|
|
162
|
-
}
|
|
197
|
+
const { regType, startConfig } = getStartParams(confType);
|
|
163
198
|
const config = init(regType);
|
|
164
199
|
const start = startSetup(config, startConfig);
|
|
165
200
|
|
|
166
|
-
getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.name, config.pack.swaggerFile.version)
|
|
201
|
+
getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.swaggerFile.account, config.pack.swaggerFile.name, config.pack.swaggerFile.version, config.key.apiKey)
|
|
167
202
|
.then((apiFile) => {
|
|
168
203
|
console.log('- mST base url: ' + config.mSTBaseUrl.info);
|
|
169
204
|
console.log('- mIT base url: ' + config.MITBaseUrl.info);
|
|
170
205
|
console.log('- mST config: ' + JSON.stringify(config.mST, null, 2).info);
|
|
171
|
-
if (confType ===
|
|
172
|
-
start.CUSTOMER_NAME =
|
|
206
|
+
if (confType === TEST) {
|
|
207
|
+
start.CUSTOMER_NAME = SYSTEM_NAME;
|
|
173
208
|
start.BASE_PATH = apiFile.basePath;
|
|
174
209
|
return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
|
|
175
210
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
shell += start2shell(start);
|
|
179
|
-
shell += 'node index\n';
|
|
180
|
-
return { file: shellFile, content: shell, type: 'shell script' };
|
|
211
|
+
return { file: shellFile, content: start2shell(start), type: 'shell script' };
|
|
181
212
|
})
|
|
182
213
|
.then((response) => {
|
|
183
214
|
fs.writeFileSync(response.file, response.content);
|
|
@@ -186,58 +217,116 @@ const mSTInit = (confType) => {
|
|
|
186
217
|
.catch((err) => exitError(regType, err));
|
|
187
218
|
};
|
|
188
219
|
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
220
|
+
const mITInit = (confType) => {
|
|
221
|
+
const { regType, startConfig } = getStartParams(confType);
|
|
222
|
+
const config = init(regType, startConfig.standAlone);
|
|
223
|
+
const { mSTBaseUrl } = config;
|
|
224
|
+
const { type } = config.pack.mimik;
|
|
225
|
+
let start = startSetup(config, startConfig);
|
|
226
|
+
let authorization;
|
|
192
227
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
228
|
+
getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.swaggerFile.account, config.pack.swaggerFile.name, config.pack.swaggerFile.version, config.key.apiKey)
|
|
229
|
+
.then((apiFile) => {
|
|
230
|
+
console.log('- mST base url: ' + `${mSTBaseUrl}`.info);
|
|
231
|
+
console.log('- mIT base url: ' + config.MITBaseUrl.info);
|
|
232
|
+
if (startConfig.standAlone === 'yes') {
|
|
233
|
+
console.log('- service ' + type.info + ' is in ' + 'stand alone'.warn + ' mode');
|
|
234
|
+
start = settingUpDummyServer(type, start.SERVER_ID, null, start);
|
|
235
|
+
if (confType === TEST) {
|
|
236
|
+
start.CUSTOMER_NAME = SYSTEM_NAME;
|
|
237
|
+
start.CUSTOMER_CODE = DUMMY_CUSTOMER_CODE;
|
|
238
|
+
start.BASE_PATH = apiFile.basePath;
|
|
239
|
+
return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
|
|
240
|
+
}
|
|
241
|
+
return { file: shellFile, content: start2shell(start), type: 'shell script' };
|
|
242
|
+
}
|
|
243
|
+
return getAdminToken(
|
|
244
|
+
{ type: 'mST', audience: `${baseUrl('mST', regType, config.mST, LITERAL)}/clients/Generic-mST` },
|
|
245
|
+
{ id: config.mST.admin.clientId, secret: config.mST.admin.clientSecret },
|
|
246
|
+
mSTBaseUrl,
|
|
247
|
+
)
|
|
248
|
+
.then((mSTAdminToken) => {
|
|
249
|
+
authorization = mSTAdminToken;
|
|
250
|
+
return gettingSystemCustomer(authorization, mSTBaseUrl);
|
|
251
|
+
})
|
|
252
|
+
.then((customer) => settingUpServer(type, start.SERVER_ID, customer, authorization, mSTBaseUrl, start)
|
|
253
|
+
.then((updatedStart) => {
|
|
254
|
+
start = updatedStart;
|
|
255
|
+
return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
|
|
256
|
+
.then((adminType) => {
|
|
257
|
+
const adminAudience = _.find(adminType.audiences, (audienceItem) => audienceItem.type === type);
|
|
258
|
+
if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
|
|
259
|
+
return undefined;
|
|
260
|
+
})
|
|
261
|
+
.then((adminToken) => {
|
|
262
|
+
if (confType === TEST) {
|
|
263
|
+
start.CUSTOMER_NAME = customer.name;
|
|
264
|
+
start.CUSTOMER_CODE = customer.code;
|
|
265
|
+
start.BASE_PATH = apiFile.basePath;
|
|
266
|
+
start.MST_TOKEN = authorization;
|
|
267
|
+
start.ADMIN_TOKEN = adminToken;
|
|
268
|
+
return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
|
|
269
|
+
}
|
|
270
|
+
if (adminToken) console.log('- admin token for the service: ' + adminToken.info);
|
|
271
|
+
console.log('- mST token: ' + authorization.info);
|
|
272
|
+
return { file: shellFile, content: start2shell(start), type: 'shell script' };
|
|
273
|
+
});
|
|
274
|
+
}));
|
|
275
|
+
})
|
|
276
|
+
.then((response) => {
|
|
277
|
+
fs.writeFileSync(response.file, response.content);
|
|
278
|
+
console.log(`${regType}status: ` + 'completed'.success + ', ' + response.type.info + ' created at (' + response.file.info + ')');
|
|
279
|
+
})
|
|
280
|
+
.catch((err) => exitError(regType, err));
|
|
281
|
+
};
|
|
196
282
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
startConfig = retrieve(regType, testStartFile, { sourceFilename: exampleStartFile, altFilename: startFile });
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
startConfig = retrieve(regType, startFile, { sourceFilename: exampleStartFile });
|
|
203
|
-
}
|
|
283
|
+
const serverInit = (confType) => {
|
|
284
|
+
const { regType, startConfig } = getStartParams(confType);
|
|
204
285
|
const config = init(regType, startConfig.standAlone);
|
|
205
286
|
const { mSTBaseUrl, customer } = config;
|
|
206
|
-
const { type } = config.pack;
|
|
287
|
+
const { type } = config.pack.mimik;
|
|
207
288
|
let start = startSetup(config, startConfig);
|
|
208
289
|
let authorization;
|
|
209
290
|
|
|
210
|
-
getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.name, config.pack.swaggerFile.version)
|
|
291
|
+
getAPI(start.SWAGGER_FILE_DIRECTORY || defaultDirectory, config.pack.swaggerFile.account, config.pack.swaggerFile.name, config.pack.swaggerFile.version, config.key.apiKey)
|
|
211
292
|
.then((apiFile) => {
|
|
212
293
|
console.log('- mST base url: ' + `${mSTBaseUrl}`.info);
|
|
213
294
|
console.log('- mIT base url: ' + config.MITBaseUrl.info);
|
|
214
295
|
if (startConfig.standAlone === 'yes') {
|
|
215
296
|
console.log('- service ' + type.info + ' is in ' + 'stand alone'.warn + ' mode');
|
|
216
297
|
start = settingUpDummyServer(type, start.SERVER_ID, customer, start);
|
|
217
|
-
if (confType ===
|
|
298
|
+
if (confType === TEST) {
|
|
218
299
|
start.CUSTOMER_NAME = customer.name;
|
|
219
|
-
start.CUSTOMER_CODE =
|
|
300
|
+
start.CUSTOMER_CODE = DUMMY_CUSTOMER_CODE;
|
|
220
301
|
start.BASE_PATH = apiFile.basePath;
|
|
221
302
|
return { file: testJsonFile, content: JSON.stringify(start2env(start), null, 2), type: 'JSON file' };
|
|
222
303
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
shell += start2shell(start);
|
|
226
|
-
shell += 'node index\n';
|
|
227
|
-
return { file: shellFile, content: shell, type: 'shell script' };
|
|
304
|
+
return { file: shellFile, content: start2shell(start), type: 'shell script' };
|
|
228
305
|
}
|
|
229
|
-
return getAdminToken(
|
|
306
|
+
return getAdminToken(
|
|
307
|
+
{ type: 'mST', audience: `${baseUrl('mST', regType, config.mST, LITERAL)}/clients/Generic-mST` },
|
|
308
|
+
{ id: config.mST.admin.clientId, secret: config.mST.admin.clientSecret },
|
|
309
|
+
mSTBaseUrl,
|
|
310
|
+
)
|
|
230
311
|
.then((mSTAdminToken) => {
|
|
231
312
|
authorization = mSTAdminToken;
|
|
232
313
|
return settingUpCustomer(customer, authorization, mSTBaseUrl, config.mST.update);
|
|
233
314
|
})
|
|
234
|
-
.then(() =>
|
|
315
|
+
.then((updatedCustomer) => {
|
|
316
|
+
customer.code = updatedCustomer.code;
|
|
317
|
+
customer.config = updatedCustomer.config;
|
|
318
|
+
return settingUpServer(type, start.SERVER_ID, customer, authorization, mSTBaseUrl, start);
|
|
319
|
+
})
|
|
235
320
|
.then((updatedStart) => {
|
|
236
321
|
start = updatedStart;
|
|
237
322
|
return settingUpAdminClient(type, `admin_${customer.name}_${start.NODE_ENV}_${type}`, customer, authorization, mSTBaseUrl)
|
|
238
|
-
.then((
|
|
323
|
+
.then((adminType) => {
|
|
324
|
+
const adminAudience = _.find(adminType.audiences, (audienceItem) => audienceItem.type === type);
|
|
325
|
+
if (adminAudience) return getAdminToken(adminAudience, adminType.data, mSTBaseUrl);
|
|
326
|
+
return undefined;
|
|
327
|
+
})
|
|
239
328
|
.then((adminToken) => {
|
|
240
|
-
if (confType ===
|
|
329
|
+
if (confType === TEST) {
|
|
241
330
|
start.CUSTOMER_NAME = customer.name;
|
|
242
331
|
start.CUSTOMER_CODE = customer.code;
|
|
243
332
|
start.BASE_PATH = apiFile.basePath;
|
|
@@ -247,7 +336,7 @@ const serverInit = (confType) => {
|
|
|
247
336
|
|
|
248
337
|
if (startConfig.oauthImplicitNeeded === 'yes') {
|
|
249
338
|
return settingUpAdminClient('mID', `admin_${customer.name}_${start.NODE_ENV}_mID`, customer, start.MST_TOKEN, mSTBaseUrl)
|
|
250
|
-
.then((
|
|
339
|
+
.then((mIDAdminType) => getAdminToken(_.find(mIDAdminType.audiences, (audienceItem) => audienceItem.type === 'mID'), mIDAdminType.data, mSTBaseUrl))
|
|
251
340
|
.then((mIDAdminToken) => {
|
|
252
341
|
start.MID_TOKEN = mIDAdminToken;
|
|
253
342
|
testResponse.content = JSON.stringify(start2env(start), null, 2);
|
|
@@ -256,13 +345,9 @@ const serverInit = (confType) => {
|
|
|
256
345
|
}
|
|
257
346
|
return testResponse;
|
|
258
347
|
}
|
|
259
|
-
console.log('- admin token for the service: ' + adminToken.info);
|
|
348
|
+
if (adminToken) console.log('- admin token for the service: ' + adminToken.info);
|
|
260
349
|
console.log('- mST token: ' + authorization.info);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
shell += start2shell(start);
|
|
264
|
-
shell += 'node index\n';
|
|
265
|
-
return { file: shellFile, content: shell, type: 'shell script' };
|
|
350
|
+
return { file: shellFile, content: start2shell(start), type: 'shell script' };
|
|
266
351
|
});
|
|
267
352
|
});
|
|
268
353
|
})
|
|
@@ -293,14 +378,14 @@ const serverInit = (confType) => {
|
|
|
293
378
|
*
|
|
294
379
|
* | Filename | Description |
|
|
295
380
|
* | -------- | ----------- |
|
|
296
|
-
* | `../
|
|
381
|
+
* | `../sumoLog.json` | The sumologic endpoints and code
|
|
382
|
+
* | `../kinesisLog.json` | The Kinesis information
|
|
383
|
+
* | `../s3Log.json` | The S3 information
|
|
297
384
|
* | `../mSTConfig.json` | The config for mST
|
|
298
385
|
* | `../mITConfig.json` | The config for mIT
|
|
299
|
-
* | `../mIDConfig.json` | The config for mID
|
|
300
|
-
* | `../customerConfig.json` | The mST customer config
|
|
301
386
|
* | `./local/testStart.json` | The local configuration. If it does not exist start.json and if sart.json does not exist start-example.json will be used to create start.json
|
|
302
387
|
*/
|
|
303
|
-
const mSTTestSetup = () => mSTInit(
|
|
388
|
+
const mSTTestSetup = () => mSTInit(TEST);
|
|
304
389
|
|
|
305
390
|
/**
|
|
306
391
|
*
|
|
@@ -322,18 +407,110 @@ const mSTTestSetup = () => mSTInit('test');
|
|
|
322
407
|
*
|
|
323
408
|
* | Filename | Description |
|
|
324
409
|
* | -------- | ----------- |
|
|
325
|
-
* | `../
|
|
410
|
+
* | `../sumoLog.json` | The sumologic endpoints and code
|
|
411
|
+
* | `../kinesisLog.json` | The Kinesis information
|
|
412
|
+
* | `../s3Log.json` | The S3 information
|
|
326
413
|
* | `../mSTConfig.json` | The config for mST
|
|
327
414
|
* | `../mITConfig.json` | The config for mIT
|
|
328
|
-
* | `../mIDConfig.json` | The config for mID
|
|
329
|
-
* | `../customerConfig.json` | The mST customer config
|
|
330
415
|
* | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
|
|
331
416
|
*/
|
|
332
417
|
const mSTSetup = () => mSTInit();
|
|
333
418
|
|
|
334
419
|
/**
|
|
335
420
|
*
|
|
336
|
-
* Setup
|
|
421
|
+
* Setup mIT for test.
|
|
422
|
+
*
|
|
423
|
+
* @function testSetup
|
|
424
|
+
* @category sync
|
|
425
|
+
*
|
|
426
|
+
* @return `null`.
|
|
427
|
+
*
|
|
428
|
+
* Will exit 1 if there is an error.
|
|
429
|
+
*
|
|
430
|
+
* Two modes are available:
|
|
431
|
+
* 1. stand alone
|
|
432
|
+
* 2. with mST
|
|
433
|
+
*
|
|
434
|
+
* The environment variable STAND_ALONE will select the mode.
|
|
435
|
+
* When in stand alone, the following actions are being performed:
|
|
436
|
+
*
|
|
437
|
+
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
438
|
+
* 2. get an admin token for that service
|
|
439
|
+
* 3. generate a json object store in a file under .
|
|
440
|
+
*
|
|
441
|
+
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
|
|
442
|
+
*
|
|
443
|
+
* When mST and other servers are present, the following actions are being performed:
|
|
444
|
+
*
|
|
445
|
+
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
446
|
+
* 2. get an admin token for mST
|
|
447
|
+
* 3. register the service in mST
|
|
448
|
+
* 4. register an admin client for that service in mST
|
|
449
|
+
* 5. get an admin token for that service
|
|
450
|
+
* 6. get an admin token for mID if needed
|
|
451
|
+
* 7. generate a json object store in a file under .
|
|
452
|
+
*
|
|
453
|
+
* The following files are needed to perform these actions:
|
|
454
|
+
*
|
|
455
|
+
* | Filename | Description |
|
|
456
|
+
* | -------- | ----------- |
|
|
457
|
+
* | `../sumoLog.json` | The sumologic endpoints and code
|
|
458
|
+
* | `../kinesisLog.json` | The Kinesis information
|
|
459
|
+
* | `../s3Log.json` | The S3 information
|
|
460
|
+
* | `../mSTConfig.json` | The config for mST
|
|
461
|
+
* | `../mITConfig.json` | The config for mIT
|
|
462
|
+
* | `./local/testStart.json` | The local configuration. If it does not exist start.json and if sart.json does not exist start-example.json will be used to create start.json
|
|
463
|
+
*/
|
|
464
|
+
const mITTestSetup = () => mITInit(TEST);
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
*
|
|
468
|
+
* Setup mIT.
|
|
469
|
+
*
|
|
470
|
+
* @function setup
|
|
471
|
+
* @category sync
|
|
472
|
+
*
|
|
473
|
+
* @return `null`.
|
|
474
|
+
*
|
|
475
|
+
* Will exit 1 if there is an error.
|
|
476
|
+
*
|
|
477
|
+
* Two modes are available:
|
|
478
|
+
* 1. stand alone
|
|
479
|
+
* 2. with mST
|
|
480
|
+
*
|
|
481
|
+
* The environment variable STAND_ALONE will select the mode.
|
|
482
|
+
* When in stand alone, the following actions are being performed:
|
|
483
|
+
*
|
|
484
|
+
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
485
|
+
* 2. get an admin token for that service
|
|
486
|
+
* 3. generate a shell script to start the server
|
|
487
|
+
*
|
|
488
|
+
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
|
|
489
|
+
*
|
|
490
|
+
* When mST is present, the following actions are being performed:
|
|
491
|
+
*
|
|
492
|
+
*
|
|
493
|
+
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
494
|
+
* 2. get an Admin token for mST
|
|
495
|
+
* 3. register the service in mST
|
|
496
|
+
* 4. generate a shell script to start the server
|
|
497
|
+
*
|
|
498
|
+
* The following files are needed to perform these actions:
|
|
499
|
+
*
|
|
500
|
+
* | Filename | Description |
|
|
501
|
+
* | -------- | ----------- |
|
|
502
|
+
* | `../sumoLog.json` | The sumologic endpoints and code
|
|
503
|
+
* | `../kinesisLog.json` | The Kinesis information
|
|
504
|
+
* | `../s3Log.json` | The S3 information
|
|
505
|
+
* | `../mSTConfig.json` | The config for mST
|
|
506
|
+
* | `../mITConfig.json` | The config for mIT
|
|
507
|
+
* | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
|
|
508
|
+
*/
|
|
509
|
+
const mITSetup = () => mITInit();
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
*
|
|
513
|
+
* Setup a service (not mST, mIT) for test.
|
|
337
514
|
*
|
|
338
515
|
* @function testSetup
|
|
339
516
|
* @category sync
|
|
@@ -346,14 +523,14 @@ const mSTSetup = () => mSTInit();
|
|
|
346
523
|
* 1. stand alone
|
|
347
524
|
* 2. with mST, mID are other dependent servers
|
|
348
525
|
*
|
|
349
|
-
* The environment variable STAND_ALONE will select the
|
|
526
|
+
* The environment variable STAND_ALONE will select the mode.
|
|
350
527
|
* When in stand alone, the following actions are being performed:
|
|
351
528
|
*
|
|
352
529
|
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
353
530
|
* 2. get an admin token for that service
|
|
354
531
|
* 3. generate a json object store in a file under .
|
|
355
532
|
*
|
|
356
|
-
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most
|
|
533
|
+
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
|
|
357
534
|
*
|
|
358
535
|
* When mST and other servers are present, the following actions are being performed:
|
|
359
536
|
*
|
|
@@ -370,18 +547,20 @@ const mSTSetup = () => mSTInit();
|
|
|
370
547
|
*
|
|
371
548
|
* | Filename | Description |
|
|
372
549
|
* | -------- | ----------- |
|
|
373
|
-
* | `../
|
|
550
|
+
* | `../sumoLog.json` | The sumologic endpoints and code
|
|
551
|
+
* | `../kinesisLog.json` | The Kinesis information
|
|
552
|
+
* | `../s3Log.json` | The S3 information
|
|
374
553
|
* | `../mSTConfig.json` | The config for mST
|
|
375
554
|
* | `../mITConfig.json` | The config for mIT
|
|
376
555
|
* | `../mIDConfig.json` | The config for mID
|
|
377
556
|
* | `../customerConfig.json` | The mST customer config
|
|
378
557
|
* | `./local/testStart.json` | The local configuration. If it does not exist start.json and if sart.json does not exist start-example.json will be used to create start.json
|
|
379
558
|
*/
|
|
380
|
-
const testSetup = () => serverInit(
|
|
559
|
+
const testSetup = () => serverInit(TEST);
|
|
381
560
|
|
|
382
561
|
/**
|
|
383
562
|
*
|
|
384
|
-
* Setup a service (not mST).
|
|
563
|
+
* Setup a service (not mST, mIT).
|
|
385
564
|
*
|
|
386
565
|
* @function setup
|
|
387
566
|
* @category sync
|
|
@@ -390,7 +569,21 @@ const testSetup = () => serverInit('test');
|
|
|
390
569
|
*
|
|
391
570
|
* Will exit 1 if there is an error.
|
|
392
571
|
*
|
|
393
|
-
*
|
|
572
|
+
* Two modes are available:
|
|
573
|
+
* 1. stand alone
|
|
574
|
+
* 2. with mST, mID are other dependent servers
|
|
575
|
+
*
|
|
576
|
+
* The environment variable STAND_ALONE will select the mode.
|
|
577
|
+
* When in stand alone, the following actions are being performed:
|
|
578
|
+
*
|
|
579
|
+
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
580
|
+
* 2. get an admin token for that service
|
|
581
|
+
* 3. generate a shell script to start the server
|
|
582
|
+
*
|
|
583
|
+
* In standAlone the dependencies will not be reachable and the operation that implies reaching dependencies will most likely generate a 500 error
|
|
584
|
+
*
|
|
585
|
+
* When mST and other servers are present, the following actions are being performed:
|
|
586
|
+
*
|
|
394
587
|
*
|
|
395
588
|
* 1. retrieve the API from [swaggerhub](https://app.swaggerhub.com/search?type=API&owner=mimik)
|
|
396
589
|
* 2. get an Admin token for mST
|
|
@@ -403,32 +596,33 @@ const testSetup = () => serverInit('test');
|
|
|
403
596
|
* | Filename | Description |
|
|
404
597
|
* | -------- | ----------- |
|
|
405
598
|
* | `../sumo.json` | The sumologic endpoints and code
|
|
599
|
+
* | `../kinesisLog.json` | The Kinesis information
|
|
600
|
+
* | `../s3Log.json` | The S3 information
|
|
406
601
|
* | `../mSTConfig.json` | The config for mST
|
|
407
602
|
* | `../mITConfig.json` | The config for mIT
|
|
408
603
|
* | `../mIDConfig.json` | The config for mID
|
|
409
604
|
* | `../customerConfig.json` | The mST customer config
|
|
410
|
-
* | `./config.json` | The config of the service
|
|
411
605
|
* | `./local/start.json` | The local configuration. If it does not exist start-example.json will be used to create start.json
|
|
412
606
|
*/
|
|
413
607
|
const setup = () => serverInit();
|
|
414
608
|
|
|
415
|
-
const rootPath = (pathName) => {
|
|
609
|
+
const rootPath = (pathName, ignore) => {
|
|
416
610
|
const rootDir = path.join(__dirname, '..', '..', '..');
|
|
417
611
|
|
|
418
|
-
if (pathName)
|
|
612
|
+
if (pathName) {
|
|
613
|
+
if (ignore) return `${IGNORE}${path.join(rootDir, pathName)}`;
|
|
614
|
+
return path.join(rootDir, pathName);
|
|
615
|
+
}
|
|
616
|
+
if (ignore) return `${IGNORE}${rootDir}`;
|
|
419
617
|
return rootDir;
|
|
420
618
|
};
|
|
421
619
|
const files = [
|
|
422
|
-
rootPath('
|
|
423
|
-
rootPath('configuration/*.js'),
|
|
424
|
-
rootPath('controllers/*.js'),
|
|
425
|
-
rootPath('processors/*.js'),
|
|
426
|
-
rootPath('models/*.js'),
|
|
427
|
-
rootPath('lib/**.js'),
|
|
428
|
-
rootPath('util/**.js'),
|
|
620
|
+
rootPath('src/**/*.js'),
|
|
429
621
|
rootPath('Gulpfile.js'),
|
|
430
622
|
rootPath('local/**.js'),
|
|
431
|
-
rootPath('test
|
|
623
|
+
rootPath('test/**/*.js'),
|
|
624
|
+
rootPath('tools/**/*.js'),
|
|
625
|
+
rootPath('tools/**/{node_modules,node_modules/**}', true),
|
|
432
626
|
];
|
|
433
627
|
|
|
434
628
|
/**
|
|
@@ -463,14 +657,13 @@ const test = () => {
|
|
|
463
657
|
*/
|
|
464
658
|
const lint = () => gulp.src(files, { allowEmpty: true })
|
|
465
659
|
.pipe(eslint({}))
|
|
466
|
-
.pipe(eslint.format())
|
|
467
|
-
.pipe(eslint.failOnError());
|
|
660
|
+
.pipe(eslint.format());
|
|
468
661
|
|
|
469
662
|
const createDocs = (done) => {
|
|
470
|
-
jsdoc2md.render({ files: rootPath('configuration/config.js') })
|
|
663
|
+
jsdoc2md.render({ files: rootPath('src/configuration/config.js') })
|
|
471
664
|
.then((output) => fs.writeFileSync(rootPath('README.md'), output))
|
|
472
|
-
.catch((err) => log.error('docs creation failed:', err.message))
|
|
473
|
-
|
|
665
|
+
.catch((err) => log.error('docs creation failed:', err.message))
|
|
666
|
+
.finally(() => done());
|
|
474
667
|
};
|
|
475
668
|
|
|
476
669
|
const add = () => gulp.src(rootPath('README.md'))
|
|
@@ -487,13 +680,91 @@ const add = () => gulp.src(rootPath('README.md'))
|
|
|
487
680
|
*/
|
|
488
681
|
const docs = gulp.series(createDocs, add);
|
|
489
682
|
|
|
683
|
+
const dotFiles = () => {
|
|
684
|
+
const eslintrc = {
|
|
685
|
+
env: {
|
|
686
|
+
node: true,
|
|
687
|
+
},
|
|
688
|
+
plugins: [
|
|
689
|
+
'@mimik/document-env',
|
|
690
|
+
'@mimik/dependencies',
|
|
691
|
+
],
|
|
692
|
+
extends: 'airbnb',
|
|
693
|
+
parserOptions: {
|
|
694
|
+
ecmaVersion: 2020,
|
|
695
|
+
},
|
|
696
|
+
rules: {
|
|
697
|
+
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
|
|
698
|
+
'brace-style': [1, 'stroustrup', { allowSingleLine: true }],
|
|
699
|
+
'no-confusing-arrow': [0], // arrow isnt confusing
|
|
700
|
+
'max-len': [1, 180, { ignoreComments: true }],
|
|
701
|
+
'linebreak-style': 0,
|
|
702
|
+
quotes: [1, 'single'],
|
|
703
|
+
semi: [1, 'always'],
|
|
704
|
+
'no-process-env': ['error'],
|
|
705
|
+
'@mimik/document-env/validate-document-env': 2,
|
|
706
|
+
'@mimik/dependencies/case-sensitive': 2,
|
|
707
|
+
'@mimik/dependencies/no-cycles': 2,
|
|
708
|
+
'@mimik/dependencies/no-unresolved': 2,
|
|
709
|
+
'@mimik/dependencies/require-json-ext': 2,
|
|
710
|
+
},
|
|
711
|
+
overrides: [
|
|
712
|
+
{
|
|
713
|
+
files: [
|
|
714
|
+
'src/configuration/config.js',
|
|
715
|
+
'test/**/*.js',
|
|
716
|
+
'tools/**/*.js',
|
|
717
|
+
],
|
|
718
|
+
rules: {
|
|
719
|
+
'no-process-env': 'off',
|
|
720
|
+
},
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
files: [
|
|
724
|
+
'test/**/*.js',
|
|
725
|
+
'tools/**/*.js',
|
|
726
|
+
],
|
|
727
|
+
rules: {
|
|
728
|
+
'@mimik/document-env/validate-document-env': 'off',
|
|
729
|
+
},
|
|
730
|
+
},
|
|
731
|
+
],
|
|
732
|
+
settings: {
|
|
733
|
+
react: {
|
|
734
|
+
version: 'latest',
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
globals: {
|
|
738
|
+
module: true,
|
|
739
|
+
require: true,
|
|
740
|
+
const: false,
|
|
741
|
+
it: false,
|
|
742
|
+
describe: false,
|
|
743
|
+
before: true,
|
|
744
|
+
after: true,
|
|
745
|
+
JSON: true,
|
|
746
|
+
},
|
|
747
|
+
};
|
|
748
|
+
const nycrc = {
|
|
749
|
+
exclude: ['gulpfile.js'],
|
|
750
|
+
reporter: ['lcov', 'text'],
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
fs.writeFileSync(rootPath('.eslintrc'), JSON.stringify(eslintrc, null, 2));
|
|
754
|
+
fs.writeFileSync(rootPath('.nycrc'), JSON.stringify(nycrc, null, 2));
|
|
755
|
+
};
|
|
756
|
+
|
|
490
757
|
module.exports = {
|
|
491
758
|
mSTTestSetup,
|
|
492
759
|
mSTSetup,
|
|
760
|
+
mITTestSetup,
|
|
761
|
+
mITSetup,
|
|
493
762
|
testSetup,
|
|
494
763
|
setup,
|
|
495
764
|
test,
|
|
496
765
|
lint,
|
|
497
766
|
docs,
|
|
498
767
|
add,
|
|
768
|
+
dotFiles,
|
|
769
|
+
commitCheckMsg,
|
|
499
770
|
};
|