@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/lib/tasks.js
CHANGED
|
@@ -3,16 +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
|
+
kinesisLogFile,
|
|
15
|
+
locationFile,
|
|
16
|
+
keyFile,
|
|
14
17
|
packageFile,
|
|
15
18
|
customerConfigFile,
|
|
19
|
+
testStartFile,
|
|
20
|
+
exampleStartFile,
|
|
21
|
+
exampleTestStartFile,
|
|
22
|
+
startFile,
|
|
16
23
|
mSTConfigFile,
|
|
17
24
|
mITConfigFile,
|
|
18
25
|
mIDConfigFile,
|
|
@@ -21,8 +28,12 @@ const {
|
|
|
21
28
|
swaggerExt,
|
|
22
29
|
APIProvider,
|
|
23
30
|
correlationId,
|
|
31
|
+
LITERAL,
|
|
24
32
|
DEFAULT_SUMOLOG,
|
|
25
33
|
DEFAULT_S3LOG,
|
|
34
|
+
DEFAULT_KINESISLOG,
|
|
35
|
+
DEFAULT_KEY,
|
|
36
|
+
DEFAULT_LOCATION,
|
|
26
37
|
DEFAULT_MST,
|
|
27
38
|
DEFAULT_MIT,
|
|
28
39
|
DEFAULT_MID,
|
|
@@ -30,29 +41,111 @@ const {
|
|
|
30
41
|
DUMMY_MIT,
|
|
31
42
|
DUMMY_MID,
|
|
32
43
|
AWS_S3,
|
|
44
|
+
AWS_KINESIS,
|
|
33
45
|
SUMOLOGIC,
|
|
34
46
|
ALL,
|
|
47
|
+
NONE,
|
|
48
|
+
ALL_MODES,
|
|
49
|
+
SWAGGER_SEP,
|
|
50
|
+
SYSTEM_NAME,
|
|
51
|
+
IT_REGISTRY,
|
|
52
|
+
TOKEN_SERVICE,
|
|
53
|
+
IDENTITY_SERVICE,
|
|
54
|
+
TEST,
|
|
35
55
|
} = require('./common');
|
|
36
56
|
const {
|
|
37
57
|
exitError,
|
|
58
|
+
setDomainName,
|
|
38
59
|
baseUrl,
|
|
39
60
|
retrieve,
|
|
40
61
|
} = require('./helpers');
|
|
41
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) => {
|
|
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 (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 === 'yes') {
|
|
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
|
+
|
|
42
126
|
const startSetup = (config, origStart) => {
|
|
43
127
|
const start = _.clone(origStart);
|
|
44
128
|
const { regType } = config;
|
|
45
|
-
const { type } = config.pack;
|
|
129
|
+
const { type } = config.pack.mimik;
|
|
46
130
|
// basic check
|
|
47
131
|
if (start.standAlone === 'yes') {
|
|
48
132
|
if (start.NODE_ENV !== 'local') exitError(regType, Error('standAlone is only for local environment'));
|
|
49
|
-
if (type ===
|
|
133
|
+
if (type === TOKEN_SERVICE) exitError(regType, Error(`standAlone does not apply to ${type}`));
|
|
50
134
|
}
|
|
51
135
|
// references
|
|
52
|
-
start.MIT_URL = baseUrl(
|
|
53
|
-
start.MST_URL = baseUrl(
|
|
136
|
+
start.MIT_URL = baseUrl(IT_REGISTRY, regType, config.mIT);
|
|
137
|
+
start.MST_URL = baseUrl(TOKEN_SERVICE, regType, config.mST);
|
|
54
138
|
// logs
|
|
55
|
-
|
|
139
|
+
let logMode = null;
|
|
140
|
+
|
|
141
|
+
if (start.LOG_MODE) {
|
|
142
|
+
logMode = _.split(_.trim(start.LOG_MODE), /\s*,\s*/);
|
|
143
|
+
if (logMode.length === 0) exitError(regType, 'Invalid LOG_MODE: cannot be an empty array');
|
|
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`);
|
|
146
|
+
if (logMode.includes(ALL)) logMode = [SUMOLOGIC, AWS_S3]; // legacy support
|
|
147
|
+
}
|
|
148
|
+
if (!logMode || logMode.includes(SUMOLOGIC)) {
|
|
56
149
|
let sumoLog = config.sumoLog[type];
|
|
57
150
|
|
|
58
151
|
if (!sumoLog) {
|
|
@@ -63,7 +156,7 @@ const startSetup = (config, origStart) => {
|
|
|
63
156
|
start.SUMO_LOGIC_ENDPOINT = start.SUMO_LOGIC_ENDPOINT || sumoLog.url;
|
|
64
157
|
start.SUMO_LOGIC_COLLECTOR_CODE = start.SUMO_LOGIC_COLLECTOR_CODE || sumoLog.code;
|
|
65
158
|
}
|
|
66
|
-
if (
|
|
159
|
+
if (logMode && logMode.includes(AWS_S3)) {
|
|
67
160
|
const { s3Log } = config;
|
|
68
161
|
|
|
69
162
|
start.S3_AWS_ACCESS_KEY_ID = start.S3_AWS_ACCESS_KEY_ID || s3Log.accessKeyId;
|
|
@@ -74,20 +167,32 @@ const startSetup = (config, origStart) => {
|
|
|
74
167
|
start.S3_AWS_TIMEOUT = start.S3_AWS_TIMEOUT || s3Log.timeout;
|
|
75
168
|
start.S3_AWS_MAX_SIZE = start.S3_AWS_MAX_SIZE || s3Log.maxSize;
|
|
76
169
|
}
|
|
170
|
+
if (logMode && logMode.includes(AWS_KINESIS)) {
|
|
171
|
+
const { kinesisLog } = config;
|
|
172
|
+
|
|
173
|
+
start.KINESIS_AWS_ACCESS_KEY_ID = start.KINESIS_AWS_ACCESS_KEY_ID || kinesisLog.accessKeyId;
|
|
174
|
+
start.KINESIS_AWS_REGION = start.KINESIS_AWS_REGION || kinesisLog.region;
|
|
175
|
+
start.KINESIS_AWS_SECRET_ACCESS_KEY = start.KINESIS_AWS_SECRET_ACCESS_KEY || kinesisLog.secretAccessKey;
|
|
176
|
+
start.KINESIS_AWS_STREAM_NAME_INFO = start.KINESIS_AWS_STREAM_NAME_INFO || kinesisLog.streamNameInfo;
|
|
177
|
+
start.KINESIS_AWS_STREAM_NAME_ERROR = start.KINESIS_AWS_STREAM_NAME_ERROR || kinesisLog.streamNameError;
|
|
178
|
+
start.KINESIS_AWS_STREAM_NAME_OTHER = start.KINESIS_AWS_STREAM_NAME_OTHER || kinesisLog.streamNameOther;
|
|
179
|
+
}
|
|
77
180
|
// server basics
|
|
78
181
|
start.SERVER_TYPE = type;
|
|
79
182
|
start.SERVER_ID = start.SERVER_ID || uuid.v4();
|
|
183
|
+
// passphrase to be shared to all the servers
|
|
184
|
+
if (config.mST.passphrase) start.PASSPHRASE = config.mST.passphrase;
|
|
80
185
|
// oauth issuer full address
|
|
81
|
-
start.OAUTH_ISSUER = `${baseUrl(
|
|
186
|
+
start.OAUTH_ISSUER = `${baseUrl(TOKEN_SERVICE, regType, config.mST, LITERAL)}/oauth/token`;
|
|
82
187
|
// setting admin
|
|
83
|
-
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}`;
|
|
84
189
|
// setting up dummy variables which will be updating by mST seeding
|
|
85
190
|
start.OAUTH_CLIENT_ID = '--noId--';
|
|
86
191
|
start.OAUTH_CLIENT_SECRET = '--noSecret--';
|
|
87
192
|
start.OAUTH_CLIENT_ACCESS_KEY = '--noKey--';
|
|
88
193
|
start.OAUTH_CLIENT_AUDIENCE = '--noAudience--';
|
|
89
194
|
// specific to mST
|
|
90
|
-
if (type ===
|
|
195
|
+
if (type === TOKEN_SERVICE) {
|
|
91
196
|
// use the port from config
|
|
92
197
|
start.SERVER_PORT = config.mST.port;
|
|
93
198
|
// setting admin
|
|
@@ -96,27 +201,35 @@ const startSetup = (config, origStart) => {
|
|
|
96
201
|
// default audience
|
|
97
202
|
start.MIT_AUDIENCE = '--noAudience--';
|
|
98
203
|
start.MST_AUDIENCE = '--noAudience--';
|
|
204
|
+
// setting public address for platform independence
|
|
205
|
+
start.SERVER_PUBLIC_DOMAIN_NAME = setDomainName(type, regType, config.mST.domainName, config.mST.port, LITERAL);
|
|
206
|
+
start.SERVER_PUBLIC_PROTOCOL = config.mST.protocol;
|
|
99
207
|
}
|
|
100
208
|
// specific to mID
|
|
101
|
-
if (type ===
|
|
209
|
+
if (type === IDENTITY_SERVICE) {
|
|
102
210
|
start.SERVER_PORT = config.mID.port;
|
|
103
211
|
// setting url
|
|
104
|
-
start.MID_URL = baseUrl(
|
|
212
|
+
start.MID_URL = baseUrl(IDENTITY_SERVICE, regType, config.mID);
|
|
105
213
|
}
|
|
106
|
-
if (type ===
|
|
214
|
+
if (type === IT_REGISTRY) {
|
|
107
215
|
start.SERVER_PORT = config.mIT.port;
|
|
108
216
|
}
|
|
109
217
|
// specific to servers that need to handle user token and mID
|
|
110
|
-
if (start.oauthImplicitNeeded === 'yes' || type ===
|
|
218
|
+
if (start.oauthImplicitNeeded === 'yes' || type === IDENTITY_SERVICE) {
|
|
111
219
|
delete start.oauthImplicitNeeded;
|
|
112
220
|
start.OAUTH_IMPLICIT_AUDIENCE = config.mID.implicit.audience;
|
|
113
221
|
start.OAUTH_IMPLICIT_KEY = config.mID.implicit.key;
|
|
114
|
-
start.OAUTH_IMPLICIT_ISSUER = `${baseUrl(
|
|
222
|
+
start.OAUTH_IMPLICIT_ISSUER = `${baseUrl(IDENTITY_SERVICE, regType, config.mID, LITERAL)}/oauth/token`;
|
|
115
223
|
}
|
|
116
224
|
// specific to servers than need to interact with mID
|
|
117
225
|
if (start.mIDNeeded === 'yes') {
|
|
118
226
|
delete start.mIDNeeded;
|
|
119
|
-
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;
|
|
120
233
|
}
|
|
121
234
|
|
|
122
235
|
return start;
|
|
@@ -129,16 +242,17 @@ const startSetup = (config, origStart) => {
|
|
|
129
242
|
* @function getAPI
|
|
130
243
|
* @category async
|
|
131
244
|
* @param {PATH<string>} directory - Directory to store the API file.
|
|
132
|
-
* @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.
|
|
133
247
|
* @param {SEMVER<string>} version - Version fo the API to retrieve.
|
|
248
|
+
* @param {string} apiKey - key to access private API.
|
|
134
249
|
* @return {Promise}.
|
|
135
250
|
* @fulfil {object} The API file itself.
|
|
136
251
|
* @throws {Promise} An error containing the reason of the failure.
|
|
137
252
|
*
|
|
138
253
|
* The directory will be created if it does not exist.
|
|
139
254
|
*/
|
|
140
|
-
const getAPI = (directory,
|
|
141
|
-
const params = name.split('_');
|
|
255
|
+
const getAPI = (directory, account, type, version, apiKey) => {
|
|
142
256
|
const fileExists = (fname) => {
|
|
143
257
|
try { fs.statSync(fname); }
|
|
144
258
|
catch (err) { return false; }
|
|
@@ -153,7 +267,7 @@ const getAPI = (directory, name, version) => {
|
|
|
153
267
|
return Promise.reject(err);
|
|
154
268
|
}
|
|
155
269
|
}
|
|
156
|
-
const filename = path.join(directory, `${
|
|
270
|
+
const filename = path.join(directory, `${account}${SWAGGER_SEP}${type}${SWAGGER_SEP}${version}${SWAGGER_SEP}${swaggerExt}`);
|
|
157
271
|
|
|
158
272
|
if (fileExists(filename)) {
|
|
159
273
|
let result;
|
|
@@ -163,53 +277,96 @@ const getAPI = (directory, name, version) => {
|
|
|
163
277
|
catch (errRead) { return Promise.reject(errRead); }
|
|
164
278
|
return Promise.resolve(result);
|
|
165
279
|
}
|
|
166
|
-
const url = `${APIProvider}/${
|
|
280
|
+
const url = `${APIProvider}/${account}/${type}/${version}`;
|
|
167
281
|
|
|
168
282
|
process.stdout.write(' at (' + `${url}`.info + '): ');
|
|
169
|
-
|
|
283
|
+
const options = {
|
|
170
284
|
method: 'GET',
|
|
171
285
|
url,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
try { fs.writeFileSync(filename, json.stringify(result, null, 2)); }
|
|
178
|
-
catch (err) {
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
if (apiKey) options.headers = { Authorization: apiKey };
|
|
289
|
+
return rp(options)
|
|
290
|
+
.catch((err) => {
|
|
179
291
|
console.log(ERR_CHECK.error);
|
|
180
292
|
throw err;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
+
});
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const gettingSystemCustomer = (authorization, mSTbaseUrl) => {
|
|
306
|
+
process.stdout.write('- getting customer (' + SYSTEM_NAME.info + '): ');
|
|
307
|
+
return rp({
|
|
308
|
+
method: 'GET',
|
|
309
|
+
headers: { authorization, 'x-correlation-id': correlationId },
|
|
310
|
+
url: `${mSTbaseUrl}/customers/${SYSTEM_NAME}`,
|
|
311
|
+
})
|
|
312
|
+
.then((responseGET) => {
|
|
313
|
+
console.log(SUCCESS_CHECK.success);
|
|
314
|
+
return responseGET.data;
|
|
315
|
+
})
|
|
316
|
+
.catch((err) => {
|
|
317
|
+
console.log(ERR_CHECK.error);
|
|
318
|
+
throw err;
|
|
319
|
+
});
|
|
185
320
|
};
|
|
186
321
|
|
|
187
322
|
const settingUpCustomer = (customer, authorization, mSTbaseUrl, update) => {
|
|
188
323
|
process.stdout.write('- setting up customer (' + `${customer.name}`.info + '): ');
|
|
324
|
+
|
|
325
|
+
let isNewCustomer;
|
|
326
|
+
|
|
189
327
|
return rp({
|
|
190
|
-
method: '
|
|
328
|
+
method: 'GET',
|
|
191
329
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
192
|
-
url: `${mSTbaseUrl}/customers`,
|
|
193
|
-
json: customer,
|
|
330
|
+
url: `${mSTbaseUrl}/customers/${customer.name}`,
|
|
194
331
|
})
|
|
195
|
-
.then(() => console.log(SUCCESS_CHECK.success))
|
|
196
332
|
.catch((err) => {
|
|
197
|
-
if (err.statusCode !==
|
|
333
|
+
if (err.statusCode !== 404) {
|
|
198
334
|
console.log(ERR_CHECK.error);
|
|
199
335
|
throw err;
|
|
200
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
|
+
|
|
201
354
|
if (!update) {
|
|
202
|
-
console.log('already setup and update is false in mSTConfig.json, not updating'.
|
|
203
|
-
return
|
|
355
|
+
console.log('already setup and update is false in mSTConfig.json, not updating'.info);
|
|
356
|
+
return response.data;
|
|
204
357
|
}
|
|
205
|
-
|
|
358
|
+
|
|
359
|
+
console.log('already setup and update is true in mSTConfig.json, updating'.info);
|
|
206
360
|
return rp({
|
|
207
361
|
method: 'PUT',
|
|
208
362
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
209
363
|
url: `${mSTbaseUrl}/customers/${customer.name}`,
|
|
210
|
-
|
|
364
|
+
data: customer,
|
|
211
365
|
})
|
|
212
|
-
.then(() =>
|
|
366
|
+
.then((responsePUT) => {
|
|
367
|
+
console.log(SUCCESS_CHECK.success);
|
|
368
|
+
return responsePUT.data;
|
|
369
|
+
})
|
|
213
370
|
.catch((errPUT) => {
|
|
214
371
|
console.log(ERR_CHECK.error);
|
|
215
372
|
throw errPUT;
|
|
@@ -223,7 +380,7 @@ const settingUpServer = (serverType, serverId, customer, authorization, mSTbaseU
|
|
|
223
380
|
method: 'POST',
|
|
224
381
|
url: `${mSTbaseUrl}/clients`,
|
|
225
382
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
226
|
-
|
|
383
|
+
data: {
|
|
227
384
|
externalId: serverId,
|
|
228
385
|
type: serverType,
|
|
229
386
|
customerName: customer.name,
|
|
@@ -262,49 +419,18 @@ const settingUpDummyServer = (serverType, serverId, customer, origStart) => {
|
|
|
262
419
|
|
|
263
420
|
updatedStart.OAUTH_GENERIC_KEY = 'a-secret-key-for-generic';
|
|
264
421
|
updatedStart.OAUTH_GENERIC_AUDIENCE = `http://dummy-${serverType}-generic-audience`;
|
|
265
|
-
|
|
266
|
-
updatedStart[`${
|
|
267
|
-
updatedStart[`${
|
|
268
|
-
});
|
|
269
|
-
console.log(SUCCESS_CHECK.success);
|
|
270
|
-
return updatedStart;
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
const init = (regType, standAlone) => {
|
|
274
|
-
const pack = retrieve(regType, packageFile);
|
|
275
|
-
const sumoLog = retrieve(regType, sumoLogFile, { default: DEFAULT_SUMOLOG });
|
|
276
|
-
const s3Log = retrieve(regType, s3LogFile, { default: DEFAULT_S3LOG });
|
|
277
|
-
|
|
278
|
-
console.log('- server type is ' + pack.type.info);
|
|
279
|
-
const config = {
|
|
280
|
-
regType,
|
|
281
|
-
pack,
|
|
282
|
-
sumoLog,
|
|
283
|
-
s3Log,
|
|
284
|
-
};
|
|
285
|
-
if (pack.type !== 'mST') config.customer = retrieve(regType, customerConfigFile); // we don't need customer for mST
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (standAlone === 'yes') {
|
|
289
|
-
config.mST = DUMMY_MST;
|
|
290
|
-
console.log('- using ' + 'dummy mSTConfig'.warn);
|
|
291
|
-
config.mIT = DUMMY_MIT;
|
|
292
|
-
console.log('- using ' + 'dummy mITConfig'.warn);
|
|
293
|
-
config.mID = DUMMY_MID;
|
|
294
|
-
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`;
|
|
295
425
|
}
|
|
296
426
|
else {
|
|
297
|
-
config.
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
config.mSTBaseUrl = baseUrl('mST', regType, config.mST);
|
|
302
|
-
config.MITBaseUrl = baseUrl('mIT', regType, config.mIT);
|
|
303
|
-
if (config.mST.domainName === 'localhost') {
|
|
304
|
-
console.log('- in ' + 'mST localhost, updating mST is true'.warn);
|
|
305
|
-
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
|
+
});
|
|
306
431
|
}
|
|
307
|
-
|
|
432
|
+
console.log(SUCCESS_CHECK.success);
|
|
433
|
+
return updatedStart;
|
|
308
434
|
};
|
|
309
435
|
|
|
310
436
|
const settingUpAdminClient = (serverType, adminExternalId, customer, authorization, mSTbaseUrl) => {
|
|
@@ -313,14 +439,14 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
|
|
|
313
439
|
method: 'POST',
|
|
314
440
|
url: `${mSTbaseUrl}/clients`,
|
|
315
441
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
316
|
-
|
|
442
|
+
data: {
|
|
317
443
|
externalId: adminExternalId,
|
|
318
444
|
type: 'admin',
|
|
319
445
|
customerName: customer.name,
|
|
320
446
|
},
|
|
321
447
|
}).then((resultPOST) => {
|
|
322
448
|
console.log(SUCCESS_CHECK.success);
|
|
323
|
-
return resultPOST
|
|
449
|
+
return resultPOST;
|
|
324
450
|
}).catch((err) => {
|
|
325
451
|
if (err.statusCode !== 409) {
|
|
326
452
|
console.log(ERR_CHECK.error);
|
|
@@ -330,7 +456,6 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
|
|
|
330
456
|
method: 'GET',
|
|
331
457
|
url: `${mSTbaseUrl}/clients/${adminExternalId}`,
|
|
332
458
|
headers: { authorization, 'x-correlation-id': correlationId },
|
|
333
|
-
json: true,
|
|
334
459
|
}).catch((errGET) => {
|
|
335
460
|
console.log(ERR_CHECK.error);
|
|
336
461
|
throw errGET;
|
|
@@ -340,21 +465,25 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
|
|
|
340
465
|
throw new Error(`customer name conflict, admin cannot use externalId: ${adminExternalId}`);
|
|
341
466
|
}
|
|
342
467
|
console.log('already setup'.warn);
|
|
343
|
-
return resultGET
|
|
468
|
+
return resultGET;
|
|
344
469
|
});
|
|
345
470
|
});
|
|
346
471
|
};
|
|
347
472
|
|
|
348
|
-
const getAdminToken = (
|
|
349
|
-
process.stdout.write('- getting admin token for ' +
|
|
473
|
+
const getAdminToken = (audienceType, admin, mSTbaseUrl) => {
|
|
474
|
+
process.stdout.write('- getting admin token for ' + audienceType.type.info + ': ');
|
|
475
|
+
if (!audienceType.audience) {
|
|
476
|
+
console.log(ERR_CHECK.error);
|
|
477
|
+
return Promise.reject(new Error(`no audience for ${audienceType.type}`));
|
|
478
|
+
}
|
|
350
479
|
return rp({
|
|
351
480
|
method: 'POST',
|
|
352
481
|
headers: { 'x-correlation-id': correlationId },
|
|
353
482
|
url: `${mSTbaseUrl}/oauth/token`,
|
|
354
|
-
|
|
483
|
+
data: {
|
|
355
484
|
client_id: admin.id,
|
|
356
485
|
client_secret: admin.secret,
|
|
357
|
-
audience: `${
|
|
486
|
+
audience: `${audienceType.audience.split('Generic-')[0]}Generic-${audienceType.type}`,
|
|
358
487
|
grant_type: 'client_credentials',
|
|
359
488
|
},
|
|
360
489
|
}).catch((err) => {
|
|
@@ -367,12 +496,14 @@ const getAdminToken = (serverType, admin, mSTbaseUrl) => {
|
|
|
367
496
|
};
|
|
368
497
|
|
|
369
498
|
module.exports = {
|
|
499
|
+
getStartParams,
|
|
500
|
+
init,
|
|
370
501
|
startSetup,
|
|
371
502
|
getAPI,
|
|
503
|
+
gettingSystemCustomer,
|
|
372
504
|
settingUpCustomer,
|
|
373
505
|
settingUpServer,
|
|
374
506
|
settingUpDummyServer,
|
|
375
|
-
init,
|
|
376
507
|
settingUpAdminClient,
|
|
377
508
|
getAdminToken,
|
|
378
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
|
+
}
|