@mimik/local 5.1.5 → 5.2.0
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/README.md +2 -1
- package/index.js +6 -5
- package/lib/common.js +20 -7
- package/lib/tasks.js +67 -22
- package/package.json +20 -17
package/README.md
CHANGED
|
@@ -83,7 +83,8 @@ Similar properties than for mSTConfig on `domainName` and `port` apply.
|
|
|
83
83
|
- for `key.json`:
|
|
84
84
|
``` javascript
|
|
85
85
|
{
|
|
86
|
-
"
|
|
86
|
+
"username": "username to access the bitbucket account",
|
|
87
|
+
"password": "password to access the bitbucket account"
|
|
87
88
|
}
|
|
88
89
|
```
|
|
89
90
|
- for `locationConfig.json`:
|
package/index.js
CHANGED
|
@@ -17,7 +17,7 @@ const {
|
|
|
17
17
|
parse,
|
|
18
18
|
} = require('./lib/helpers');
|
|
19
19
|
const {
|
|
20
|
-
|
|
20
|
+
DEFAULT_DIRECTORY,
|
|
21
21
|
testJsonFile,
|
|
22
22
|
shellFile,
|
|
23
23
|
DUMMY_CUSTOMER_CODE,
|
|
@@ -135,7 +135,8 @@ const INSTALL = 'install';
|
|
|
135
135
|
* - for `key.json`:
|
|
136
136
|
* ``` javascript
|
|
137
137
|
* {
|
|
138
|
-
* "
|
|
138
|
+
* "username": "username to access the bitbucket account",
|
|
139
|
+
* "password": "password to access the bitbucket account"
|
|
139
140
|
* }
|
|
140
141
|
* ```
|
|
141
142
|
* - for `locationConfig.json`:
|
|
@@ -197,7 +198,7 @@ const mSTInit = (confType) => {
|
|
|
197
198
|
const config = init(regType, false, true);
|
|
198
199
|
const start = startSetup(config, startConfig);
|
|
199
200
|
|
|
200
|
-
getAPI(start.SWAGGER_FILE_DIRECTORY ||
|
|
201
|
+
getAPI(start.SWAGGER_FILE_DIRECTORY || DEFAULT_DIRECTORY, config.pack.swaggerFile.account, config.pack.swaggerFile.name, config.pack.swaggerFile.version, config.key)
|
|
201
202
|
.then((apiFile) => {
|
|
202
203
|
console.log('- mST base url: ' + config.mSTBaseUrl.info);
|
|
203
204
|
console.log('- mIT base url: ' + config.MITBaseUrl.info);
|
|
@@ -224,7 +225,7 @@ const mITInit = (confType) => {
|
|
|
224
225
|
let start = startSetup(config, startConfig);
|
|
225
226
|
let authorization;
|
|
226
227
|
|
|
227
|
-
getAPI(start.SWAGGER_FILE_DIRECTORY ||
|
|
228
|
+
getAPI(start.SWAGGER_FILE_DIRECTORY || DEFAULT_DIRECTORY, config.pack.swaggerFile.account, config.pack.swaggerFile.name, config.pack.swaggerFile.version, config.key)
|
|
228
229
|
.then((apiFile) => {
|
|
229
230
|
console.log('- mST base url: ' + `${mSTBaseUrl}`.info);
|
|
230
231
|
console.log('- mIT base url: ' + config.MITBaseUrl.info);
|
|
@@ -291,7 +292,7 @@ const serverInit = (confType) => {
|
|
|
291
292
|
let start = startSetup(config, startConfig);
|
|
292
293
|
let authorization;
|
|
293
294
|
|
|
294
|
-
getAPI(start.SWAGGER_FILE_DIRECTORY ||
|
|
295
|
+
getAPI(start.SWAGGER_FILE_DIRECTORY || DEFAULT_DIRECTORY, config.pack.swaggerFile.account, config.pack.swaggerFile.name, config.pack.swaggerFile.version, config.key)
|
|
295
296
|
.then((apiFile) => {
|
|
296
297
|
console.log('- mST base url: ' + `${mSTBaseUrl}`.info);
|
|
297
298
|
console.log('- mIT base url: ' + config.MITBaseUrl.info);
|
package/lib/common.js
CHANGED
|
@@ -8,9 +8,13 @@ const kinesisLogFile = '../kinesisLog.json';
|
|
|
8
8
|
const locationFile = '../locationConfig.json';
|
|
9
9
|
const keyFile = '../key.json';
|
|
10
10
|
const customerConfigFile = '../customerConfig.json';
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
|
|
12
|
+
const API_PROVIDER = 'https://api.bitbucket.org/2.0/repositories';
|
|
13
|
+
const API_SOURCE = '/src';
|
|
14
|
+
const SWAGGER = 'swagger';
|
|
15
|
+
const EXTENSION = '.yml';
|
|
16
|
+
const SWAGGER_EXT = `${SWAGGER}.json`;
|
|
17
|
+
const DEFAULT_DIRECTORY = './api';
|
|
14
18
|
|
|
15
19
|
const AWS_S3 = 'awsS3';
|
|
16
20
|
const AWS_KINESIS = 'awsKinesis';
|
|
@@ -22,6 +26,9 @@ const ALL_MODES = [AWS_S3, AWS_KINESIS, SUMOLOGIC, ALL, NONE];
|
|
|
22
26
|
const SWAGGER_SEP = '_';
|
|
23
27
|
const TEST = 'test';
|
|
24
28
|
|
|
29
|
+
const DEFAULT_BITBUCKET_USERNAME = ' ';
|
|
30
|
+
const DEFAULT_BITBUCKET_PASSWORD = ' ';
|
|
31
|
+
|
|
25
32
|
const SYSTEM_NAME = 'System';
|
|
26
33
|
const TOKEN_SERVICE = 'mST';
|
|
27
34
|
const IT_REGISTRY = 'mIT';
|
|
@@ -116,7 +123,8 @@ const DEFAULT_KINESISLOG = {
|
|
|
116
123
|
streamNameOther: '--- default streamName Other ---',
|
|
117
124
|
};
|
|
118
125
|
const DEFAULT_KEY = {
|
|
119
|
-
|
|
126
|
+
username: DEFAULT_BITBUCKET_USERNAME,
|
|
127
|
+
password: DEFAULT_BITBUCKET_USERNAME,
|
|
120
128
|
};
|
|
121
129
|
const DEFAULT_LOCATION = {
|
|
122
130
|
url: null,
|
|
@@ -137,9 +145,12 @@ module.exports = {
|
|
|
137
145
|
locationFile,
|
|
138
146
|
keyFile,
|
|
139
147
|
customerConfigFile,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
API_PROVIDER,
|
|
149
|
+
API_SOURCE,
|
|
150
|
+
SWAGGER,
|
|
151
|
+
EXTENSION,
|
|
152
|
+
SWAGGER_EXT,
|
|
153
|
+
DEFAULT_DIRECTORY,
|
|
143
154
|
testJsonFile,
|
|
144
155
|
shellFile,
|
|
145
156
|
startFile,
|
|
@@ -175,4 +186,6 @@ module.exports = {
|
|
|
175
186
|
TOKEN_SERVICE,
|
|
176
187
|
IT_REGISTRY,
|
|
177
188
|
IDENTITY_SERVICE,
|
|
189
|
+
DEFAULT_BITBUCKET_USERNAME,
|
|
190
|
+
DEFAULT_BITBUCKET_PASSWORD,
|
|
178
191
|
};
|
package/lib/tasks.js
CHANGED
|
@@ -5,6 +5,9 @@ const path = require('path');
|
|
|
5
5
|
const Promise = require('bluebird');
|
|
6
6
|
const uuid = require('uuid');
|
|
7
7
|
const _ = require('lodash');
|
|
8
|
+
const yaml = require('js-yaml');
|
|
9
|
+
const SwaggerClient = require('swagger-client');
|
|
10
|
+
const { Base64 } = require('js-base64');
|
|
8
11
|
|
|
9
12
|
const { rp } = require('./rp-axios-wrapper');
|
|
10
13
|
const { getAllTargets } = require('./commonExt');
|
|
@@ -25,8 +28,11 @@ const {
|
|
|
25
28
|
mIDConfigFile,
|
|
26
29
|
ERR_CHECK,
|
|
27
30
|
SUCCESS_CHECK,
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
SWAGGER_EXT,
|
|
32
|
+
API_SOURCE,
|
|
33
|
+
SWAGGER,
|
|
34
|
+
EXTENSION,
|
|
35
|
+
API_PROVIDER,
|
|
30
36
|
correlationId,
|
|
31
37
|
LITERAL,
|
|
32
38
|
DEFAULT_SUMOLOG,
|
|
@@ -52,6 +58,8 @@ const {
|
|
|
52
58
|
TOKEN_SERVICE,
|
|
53
59
|
IDENTITY_SERVICE,
|
|
54
60
|
TEST,
|
|
61
|
+
DEFAULT_BITBUCKET_USERNAME,
|
|
62
|
+
DEFAULT_BITBUCKET_PASSWORD,
|
|
55
63
|
} = require('./common');
|
|
56
64
|
const {
|
|
57
65
|
exitError,
|
|
@@ -245,14 +253,15 @@ const startSetup = (config, origStart) => {
|
|
|
245
253
|
* @param {string} account - Account of the API API to retrieve.
|
|
246
254
|
* @param {string} type - Type of microservice associated with the API to retrieve.
|
|
247
255
|
* @param {SEMVER<string>} version - Version fo the API to retrieve.
|
|
248
|
-
* @param {string}
|
|
256
|
+
* @param {string} basicAuth - username password to access the bitbucket account
|
|
257
|
+
* .
|
|
249
258
|
* @return {Promise}.
|
|
250
259
|
* @fulfil {object} The API file itself.
|
|
251
260
|
* @throws {Promise} An error containing the reason of the failure.
|
|
252
261
|
*
|
|
253
262
|
* The directory will be created if it does not exist.
|
|
254
263
|
*/
|
|
255
|
-
const getAPI = (directory, account, type, version,
|
|
264
|
+
const getAPI = (directory, account, type, version, basicAuth) => {
|
|
256
265
|
const fileExists = (fname) => {
|
|
257
266
|
try { fs.statSync(fname); }
|
|
258
267
|
catch (err) { return false; }
|
|
@@ -267,17 +276,37 @@ const getAPI = (directory, account, type, version, apiKey) => {
|
|
|
267
276
|
return Promise.reject(err);
|
|
268
277
|
}
|
|
269
278
|
}
|
|
270
|
-
const
|
|
279
|
+
const apiFilename = path.join(directory, `${account}${SWAGGER_SEP}${type}${SWAGGER_SEP}${version}${SWAGGER_SEP}${SWAGGER_EXT}`);
|
|
271
280
|
|
|
272
|
-
if (fileExists(
|
|
273
|
-
|
|
281
|
+
if (fileExists(apiFilename)) {
|
|
282
|
+
console.log(': ' + apiFilename.info + ' ' + 'already setup'.warn);
|
|
283
|
+
let apiDefinition;
|
|
274
284
|
|
|
275
|
-
|
|
276
|
-
try { result = json.parse(fs.readFileSync(filename).toString()); }
|
|
285
|
+
try { apiDefinition = json.parse(fs.readFileSync(apiFilename).toString()); }
|
|
277
286
|
catch (errRead) { return Promise.reject(errRead); }
|
|
278
|
-
return
|
|
287
|
+
return SwaggerClient.resolve({
|
|
288
|
+
spec: apiDefinition,
|
|
289
|
+
allowMetaPatches: false,
|
|
290
|
+
skipNormalization: true,
|
|
291
|
+
mode: 'strict',
|
|
292
|
+
})
|
|
293
|
+
.then((apiDefinitionResult) => {
|
|
294
|
+
if (apiDefinitionResult.errors.length !== 0) {
|
|
295
|
+
throw new Error('Errors while resolving definition');
|
|
296
|
+
}
|
|
297
|
+
fs.writeFileSync(apiFilename, JSON.stringify(apiDefinitionResult.spec, null, 2));
|
|
298
|
+
console.log(SUCCESS_CHECK.success);
|
|
299
|
+
return apiDefinitionResult.spec;
|
|
300
|
+
})
|
|
301
|
+
.catch((err) => {
|
|
302
|
+
console.log(ERR_CHECK.error);
|
|
303
|
+
const error = err;
|
|
304
|
+
|
|
305
|
+
error.message = `${error.message} - { "apiFilename": "${apiFilename}" }`;
|
|
306
|
+
throw error;
|
|
307
|
+
});
|
|
279
308
|
}
|
|
280
|
-
const url = `${
|
|
309
|
+
const url = `${API_PROVIDER}/${account}/${type}${API_SOURCE}/${version}/${SWAGGER}${EXTENSION}`;
|
|
281
310
|
|
|
282
311
|
process.stdout.write(' at (' + `${url}`.info + '): ');
|
|
283
312
|
const options = {
|
|
@@ -285,20 +314,36 @@ const getAPI = (directory, account, type, version, apiKey) => {
|
|
|
285
314
|
url,
|
|
286
315
|
};
|
|
287
316
|
|
|
288
|
-
if (
|
|
317
|
+
if (!basicAuth || basicAuth.username === DEFAULT_BITBUCKET_USERNAME || basicAuth.password === DEFAULT_BITBUCKET_PASSWORD) {
|
|
318
|
+
console.log(ERR_CHECK.error);
|
|
319
|
+
return Promise.reject(new Error('missing username/password for accessing Bitbucket'));
|
|
320
|
+
}
|
|
321
|
+
try { options.headers = { authorization: `Basic ${Base64.encode(`${basicAuth.username}:${basicAuth.password}`)}` }; }
|
|
322
|
+
catch (err) {
|
|
323
|
+
console.log(ERR_CHECK.error);
|
|
324
|
+
return Promise.reject(err);
|
|
325
|
+
}
|
|
289
326
|
return rp(options)
|
|
290
|
-
.
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
throw
|
|
327
|
+
.then((result) => SwaggerClient.resolve({
|
|
328
|
+
spec: yaml.load(result),
|
|
329
|
+
allowMetaPatches: false,
|
|
330
|
+
skipNormalization: true,
|
|
331
|
+
mode: 'strict',
|
|
332
|
+
}))
|
|
333
|
+
.then((apiDefinitionResult) => {
|
|
334
|
+
if (apiDefinitionResult.errors.length !== 0) {
|
|
335
|
+
throw new Error('Errors while resolving definition');
|
|
299
336
|
}
|
|
337
|
+
fs.writeFileSync(apiFilename, JSON.stringify(apiDefinitionResult.spec, null, 2));
|
|
300
338
|
console.log(SUCCESS_CHECK.success);
|
|
301
|
-
return
|
|
339
|
+
return apiDefinitionResult.spec;
|
|
340
|
+
})
|
|
341
|
+
.catch((err) => {
|
|
342
|
+
console.log(ERR_CHECK.error);
|
|
343
|
+
const error = err;
|
|
344
|
+
|
|
345
|
+
error.message = `${error.message} - { "apiFilename": "${apiFilename}" }`;
|
|
346
|
+
throw error;
|
|
302
347
|
});
|
|
303
348
|
};
|
|
304
349
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/local",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Local setup configuration for normal and test opreration",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,31 +29,34 @@
|
|
|
29
29
|
"url": "https://bitbucket.org/mimiktech/local"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@mimik/
|
|
33
|
-
"
|
|
32
|
+
"@mimik/eslint-plugin-dependencies": "^2.4.5",
|
|
33
|
+
"@mimik/eslint-plugin-document-env": "^1.0.5",
|
|
34
|
+
"@mimik/git-hooks": "^1.5.7",
|
|
35
|
+
"axios": "1.3.5",
|
|
34
36
|
"bluebird": "3.7.2",
|
|
37
|
+
"chai": "4.3.7",
|
|
35
38
|
"colors": "1.4.0",
|
|
36
39
|
"comment-json": "4.2.3",
|
|
37
40
|
"debug": "4.3.4",
|
|
38
|
-
"
|
|
39
|
-
"lodash": "4.17.21",
|
|
40
|
-
"uuid": "9.0.0",
|
|
41
|
-
"@mimik/eslint-plugin-dependencies": "^2.4.4",
|
|
42
|
-
"@mimik/eslint-plugin-document-env": "^1.0.4",
|
|
43
|
-
"chai": "4.3.7",
|
|
44
|
-
"eslint": "8.28.0",
|
|
41
|
+
"eslint": "8.38.0",
|
|
45
42
|
"eslint-config-airbnb": "19.0.4",
|
|
46
|
-
"eslint-plugin-import": "2.
|
|
47
|
-
"eslint-plugin-jsx-a11y": "6.
|
|
48
|
-
"eslint-plugin-react": "7.
|
|
43
|
+
"eslint-plugin-import": "2.27.5",
|
|
44
|
+
"eslint-plugin-jsx-a11y": "6.7.1",
|
|
45
|
+
"eslint-plugin-react": "7.32.2",
|
|
49
46
|
"eslint-plugin-react-hooks": "4.6.0",
|
|
50
|
-
"husky": "8.0.
|
|
47
|
+
"husky": "8.0.3",
|
|
48
|
+
"ip": "1.1.8",
|
|
49
|
+
"js-base64": "3.7.5",
|
|
50
|
+
"js-yaml": "4.1.0",
|
|
51
51
|
"jsdoc-to-markdown": "8.0.0",
|
|
52
|
-
"
|
|
52
|
+
"lodash": "4.17.21",
|
|
53
|
+
"mocha": "10.2.0",
|
|
53
54
|
"mochawesome": "7.1.3",
|
|
54
55
|
"nyc": "15.1.0",
|
|
55
56
|
"rewire": "6.0.0",
|
|
56
|
-
"sinon": "15.0.
|
|
57
|
-
"supertest": "6.3.
|
|
57
|
+
"sinon": "15.0.3",
|
|
58
|
+
"supertest": "6.3.3",
|
|
59
|
+
"swagger-client": "3.19.6",
|
|
60
|
+
"uuid": "9.0.0"
|
|
58
61
|
}
|
|
59
62
|
}
|