@mimik/local 1.6.2 → 4.4.4
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 +163 -17
- package/configuration/config.js +2 -2
- package/index.js +358 -92
- package/lib/common.js +35 -2
- package/lib/commonExt.js +29 -21
- package/lib/helpers.js +73 -20
- package/lib/rp-axios-wrapper.js +36 -0
- package/lib/tasks.js +182 -101
- 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/package.json +29 -21
- package/package.json.bak +0 -57
package/lib/tasks.js
CHANGED
|
@@ -3,17 +3,23 @@ const fs = require('fs');
|
|
|
3
3
|
const json = require('comment-json');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const Promise = require('bluebird');
|
|
6
|
-
const rp = require('request-promise');
|
|
7
6
|
const uuid = require('uuid');
|
|
8
7
|
const _ = require('lodash');
|
|
9
8
|
|
|
10
|
-
const {
|
|
9
|
+
const { rp } = require('./rp-axios-wrapper');
|
|
10
|
+
const { getAllTargets } = require('./commonExt');
|
|
11
11
|
const {
|
|
12
12
|
sumoLogFile,
|
|
13
13
|
s3LogFile,
|
|
14
14
|
kinesisLogFile,
|
|
15
|
+
locationFile,
|
|
16
|
+
keyFile,
|
|
15
17
|
packageFile,
|
|
16
18
|
customerConfigFile,
|
|
19
|
+
testStartFile,
|
|
20
|
+
exampleStartFile,
|
|
21
|
+
exampleTestStartFile,
|
|
22
|
+
startFile,
|
|
17
23
|
mSTConfigFile,
|
|
18
24
|
mITConfigFile,
|
|
19
25
|
mIDConfigFile,
|
|
@@ -26,6 +32,8 @@ const {
|
|
|
26
32
|
DEFAULT_SUMOLOG,
|
|
27
33
|
DEFAULT_S3LOG,
|
|
28
34
|
DEFAULT_KINESISLOG,
|
|
35
|
+
DEFAULT_KEY,
|
|
36
|
+
DEFAULT_LOCATION,
|
|
29
37
|
DEFAULT_MST,
|
|
30
38
|
DEFAULT_MIT,
|
|
31
39
|
DEFAULT_MID,
|
|
@@ -36,7 +44,14 @@ const {
|
|
|
36
44
|
AWS_KINESIS,
|
|
37
45
|
SUMOLOGIC,
|
|
38
46
|
ALL,
|
|
47
|
+
NONE,
|
|
39
48
|
ALL_MODES,
|
|
49
|
+
SWAGGER_SEP,
|
|
50
|
+
SYSTEM_NAME,
|
|
51
|
+
IT_REGISTRY,
|
|
52
|
+
TOKEN_SERVICE,
|
|
53
|
+
IDENTITY_SERVICE,
|
|
54
|
+
TEST,
|
|
40
55
|
} = require('./common');
|
|
41
56
|
const {
|
|
42
57
|
exitError,
|
|
@@ -45,18 +60,81 @@ const {
|
|
|
45
60
|
retrieve,
|
|
46
61
|
} = require('./helpers');
|
|
47
62
|
|
|
63
|
+
const getStartParams = (confType) => {
|
|
64
|
+
let regType = 'Local configuration setup ';
|
|
65
|
+
let startConfig;
|
|
66
|
+
|
|
67
|
+
process.stdout.write(regType);
|
|
68
|
+
if (confType === TEST) {
|
|
69
|
+
const test = 'for ' + TEST.info + ' ';
|
|
70
|
+
|
|
71
|
+
process.stdout.write(test);
|
|
72
|
+
regType += test;
|
|
73
|
+
startConfig = retrieve(regType, testStartFile, { sourceFilename: exampleStartFile, sourceFilenameSupp: exampleTestStartFile });
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
startConfig = retrieve(regType, startFile, { sourceFilename: exampleStartFile });
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
regType,
|
|
80
|
+
startConfig,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const init = (regType, standAlone, isMSTSet) => {
|
|
85
|
+
const pack = retrieve(regType, packageFile);
|
|
86
|
+
const sumoLog = retrieve(regType, sumoLogFile, { default: DEFAULT_SUMOLOG });
|
|
87
|
+
const s3Log = retrieve(regType, s3LogFile, { default: DEFAULT_S3LOG });
|
|
88
|
+
const kinesisLog = retrieve(regType, kinesisLogFile, { default: DEFAULT_KINESISLOG });
|
|
89
|
+
const locationProvider = retrieve(regType, locationFile, { default: DEFAULT_LOCATION });
|
|
90
|
+
const key = retrieve(regType, keyFile, { default: DEFAULT_KEY });
|
|
91
|
+
|
|
92
|
+
console.log('- server type is ' + pack.mimik.type.info);
|
|
93
|
+
const config = {
|
|
94
|
+
regType,
|
|
95
|
+
pack,
|
|
96
|
+
sumoLog,
|
|
97
|
+
s3Log,
|
|
98
|
+
kinesisLog,
|
|
99
|
+
locationProvider,
|
|
100
|
+
key,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (isMSTSet && pack.mimik.type !== TOKEN_SERVICE && pack.mimik.type !== IT_REGISTRY) config.customer = retrieve(regType, customerConfigFile); // we don't need customer for mST or mIT
|
|
104
|
+
if (standAlone || !isMSTSet) {
|
|
105
|
+
config.mST = DUMMY_MST;
|
|
106
|
+
console.log('- using ' + 'dummy mSTConfig'.warn);
|
|
107
|
+
config.mIT = DUMMY_MIT;
|
|
108
|
+
console.log('- using ' + 'dummy mITConfig'.warn);
|
|
109
|
+
config.mID = DUMMY_MID;
|
|
110
|
+
console.log('- using ' + 'dummy mIDConfig'.warn);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
config.mST = retrieve(regType, mSTConfigFile, { default: DEFAULT_MST });
|
|
114
|
+
config.mIT = retrieve(regType, mITConfigFile, { default: DEFAULT_MIT });
|
|
115
|
+
config.mID = retrieve(regType, mIDConfigFile, { default: DEFAULT_MID });
|
|
116
|
+
}
|
|
117
|
+
config.mSTBaseUrl = baseUrl(TOKEN_SERVICE, regType, config.mST);
|
|
118
|
+
config.MITBaseUrl = baseUrl(IT_REGISTRY, regType, config.mIT);
|
|
119
|
+
if (config.mST.domainName === 'localhost') {
|
|
120
|
+
console.log('- in ' + `${TOKEN_SERVICE} localhost, updating ${TOKEN_SERVICE} is true`.warn);
|
|
121
|
+
config.mST.update = true;
|
|
122
|
+
}
|
|
123
|
+
return config;
|
|
124
|
+
};
|
|
125
|
+
|
|
48
126
|
const startSetup = (config, origStart) => {
|
|
49
127
|
const start = _.clone(origStart);
|
|
50
128
|
const { regType } = config;
|
|
51
|
-
const { type } = config.pack;
|
|
129
|
+
const { type } = config.pack.mimik;
|
|
52
130
|
// basic check
|
|
53
131
|
if (start.standAlone === 'yes') {
|
|
54
132
|
if (start.NODE_ENV !== 'local') exitError(regType, Error('standAlone is only for local environment'));
|
|
55
|
-
if (type ===
|
|
133
|
+
if (type === TOKEN_SERVICE) exitError(regType, Error(`standAlone does not apply to ${type}`));
|
|
56
134
|
}
|
|
57
135
|
// references
|
|
58
|
-
start.MIT_URL = baseUrl(
|
|
59
|
-
start.MST_URL = baseUrl(
|
|
136
|
+
start.MIT_URL = baseUrl(IT_REGISTRY, regType, config.mIT);
|
|
137
|
+
start.MST_URL = baseUrl(TOKEN_SERVICE, regType, config.mST);
|
|
60
138
|
// logs
|
|
61
139
|
let logMode = null;
|
|
62
140
|
|
|
@@ -64,6 +142,7 @@ const startSetup = (config, origStart) => {
|
|
|
64
142
|
logMode = _.split(_.trim(start.LOG_MODE), /\s*,\s*/);
|
|
65
143
|
if (logMode.length === 0) exitError(regType, 'Invalid LOG_MODE: cannot be an empty array');
|
|
66
144
|
if (_.difference(logMode, ALL_MODES).length !== 0) exitError(regType, `Invalid items in LOG_MODE: ${logMode}`);
|
|
145
|
+
if (logMode.includes(NONE) && logMode.length !== 1) throw new Error(`Cannot have multiple modes when ${NONE} is selected`);
|
|
67
146
|
if (logMode.includes(ALL)) logMode = [SUMOLOGIC, AWS_S3]; // legacy support
|
|
68
147
|
}
|
|
69
148
|
if (!logMode || logMode.includes(SUMOLOGIC)) {
|
|
@@ -104,16 +183,16 @@ const startSetup = (config, origStart) => {
|
|
|
104
183
|
// passphrase to be shared to all the servers
|
|
105
184
|
if (config.mST.passphrase) start.PASSPHRASE = config.mST.passphrase;
|
|
106
185
|
// oauth issuer full address
|
|
107
|
-
start.OAUTH_ISSUER = `${baseUrl(
|
|
186
|
+
start.OAUTH_ISSUER = `${baseUrl(TOKEN_SERVICE, regType, config.mST, LITERAL)}/oauth/token`;
|
|
108
187
|
// setting admin
|
|
109
|
-
start.ADMIN_EXTERNAL_ID = `admin_${config.customer ? config.customer.name :
|
|
188
|
+
start.ADMIN_EXTERNAL_ID = `admin_${config.customer ? config.customer.name : SYSTEM_NAME}_${start.NODE_ENV}_${type}`;
|
|
110
189
|
// setting up dummy variables which will be updating by mST seeding
|
|
111
190
|
start.OAUTH_CLIENT_ID = '--noId--';
|
|
112
191
|
start.OAUTH_CLIENT_SECRET = '--noSecret--';
|
|
113
192
|
start.OAUTH_CLIENT_ACCESS_KEY = '--noKey--';
|
|
114
193
|
start.OAUTH_CLIENT_AUDIENCE = '--noAudience--';
|
|
115
194
|
// specific to mST
|
|
116
|
-
if (type ===
|
|
195
|
+
if (type === TOKEN_SERVICE) {
|
|
117
196
|
// use the port from config
|
|
118
197
|
start.SERVER_PORT = config.mST.port;
|
|
119
198
|
// setting admin
|
|
@@ -127,25 +206,30 @@ const startSetup = (config, origStart) => {
|
|
|
127
206
|
start.SERVER_PUBLIC_PROTOCOL = config.mST.protocol;
|
|
128
207
|
}
|
|
129
208
|
// specific to mID
|
|
130
|
-
if (type ===
|
|
209
|
+
if (type === IDENTITY_SERVICE) {
|
|
131
210
|
start.SERVER_PORT = config.mID.port;
|
|
132
211
|
// setting url
|
|
133
|
-
start.MID_URL = baseUrl(
|
|
212
|
+
start.MID_URL = baseUrl(IDENTITY_SERVICE, regType, config.mID);
|
|
134
213
|
}
|
|
135
|
-
if (type ===
|
|
214
|
+
if (type === IT_REGISTRY) {
|
|
136
215
|
start.SERVER_PORT = config.mIT.port;
|
|
137
216
|
}
|
|
138
217
|
// specific to servers that need to handle user token and mID
|
|
139
|
-
if (start.oauthImplicitNeeded === 'yes' || type ===
|
|
218
|
+
if (start.oauthImplicitNeeded === 'yes' || type === IDENTITY_SERVICE) {
|
|
140
219
|
delete start.oauthImplicitNeeded;
|
|
141
220
|
start.OAUTH_IMPLICIT_AUDIENCE = config.mID.implicit.audience;
|
|
142
221
|
start.OAUTH_IMPLICIT_KEY = config.mID.implicit.key;
|
|
143
|
-
start.OAUTH_IMPLICIT_ISSUER = `${baseUrl(
|
|
222
|
+
start.OAUTH_IMPLICIT_ISSUER = `${baseUrl(IDENTITY_SERVICE, regType, config.mID, LITERAL)}/oauth/token`;
|
|
144
223
|
}
|
|
145
224
|
// specific to servers than need to interact with mID
|
|
146
225
|
if (start.mIDNeeded === 'yes') {
|
|
147
226
|
delete start.mIDNeeded;
|
|
148
|
-
start.MID_URL = baseUrl(
|
|
227
|
+
start.MID_URL = baseUrl(IDENTITY_SERVICE, regType, config.mID);
|
|
228
|
+
}
|
|
229
|
+
if (start.locationNeeded === 'yes' && config.locationProvider.url) {
|
|
230
|
+
delete start.locationNeeded;
|
|
231
|
+
start.LOCATION_PROVIDER = config.locationProvider.url;
|
|
232
|
+
if (config.locationProvider.key) start.LOCATION_PROVIDER_KEY = config.locationProvider.key;
|
|
149
233
|
}
|
|
150
234
|
|
|
151
235
|
return start;
|
|
@@ -158,16 +242,17 @@ const startSetup = (config, origStart) => {
|
|
|
158
242
|
* @function getAPI
|
|
159
243
|
* @category async
|
|
160
244
|
* @param {PATH<string>} directory - Directory to store the API file.
|
|
161
|
-
* @param {string}
|
|
245
|
+
* @param {string} account - Account of the API API to retrieve.
|
|
246
|
+
* @param {string} type - Type of microservice associated with the API to retrieve.
|
|
162
247
|
* @param {SEMVER<string>} version - Version fo the API to retrieve.
|
|
248
|
+
* @param {string} apiKey - key to access private API.
|
|
163
249
|
* @return {Promise}.
|
|
164
250
|
* @fulfil {object} The API file itself.
|
|
165
251
|
* @throws {Promise} An error containing the reason of the failure.
|
|
166
252
|
*
|
|
167
253
|
* The directory will be created if it does not exist.
|
|
168
254
|
*/
|
|
169
|
-
const getAPI = (directory,
|
|
170
|
-
const params = name.split('_');
|
|
255
|
+
const getAPI = (directory, account, type, version, apiKey) => {
|
|
171
256
|
const fileExists = (fname) => {
|
|
172
257
|
try { fs.statSync(fname); }
|
|
173
258
|
catch (err) { return false; }
|
|
@@ -182,7 +267,7 @@ const getAPI = (directory, name, version) => {
|
|
|
182
267
|
return Promise.reject(err);
|
|
183
268
|
}
|
|
184
269
|
}
|
|
185
|
-
const filename = path.join(directory, `${
|
|
270
|
+
const filename = path.join(directory, `${account}${SWAGGER_SEP}${type}${SWAGGER_SEP}${version}${SWAGGER_SEP}${swaggerExt}`);
|
|
186
271
|
|
|
187
272
|
if (fileExists(filename)) {
|
|
188
273
|
let result;
|
|
@@ -192,67 +277,95 @@ const getAPI = (directory, name, version) => {
|
|
|
192
277
|
catch (errRead) { return Promise.reject(errRead); }
|
|
193
278
|
return Promise.resolve(result);
|
|
194
279
|
}
|
|
195
|
-
const url = `${APIProvider}/${
|
|
280
|
+
const url = `${APIProvider}/${account}/${type}/${version}`;
|
|
196
281
|
|
|
197
282
|
process.stdout.write(' at (' + `${url}`.info + '): ');
|
|
198
|
-
|
|
283
|
+
const options = {
|
|
199
284
|
method: 'GET',
|
|
200
285
|
url,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
try { fs.writeFileSync(filename, json.stringify(result, null, 2)); }
|
|
207
|
-
catch (err) {
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
if (apiKey) options.headers = { Authorization: apiKey };
|
|
289
|
+
return rp(options)
|
|
290
|
+
.catch((err) => {
|
|
208
291
|
console.log(ERR_CHECK.error);
|
|
209
292
|
throw err;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
293
|
+
})
|
|
294
|
+
.then((result) => {
|
|
295
|
+
try { fs.writeFileSync(filename, json.stringify(result, null, 2)); }
|
|
296
|
+
catch (err) {
|
|
297
|
+
console.log(ERR_CHECK.error);
|
|
298
|
+
throw err;
|
|
299
|
+
}
|
|
300
|
+
console.log(SUCCESS_CHECK.success);
|
|
301
|
+
return result;
|
|
302
|
+
});
|
|
214
303
|
};
|
|
215
304
|
|
|
216
|
-
const
|
|
217
|
-
process.stdout.write('-
|
|
305
|
+
const gettingSystemCustomer = (authorization, mSTbaseUrl) => {
|
|
306
|
+
process.stdout.write('- getting customer (' + SYSTEM_NAME.info + '): ');
|
|
218
307
|
return rp({
|
|
219
|
-
method: '
|
|
308
|
+
method: 'GET',
|
|
220
309
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
221
|
-
url: `${mSTbaseUrl}/customers`,
|
|
222
|
-
json: customer,
|
|
310
|
+
url: `${mSTbaseUrl}/customers/${SYSTEM_NAME}`,
|
|
223
311
|
})
|
|
224
|
-
.then((
|
|
312
|
+
.then((responseGET) => {
|
|
225
313
|
console.log(SUCCESS_CHECK.success);
|
|
226
|
-
return
|
|
314
|
+
return responseGET.data;
|
|
227
315
|
})
|
|
228
316
|
.catch((err) => {
|
|
229
|
-
|
|
317
|
+
console.log(ERR_CHECK.error);
|
|
318
|
+
throw err;
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const settingUpCustomer = (customer, authorization, mSTbaseUrl, update) => {
|
|
323
|
+
process.stdout.write('- setting up customer (' + `${customer.name}`.info + '): ');
|
|
324
|
+
|
|
325
|
+
let isNewCustomer;
|
|
326
|
+
|
|
327
|
+
return rp({
|
|
328
|
+
method: 'GET',
|
|
329
|
+
headers: { authorization, 'x-correlation-id': correlationId },
|
|
330
|
+
url: `${mSTbaseUrl}/customers/${customer.name}`,
|
|
331
|
+
})
|
|
332
|
+
.catch((err) => {
|
|
333
|
+
if (err.statusCode !== 404) {
|
|
230
334
|
console.log(ERR_CHECK.error);
|
|
231
335
|
throw err;
|
|
232
336
|
}
|
|
337
|
+
|
|
338
|
+
isNewCustomer = true;
|
|
339
|
+
console.log('creating new customer'.info);
|
|
340
|
+
return rp({
|
|
341
|
+
method: 'POST',
|
|
342
|
+
headers: { authorization, 'x-correlation-id': correlationId },
|
|
343
|
+
url: `${mSTbaseUrl}/customers`,
|
|
344
|
+
data: customer,
|
|
345
|
+
})
|
|
346
|
+
.catch((error) => {
|
|
347
|
+
console.log(ERR_CHECK.error);
|
|
348
|
+
throw error;
|
|
349
|
+
});
|
|
350
|
+
})
|
|
351
|
+
.then((response) => {
|
|
352
|
+
if (isNewCustomer) return response.data;
|
|
353
|
+
|
|
233
354
|
if (!update) {
|
|
234
|
-
console.log('already setup and update is false in mSTConfig.json, not updating'.
|
|
235
|
-
return
|
|
236
|
-
method: 'GET',
|
|
237
|
-
headers: { authorization, 'x-correlation-id': correlationId },
|
|
238
|
-
url: `${mSTbaseUrl}/customers/${customer.name}`,
|
|
239
|
-
})
|
|
240
|
-
.then((responseGET) => responseGET.data.code)
|
|
241
|
-
.catch((errGET) => {
|
|
242
|
-
console.log(ERR_CHECK.error);
|
|
243
|
-
throw errGET;
|
|
244
|
-
});
|
|
355
|
+
console.log('already setup and update is false in mSTConfig.json, not updating'.info);
|
|
356
|
+
return response.data;
|
|
245
357
|
}
|
|
246
|
-
|
|
358
|
+
|
|
359
|
+
console.log('already setup and update is true in mSTConfig.json, updating'.info);
|
|
247
360
|
return rp({
|
|
248
361
|
method: 'PUT',
|
|
249
362
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
250
363
|
url: `${mSTbaseUrl}/customers/${customer.name}`,
|
|
251
|
-
|
|
364
|
+
data: customer,
|
|
252
365
|
})
|
|
253
366
|
.then((responsePUT) => {
|
|
254
367
|
console.log(SUCCESS_CHECK.success);
|
|
255
|
-
return responsePUT.data
|
|
368
|
+
return responsePUT.data;
|
|
256
369
|
})
|
|
257
370
|
.catch((errPUT) => {
|
|
258
371
|
console.log(ERR_CHECK.error);
|
|
@@ -267,7 +380,7 @@ const settingUpServer = (serverType, serverId, customer, authorization, mSTbaseU
|
|
|
267
380
|
method: 'POST',
|
|
268
381
|
url: `${mSTbaseUrl}/clients`,
|
|
269
382
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
270
|
-
|
|
383
|
+
data: {
|
|
271
384
|
externalId: serverId,
|
|
272
385
|
type: serverType,
|
|
273
386
|
customerName: customer.name,
|
|
@@ -306,51 +419,18 @@ const settingUpDummyServer = (serverType, serverId, customer, origStart) => {
|
|
|
306
419
|
|
|
307
420
|
updatedStart.OAUTH_GENERIC_KEY = 'a-secret-key-for-generic';
|
|
308
421
|
updatedStart.OAUTH_GENERIC_AUDIENCE = `http://dummy-${serverType}-generic-audience`;
|
|
309
|
-
|
|
310
|
-
updatedStart[`${
|
|
311
|
-
updatedStart[`${
|
|
312
|
-
});
|
|
313
|
-
console.log(SUCCESS_CHECK.success);
|
|
314
|
-
return updatedStart;
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
const init = (regType, standAlone) => {
|
|
318
|
-
const pack = retrieve(regType, packageFile);
|
|
319
|
-
const sumoLog = retrieve(regType, sumoLogFile, { default: DEFAULT_SUMOLOG });
|
|
320
|
-
const s3Log = retrieve(regType, s3LogFile, { default: DEFAULT_S3LOG });
|
|
321
|
-
const kinesisLog = retrieve(regType, kinesisLogFile, { default: DEFAULT_KINESISLOG });
|
|
322
|
-
|
|
323
|
-
console.log('- server type is ' + pack.type.info);
|
|
324
|
-
const config = {
|
|
325
|
-
regType,
|
|
326
|
-
pack,
|
|
327
|
-
sumoLog,
|
|
328
|
-
s3Log,
|
|
329
|
-
kinesisLog,
|
|
330
|
-
};
|
|
331
|
-
if (pack.type !== 'mST') config.customer = retrieve(regType, customerConfigFile); // we don't need customer for mST
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (standAlone === 'yes') {
|
|
335
|
-
config.mST = DUMMY_MST;
|
|
336
|
-
console.log('- using ' + 'dummy mSTConfig'.warn);
|
|
337
|
-
config.mIT = DUMMY_MIT;
|
|
338
|
-
console.log('- using ' + 'dummy mITConfig'.warn);
|
|
339
|
-
config.mID = DUMMY_MID;
|
|
340
|
-
console.log('- using ' + 'dummy mIDConfig'.warn);
|
|
422
|
+
if (!customer) { // mIT case
|
|
423
|
+
updatedStart[`${serverType.toUpperCase()}_URL`] = `http://dummy-${serverType}/dummy`;
|
|
424
|
+
updatedStart[`${serverType.toUpperCase()}_AUDIENCE`] = `http://dummy-${serverType}-audience`;
|
|
341
425
|
}
|
|
342
426
|
else {
|
|
343
|
-
config.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
config.mSTBaseUrl = baseUrl('mST', regType, config.mST);
|
|
348
|
-
config.MITBaseUrl = baseUrl('mIT', regType, config.mIT);
|
|
349
|
-
if (config.mST.domainName === 'localhost') {
|
|
350
|
-
console.log('- in ' + 'mST localhost, updating mST is true'.warn);
|
|
351
|
-
config.mST.update = true;
|
|
427
|
+
getAllTargets(serverType, customer.config).forEach((target) => {
|
|
428
|
+
updatedStart[`${target.type.toUpperCase()}_URL`] = `http://dummy-${target.type}/dummy`;
|
|
429
|
+
updatedStart[`${target.type.toUpperCase()}_AUDIENCE`] = `http://dummy-${target.type}-audience`;
|
|
430
|
+
});
|
|
352
431
|
}
|
|
353
|
-
|
|
432
|
+
console.log(SUCCESS_CHECK.success);
|
|
433
|
+
return updatedStart;
|
|
354
434
|
};
|
|
355
435
|
|
|
356
436
|
const settingUpAdminClient = (serverType, adminExternalId, customer, authorization, mSTbaseUrl) => {
|
|
@@ -359,7 +439,7 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
|
|
|
359
439
|
method: 'POST',
|
|
360
440
|
url: `${mSTbaseUrl}/clients`,
|
|
361
441
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
362
|
-
|
|
442
|
+
data: {
|
|
363
443
|
externalId: adminExternalId,
|
|
364
444
|
type: 'admin',
|
|
365
445
|
customerName: customer.name,
|
|
@@ -376,7 +456,6 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
|
|
|
376
456
|
method: 'GET',
|
|
377
457
|
url: `${mSTbaseUrl}/clients/${adminExternalId}`,
|
|
378
458
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
379
|
-
json: true,
|
|
380
459
|
}).catch((errGET) => {
|
|
381
460
|
console.log(ERR_CHECK.error);
|
|
382
461
|
throw errGET;
|
|
@@ -401,7 +480,7 @@ const getAdminToken = (audienceType, admin, mSTbaseUrl) => {
|
|
|
401
480
|
method: 'POST',
|
|
402
481
|
headers: { 'x-correlation-id': correlationId },
|
|
403
482
|
url: `${mSTbaseUrl}/oauth/token`,
|
|
404
|
-
|
|
483
|
+
data: {
|
|
405
484
|
client_id: admin.id,
|
|
406
485
|
client_secret: admin.secret,
|
|
407
486
|
audience: `${audienceType.audience.split('Generic-')[0]}Generic-${audienceType.type}`,
|
|
@@ -417,12 +496,14 @@ const getAdminToken = (audienceType, admin, mSTbaseUrl) => {
|
|
|
417
496
|
};
|
|
418
497
|
|
|
419
498
|
module.exports = {
|
|
499
|
+
getStartParams,
|
|
500
|
+
init,
|
|
420
501
|
startSetup,
|
|
421
502
|
getAPI,
|
|
503
|
+
gettingSystemCustomer,
|
|
422
504
|
settingUpCustomer,
|
|
423
505
|
settingUpServer,
|
|
424
506
|
settingUpDummyServer,
|
|
425
|
-
init,
|
|
426
507
|
settingUpAdminClient,
|
|
427
508
|
getAdminToken,
|
|
428
509
|
};
|
package/manual-test/getAPI.js
CHANGED
package/manual-test/retrieve.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { retrieve }= require('../lib/helpers');
|
|
2
2
|
|
|
3
|
-
console.log(
|
|
3
|
+
// console.log(retrieve('test', 'test.json', { sourceFilename: './start-example.json', sourceFilenameSupp: 'startTest-example.json' } ));
|
|
4
4
|
|
|
5
|
-
// console.log(
|
|
5
|
+
// console.log(retrieve('test', 'test.json'));
|
|
6
|
+
// console.log(retrieve('test', 'test.json', { sourceFilename: './nonexistent.json', sourceFilenameSupp: 'startTest-example.json' }));
|
|
7
|
+
console.log(retrieve('test', 'test.json', { sourceFilename: './start-example.json' } ));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
// "SERVER_ID": "mST-12345",
|
|
3
|
+
// "DEBUG": "swagger-tools:middleware.*",
|
|
4
|
+
// -- logs
|
|
5
|
+
"LOG_LEVEL": "info",
|
|
6
|
+
"CONSOLE_LEVEL": "debug",
|
|
7
|
+
"NO_STACK": "yes",
|
|
8
|
+
// "LOG_MODE": "all",
|
|
9
|
+
// "LOG_MODE": "awsS3",
|
|
10
|
+
"LOG_MODE": "sumologic",
|
|
11
|
+
// -- providers
|
|
12
|
+
// "LOCATION_PROVIDER": "http://ip-api.com/json",
|
|
13
|
+
// "LOCATION_PROVIDER_KEY": "---a key---",
|
|
14
|
+
// "CLOUD_PROVIDER": "AWS",
|
|
15
|
+
// -- server public address
|
|
16
|
+
// "SERVER_PUBLIC_DOMAIN_NAME": "mst.mimik360.com",
|
|
17
|
+
// "SERVER_PUBLIC_PROTOCOL": "https:",
|
|
18
|
+
// -- database
|
|
19
|
+
"DATABASE_NAME": "tokens",
|
|
20
|
+
"MONGO_MAX_POOL_SIZE": 60,
|
|
21
|
+
// "MONGO_REPLICAT_SET": "test",
|
|
22
|
+
// "DATABASE_IP": "localhost:27018,localhost:27019,localhost:27020",
|
|
23
|
+
// -- specific parameters
|
|
24
|
+
"OAUTH_ACCESS_TOKEN_EXPIRE": "24h",
|
|
25
|
+
"OAUTH_REFRESH_TOKEN_EXPIRE": "30d",
|
|
26
|
+
// "PASSPHRASE": "This is a passphrase",
|
|
27
|
+
// "MST_STANDALONE_SET": "off"
|
|
28
|
+
// "SUB_MST_SET": "off"
|
|
29
|
+
// information retriveved from super mST client registration
|
|
30
|
+
// "OAUTH_SUB_CLIENT_ID": "a sub client id",
|
|
31
|
+
// "OAUTH_SUB_CLIENT_SECRET": "a sub client secret",
|
|
32
|
+
// "OAUTH_SUB_CLIENT_ACCESS_KEY": "a sub client access key",
|
|
33
|
+
// "OAUTH_SUB_CLIENT_AUDIENCE": "a sub client audience",
|
|
34
|
+
// "OAUTH_SUB_ISSUER": "sub client token issuer",
|
|
35
|
+
// "OAUTH_SUB_GENERIC_KEY": "a sub client generic key",
|
|
36
|
+
// "OAUTH_SUB_GENERIC_AUDIENCE": "a sub client geneic audience",
|
|
37
|
+
// "SUPER_MST_AUDIENCE": "the super mST audience ",
|
|
38
|
+
// "SUB_MST_AUDIENCE": "the sub mST audience",
|
|
39
|
+
// information to be provided
|
|
40
|
+
// "SUPER_MST_URL": "url of super mST",
|
|
41
|
+
// -- security
|
|
42
|
+
// "SERVER_SECURITY_SET": "off",
|
|
43
|
+
// -- environment
|
|
44
|
+
// "REGISTRATION_RETRY": 200000,
|
|
45
|
+
"NODE_ENV": "local"
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
// "SERVER_ID": "mST-12345",
|
|
3
|
+
// "DEBUG": "swagger-tools:middleware.*",
|
|
4
|
+
// -- logs
|
|
5
|
+
"LOG_LEVEL": "info",
|
|
6
|
+
"CONSOLE_LEVEL": "debug",
|
|
7
|
+
"NO_STACK": "yes",
|
|
8
|
+
// "LOG_MODE": "all",
|
|
9
|
+
// "LOG_MODE": "awsS3",
|
|
10
|
+
"LOG_MODE": "sumologic",
|
|
11
|
+
// -- providers
|
|
12
|
+
// "LOCATION_PROVIDER": "http://ip-api.com/json",
|
|
13
|
+
// "LOCATION_PROVIDER_KEY": "---a key---",
|
|
14
|
+
// "CLOUD_PROVIDER": "AWS",
|
|
15
|
+
// -- server public address
|
|
16
|
+
// "SERVER_PUBLIC_DOMAIN_NAME": "mst.mimik360.com",
|
|
17
|
+
// "SERVER_PUBLIC_PROTOCOL": "https:",
|
|
18
|
+
// -- database
|
|
19
|
+
"DATABASE_NAME": "tokens",
|
|
20
|
+
"MONGO_MAX_POOL_SIZE": 60,
|
|
21
|
+
// "MONGO_REPLICAT_SET": "test",
|
|
22
|
+
// "DATABASE_IP": "localhost:27018,localhost:27019,localhost:27020",
|
|
23
|
+
// -- specific parameters
|
|
24
|
+
"OAUTH_ACCESS_TOKEN_EXPIRE": "24h",
|
|
25
|
+
"OAUTH_REFRESH_TOKEN_EXPIRE": "30d",
|
|
26
|
+
// "PASSPHRASE": "This is a passphrase",
|
|
27
|
+
// "MST_STANDALONE_SET": "off"
|
|
28
|
+
// "SUB_MST_SET": "off"
|
|
29
|
+
// information retriveved from super mST client registration
|
|
30
|
+
// "OAUTH_SUB_CLIENT_ID": "a sub client id",
|
|
31
|
+
// "OAUTH_SUB_CLIENT_SECRET": "a sub client secret",
|
|
32
|
+
// "OAUTH_SUB_CLIENT_ACCESS_KEY": "a sub client access key",
|
|
33
|
+
// "OAUTH_SUB_CLIENT_AUDIENCE": "a sub client audience",
|
|
34
|
+
// "OAUTH_SUB_ISSUER": "sub client token issuer",
|
|
35
|
+
// "OAUTH_SUB_GENERIC_KEY": "a sub client generic key",
|
|
36
|
+
// "OAUTH_SUB_GENERIC_AUDIENCE": "a sub client geneic audience",
|
|
37
|
+
// "SUPER_MST_AUDIENCE": "the super mST audience ",
|
|
38
|
+
// "SUB_MST_AUDIENCE": "the sub mST audience",
|
|
39
|
+
// information to be provided
|
|
40
|
+
// "SUPER_MST_URL": "url of super mST",
|
|
41
|
+
// -- security
|
|
42
|
+
// "SERVER_SECURITY_SET": "off",
|
|
43
|
+
// -- environment
|
|
44
|
+
// "REGISTRATION_RETRY": 200000,
|
|
45
|
+
"NODE_ENV": "local"
|
|
46
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const colors = require('colors');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const json = require('comment-json');
|
|
4
|
+
|
|
5
|
+
colors.setTheme({
|
|
6
|
+
success: 'green',
|
|
7
|
+
warn: 'yellow',
|
|
8
|
+
error: 'red',
|
|
9
|
+
info: ['grey', 'bold'],
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const exitError = (regType, error, filename) => {
|
|
13
|
+
let details = `{ statusCode: ${error.statusCode || 500}, message: ${error.message || error}`;
|
|
14
|
+
|
|
15
|
+
if (filename) details = `, ${details}, filename: ${filename}`;
|
|
16
|
+
details = `${details} }`;
|
|
17
|
+
console.error(`${regType}status: ` + 'error'.error + ', ' + details.info);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const regType = 'test';
|
|
22
|
+
|
|
23
|
+
const readMerge = (fname, fnameSupp) => {
|
|
24
|
+
const parse = (rawFile, rawFilename) => {
|
|
25
|
+
try { return json.parse(rawFile); }
|
|
26
|
+
catch (errParse) { exitError(regType, errParse, rawFilename); }
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const merge = (origRawFile, parsedFile, origRawFileSupp, parsedFileSupp) => {
|
|
30
|
+
const keysParsedFile = Object.keys(parsedFile);
|
|
31
|
+
let rawFile = origRawFile;
|
|
32
|
+
let rawFileSupp = origRawFileSupp;
|
|
33
|
+
|
|
34
|
+
Object.keys(parsedFileSupp).forEach((key) => {
|
|
35
|
+
if (keysParsedFile.includes(key)) {
|
|
36
|
+
const regex = new RegExp(`\n[ \t]+"${key}"`);
|
|
37
|
+
|
|
38
|
+
rawFile = rawFile.replace(regex, `\n// "${key}"`)
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
rawFile = rawFile.substring(0, rawFile.length - 2);
|
|
42
|
+
rawFileSupp = rawFileSupp.substring(1);
|
|
43
|
+
return `${rawFile},\n//-- test\n${rawFileSupp}`;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
let readFileRaw;
|
|
47
|
+
let readFileSuppRaw;
|
|
48
|
+
|
|
49
|
+
try { readFileRaw = fs.readFileSync(fname).toString(); }
|
|
50
|
+
catch (errFname) {
|
|
51
|
+
if (errFname.code !== 'ENOENT') exitError(regType, errFname, fname);
|
|
52
|
+
throw errFname;
|
|
53
|
+
}
|
|
54
|
+
const readFile = parse(readFileRaw, fname);
|
|
55
|
+
|
|
56
|
+
try { readFileSuppRaw = fs.readFileSync(fnameSupp).toString(); }
|
|
57
|
+
catch (errFnameSupp) {
|
|
58
|
+
if (errFnameSupp.code !== 'ENOENT') exitError(regType, errFnameSupp, fnameSupp);
|
|
59
|
+
return readFile;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return parse(merge(readFileRaw, readFile, readFileSuppRaw, parse(readFileSuppRaw, fnameSupp)), `${fname} + ${fnameSupp}`);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
console.log(json.stringify(readMerge('../../../mst-2297/local/start-example.json', '../../../mst-2297/local/startTest-example.json'), null, 2))
|