@mimik/local 1.6.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/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 { getTargets } = require('./commonExt');
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, isMSTDisabled) => {
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 (!isMSTDisabled && 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 || isMSTDisabled) {
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 === 'mST') exitError(regType, Error(`standAlone does not apply to ${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('mIT', regType, config.mIT);
53
- start.MST_URL = baseUrl('mST', regType, config.mST);
136
+ start.MIT_URL = baseUrl(IT_REGISTRY, regType, config.mIT);
137
+ start.MST_URL = baseUrl(TOKEN_SERVICE, regType, config.mST);
54
138
  // logs
55
- if (!start.LOG_MODE || start.LOG_MODE === SUMOLOGIC || start.LOG_MODE === ALL) {
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 (start.LOG_MODE === AWS_S3 || start.LOG_MODE === ALL) {
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,22 +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();
80
183
  // passphrase to be shared to all the servers
81
184
  if (config.mST.passphrase) start.PASSPHRASE = config.mST.passphrase;
82
185
  // oauth issuer full address
83
- start.OAUTH_ISSUER = `${baseUrl('mST', regType, config.mST)}/oauth/token`;
186
+ start.OAUTH_ISSUER = `${baseUrl(TOKEN_SERVICE, regType, config.mST, LITERAL)}/oauth/token`;
84
187
  // setting admin
85
- start.ADMIN_EXTERNAL_ID = `admin_${config.customer ? config.customer.name : 'System'}_${start.NODE_ENV}_${type}`;
188
+ start.ADMIN_EXTERNAL_ID = `admin_${config.customer ? config.customer.name : SYSTEM_NAME}_${start.NODE_ENV}_${type}`;
86
189
  // setting up dummy variables which will be updating by mST seeding
87
190
  start.OAUTH_CLIENT_ID = '--noId--';
88
191
  start.OAUTH_CLIENT_SECRET = '--noSecret--';
89
192
  start.OAUTH_CLIENT_ACCESS_KEY = '--noKey--';
90
193
  start.OAUTH_CLIENT_AUDIENCE = '--noAudience--';
91
194
  // specific to mST
92
- if (type === 'mST') {
195
+ if (type === TOKEN_SERVICE) {
93
196
  // use the port from config
94
197
  start.SERVER_PORT = config.mST.port;
95
198
  // setting admin
@@ -98,27 +201,35 @@ const startSetup = (config, origStart) => {
98
201
  // default audience
99
202
  start.MIT_AUDIENCE = '--noAudience--';
100
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;
101
207
  }
102
208
  // specific to mID
103
- if (type === 'mID') {
209
+ if (type === IDENTITY_SERVICE) {
104
210
  start.SERVER_PORT = config.mID.port;
105
211
  // setting url
106
- start.MID_URL = baseUrl('mID', regType, config.mID);
212
+ start.MID_URL = baseUrl(IDENTITY_SERVICE, regType, config.mID);
107
213
  }
108
- if (type === 'mIT') {
214
+ if (type === IT_REGISTRY) {
109
215
  start.SERVER_PORT = config.mIT.port;
110
216
  }
111
217
  // specific to servers that need to handle user token and mID
112
- if (start.oauthImplicitNeeded === 'yes' || type === 'mID') {
218
+ if (start.oauthImplicitNeeded === 'yes' || type === IDENTITY_SERVICE) {
113
219
  delete start.oauthImplicitNeeded;
114
220
  start.OAUTH_IMPLICIT_AUDIENCE = config.mID.implicit.audience;
115
221
  start.OAUTH_IMPLICIT_KEY = config.mID.implicit.key;
116
- start.OAUTH_IMPLICIT_ISSUER = `${baseUrl('mID', regType, config.mID)}/oauth/token`;
222
+ start.OAUTH_IMPLICIT_ISSUER = `${baseUrl(IDENTITY_SERVICE, regType, config.mID, LITERAL)}/oauth/token`;
117
223
  }
118
224
  // specific to servers than need to interact with mID
119
225
  if (start.mIDNeeded === 'yes') {
120
226
  delete start.mIDNeeded;
121
- start.MID_URL = baseUrl('mID', regType, config.mID);
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;
122
233
  }
123
234
 
124
235
  return start;
@@ -131,16 +242,17 @@ const startSetup = (config, origStart) => {
131
242
  * @function getAPI
132
243
  * @category async
133
244
  * @param {PATH<string>} directory - Directory to store the API file.
134
- * @param {string} name - Name of the API to retrieve. The name is made of a `(customer)`_`(API name)`.
245
+ * @param {string} account - Account of the API API to retrieve.
246
+ * @param {string} type - Type of microservice associated with the API to retrieve.
135
247
  * @param {SEMVER<string>} version - Version fo the API to retrieve.
248
+ * @param {string} apiKey - key to access private API.
136
249
  * @return {Promise}.
137
250
  * @fulfil {object} The API file itself.
138
251
  * @throws {Promise} An error containing the reason of the failure.
139
252
  *
140
253
  * The directory will be created if it does not exist.
141
254
  */
142
- const getAPI = (directory, name, version) => {
143
- const params = name.split('_');
255
+ const getAPI = (directory, account, type, version, apiKey) => {
144
256
  const fileExists = (fname) => {
145
257
  try { fs.statSync(fname); }
146
258
  catch (err) { return false; }
@@ -155,7 +267,7 @@ const getAPI = (directory, name, version) => {
155
267
  return Promise.reject(err);
156
268
  }
157
269
  }
158
- const filename = path.join(directory, `${name}_${version}_${swaggerExt}`);
270
+ const filename = path.join(directory, `${account}${SWAGGER_SEP}${type}${SWAGGER_SEP}${version}${SWAGGER_SEP}${swaggerExt}`);
159
271
 
160
272
  if (fileExists(filename)) {
161
273
  let result;
@@ -165,67 +277,95 @@ const getAPI = (directory, name, version) => {
165
277
  catch (errRead) { return Promise.reject(errRead); }
166
278
  return Promise.resolve(result);
167
279
  }
168
- const url = `${APIProvider}/${params[0]}/${params[1]}/${version}`;
280
+ const url = `${APIProvider}/${account}/${type}/${version}`;
169
281
 
170
282
  process.stdout.write(' at (' + `${url}`.info + '): ');
171
- return rp({
283
+ const options = {
172
284
  method: 'GET',
173
285
  url,
174
- json: true,
175
- }).catch((err) => {
176
- console.log(ERR_CHECK.error);
177
- throw err;
178
- }).then((result) => {
179
- try { fs.writeFileSync(filename, json.stringify(result, null, 2)); }
180
- catch (err) {
286
+ };
287
+
288
+ if (apiKey) options.headers = { Authorization: apiKey };
289
+ return rp(options)
290
+ .catch((err) => {
181
291
  console.log(ERR_CHECK.error);
182
292
  throw err;
183
- }
184
- console.log(SUCCESS_CHECK.success);
185
- return result;
186
- });
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
+ });
187
303
  };
188
304
 
189
- const settingUpCustomer = (customer, authorization, mSTbaseUrl, update) => {
190
- process.stdout.write('- setting up customer (' + `${customer.name}`.info + '): ');
305
+ const gettingSystemCustomer = (authorization, mSTbaseUrl) => {
306
+ process.stdout.write('- getting customer (' + SYSTEM_NAME.info + '): ');
191
307
  return rp({
192
- method: 'POST',
308
+ method: 'GET',
193
309
  headers: { authorization, 'x-correlation-id': correlationId },
194
- url: `${mSTbaseUrl}/customers`,
195
- json: customer,
310
+ url: `${mSTbaseUrl}/customers/${SYSTEM_NAME}`,
196
311
  })
197
- .then((responsePOST) => {
312
+ .then((responseGET) => {
198
313
  console.log(SUCCESS_CHECK.success);
199
- return responsePOST.data.code;
314
+ return responseGET.data;
200
315
  })
201
316
  .catch((err) => {
202
- if (err.statusCode !== 409) {
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) {
203
334
  console.log(ERR_CHECK.error);
204
335
  throw err;
205
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
+
206
354
  if (!update) {
207
- console.log('already setup and update is false in mSTConfig.json, not updating'.warn);
208
- return rp({
209
- method: 'GET',
210
- headers: { authorization, 'x-correlation-id': correlationId },
211
- url: `${mSTbaseUrl}/customers/${customer.name}`,
212
- })
213
- .then((responseGET) => responseGET.data.code)
214
- .catch((errGET) => {
215
- console.log(ERR_CHECK.error);
216
- throw errGET;
217
- });
355
+ console.log('already setup and update is false in mSTConfig.json, not updating'.info);
356
+ return response.data;
218
357
  }
219
- process.stdout.write('already setup, updating: '.warn);
358
+
359
+ console.log('already setup and update is true in mSTConfig.json, updating'.info);
220
360
  return rp({
221
361
  method: 'PUT',
222
362
  headers: { authorization, 'x-correlation-id': correlationId },
223
363
  url: `${mSTbaseUrl}/customers/${customer.name}`,
224
- json: customer,
364
+ data: customer,
225
365
  })
226
366
  .then((responsePUT) => {
227
367
  console.log(SUCCESS_CHECK.success);
228
- return responsePUT.data.code;
368
+ return responsePUT.data;
229
369
  })
230
370
  .catch((errPUT) => {
231
371
  console.log(ERR_CHECK.error);
@@ -240,7 +380,7 @@ const settingUpServer = (serverType, serverId, customer, authorization, mSTbaseU
240
380
  method: 'POST',
241
381
  url: `${mSTbaseUrl}/clients`,
242
382
  headers: { authorization, 'x-correlation-id': correlationId },
243
- json: {
383
+ data: {
244
384
  externalId: serverId,
245
385
  type: serverType,
246
386
  customerName: customer.name,
@@ -279,49 +419,18 @@ const settingUpDummyServer = (serverType, serverId, customer, origStart) => {
279
419
 
280
420
  updatedStart.OAUTH_GENERIC_KEY = 'a-secret-key-for-generic';
281
421
  updatedStart.OAUTH_GENERIC_AUDIENCE = `http://dummy-${serverType}-generic-audience`;
282
- getTargets(serverType, customer.config).forEach((target) => {
283
- updatedStart[`${target.toUpperCase()}_URL`] = `http://dummy-${target}/dummy`;
284
- updatedStart[`${target.toUpperCase()}_AUDIENCE`] = `http://dummy-${target}-audience`;
285
- });
286
- console.log(SUCCESS_CHECK.success);
287
- return updatedStart;
288
- };
289
-
290
- const init = (regType, standAlone) => {
291
- const pack = retrieve(regType, packageFile);
292
- const sumoLog = retrieve(regType, sumoLogFile, { default: DEFAULT_SUMOLOG });
293
- const s3Log = retrieve(regType, s3LogFile, { default: DEFAULT_S3LOG });
294
-
295
- console.log('- server type is ' + pack.type.info);
296
- const config = {
297
- regType,
298
- pack,
299
- sumoLog,
300
- s3Log,
301
- };
302
- if (pack.type !== 'mST') config.customer = retrieve(regType, customerConfigFile); // we don't need customer for mST
303
-
304
-
305
- if (standAlone === 'yes') {
306
- config.mST = DUMMY_MST;
307
- console.log('- using ' + 'dummy mSTConfig'.warn);
308
- config.mIT = DUMMY_MIT;
309
- console.log('- using ' + 'dummy mITConfig'.warn);
310
- config.mID = DUMMY_MID;
311
- 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`;
312
425
  }
313
426
  else {
314
- config.mST = retrieve(regType, mSTConfigFile, { default: DEFAULT_MST });
315
- config.mIT = retrieve(regType, mITConfigFile, { default: DEFAULT_MIT });
316
- config.mID = retrieve(regType, mIDConfigFile, { default: DEFAULT_MID });
317
- }
318
- config.mSTBaseUrl = baseUrl('mST', regType, config.mST);
319
- config.MITBaseUrl = baseUrl('mIT', regType, config.mIT);
320
- if (config.mST.domainName === 'localhost') {
321
- console.log('- in ' + 'mST localhost, updating mST is true'.warn);
322
- 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
+ });
323
431
  }
324
- return config;
432
+ console.log(SUCCESS_CHECK.success);
433
+ return updatedStart;
325
434
  };
326
435
 
327
436
  const settingUpAdminClient = (serverType, adminExternalId, customer, authorization, mSTbaseUrl) => {
@@ -330,14 +439,14 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
330
439
  method: 'POST',
331
440
  url: `${mSTbaseUrl}/clients`,
332
441
  headers: { authorization, 'x-correlation-id': correlationId },
333
- json: {
442
+ data: {
334
443
  externalId: adminExternalId,
335
444
  type: 'admin',
336
445
  customerName: customer.name,
337
446
  },
338
447
  }).then((resultPOST) => {
339
448
  console.log(SUCCESS_CHECK.success);
340
- return resultPOST.data;
449
+ return resultPOST;
341
450
  }).catch((err) => {
342
451
  if (err.statusCode !== 409) {
343
452
  console.log(ERR_CHECK.error);
@@ -347,7 +456,6 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
347
456
  method: 'GET',
348
457
  url: `${mSTbaseUrl}/clients/${adminExternalId}`,
349
458
  headers: { authorization, 'x-correlation-id': correlationId },
350
- json: true,
351
459
  }).catch((errGET) => {
352
460
  console.log(ERR_CHECK.error);
353
461
  throw errGET;
@@ -357,21 +465,25 @@ const settingUpAdminClient = (serverType, adminExternalId, customer, authorizati
357
465
  throw new Error(`customer name conflict, admin cannot use externalId: ${adminExternalId}`);
358
466
  }
359
467
  console.log('already setup'.warn);
360
- return resultGET.data;
468
+ return resultGET;
361
469
  });
362
470
  });
363
471
  };
364
472
 
365
- const getAdminToken = (serverType, admin, mSTbaseUrl) => {
366
- process.stdout.write('- getting admin token for ' + serverType.info + ': ');
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
+ }
367
479
  return rp({
368
480
  method: 'POST',
369
481
  headers: { 'x-correlation-id': correlationId },
370
482
  url: `${mSTbaseUrl}/oauth/token`,
371
- json: {
483
+ data: {
372
484
  client_id: admin.id,
373
485
  client_secret: admin.secret,
374
- audience: `${mSTbaseUrl}/clients/Generic-${serverType}`,
486
+ audience: `${audienceType.audience.split('Generic-')[0]}Generic-${audienceType.type}`,
375
487
  grant_type: 'client_credentials',
376
488
  },
377
489
  }).catch((err) => {
@@ -384,12 +496,14 @@ const getAdminToken = (serverType, admin, mSTbaseUrl) => {
384
496
  };
385
497
 
386
498
  module.exports = {
499
+ getStartParams,
500
+ init,
387
501
  startSetup,
388
502
  getAPI,
503
+ gettingSystemCustomer,
389
504
  settingUpCustomer,
390
505
  settingUpServer,
391
506
  settingUpDummyServer,
392
- init,
393
507
  settingUpAdminClient,
394
508
  getAdminToken,
395
509
  };
@@ -1,3 +1,3 @@
1
1
  const start = require('../index');
2
2
 
3
- return start.getAPI('./testing', 'mimik_mDS', '1.1.1')
3
+ return start.getAPI('./testing', 'mimik', 'mDS', '1.1.1')
@@ -1,5 +1,7 @@
1
- const start = require('../index');
1
+ const { retrieve }= require('../lib/helpers');
2
2
 
3
- console.log(start.retrieve('test', 'orig.json', 'source.json'));
3
+ // console.log(retrieve('test', 'test.json', { sourceFilename: './start-example.json', sourceFilenameSupp: 'startTest-example.json' } ));
4
4
 
5
- // console.log(start.retrieve('test', 'alt.json', 'source.json', 'orig.json'));
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,8 @@
1
+ {
2
+ "CONSOLE_LEVEL": "info",
3
+ "NO_STACK": "no",
4
+ "LOG_MODE": "all",
5
+ // Required by @mimik/test-helper if USE_MOCK_PROFILES is "no":
6
+ // "MST_TOKEN": "mST-token",
7
+ "USE_MOCK_PROFILES": "yes"
8
+ }
@@ -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
+ }