@mimik/local 5.1.6 → 5.2.1
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 +70 -22
- package/package.json +18 -15
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,
|
|
@@ -180,6 +188,9 @@ const startSetup = (config, origStart) => {
|
|
|
180
188
|
// server basics
|
|
181
189
|
start.SERVER_TYPE = type;
|
|
182
190
|
start.SERVER_ID = start.SERVER_ID || uuid.v4();
|
|
191
|
+
// api access
|
|
192
|
+
start.BITBUCKET_USERNAME = config.key.username;
|
|
193
|
+
start.BITBUCKET_PASSWORD = config.key.password;
|
|
183
194
|
// passphrase to be shared to all the servers
|
|
184
195
|
if (config.mST.passphrase) start.PASSPHRASE = config.mST.passphrase;
|
|
185
196
|
// oauth issuer full address
|
|
@@ -245,14 +256,15 @@ const startSetup = (config, origStart) => {
|
|
|
245
256
|
* @param {string} account - Account of the API API to retrieve.
|
|
246
257
|
* @param {string} type - Type of microservice associated with the API to retrieve.
|
|
247
258
|
* @param {SEMVER<string>} version - Version fo the API to retrieve.
|
|
248
|
-
* @param {string}
|
|
259
|
+
* @param {string} basicAuth - username password to access the bitbucket account
|
|
260
|
+
* .
|
|
249
261
|
* @return {Promise}.
|
|
250
262
|
* @fulfil {object} The API file itself.
|
|
251
263
|
* @throws {Promise} An error containing the reason of the failure.
|
|
252
264
|
*
|
|
253
265
|
* The directory will be created if it does not exist.
|
|
254
266
|
*/
|
|
255
|
-
const getAPI = (directory, account, type, version,
|
|
267
|
+
const getAPI = (directory, account, type, version, basicAuth) => {
|
|
256
268
|
const fileExists = (fname) => {
|
|
257
269
|
try { fs.statSync(fname); }
|
|
258
270
|
catch (err) { return false; }
|
|
@@ -267,17 +279,37 @@ const getAPI = (directory, account, type, version, apiKey) => {
|
|
|
267
279
|
return Promise.reject(err);
|
|
268
280
|
}
|
|
269
281
|
}
|
|
270
|
-
const
|
|
282
|
+
const apiFilename = path.join(directory, `${account}${SWAGGER_SEP}${type}${SWAGGER_SEP}${version}${SWAGGER_SEP}${SWAGGER_EXT}`);
|
|
271
283
|
|
|
272
|
-
if (fileExists(
|
|
273
|
-
|
|
284
|
+
if (fileExists(apiFilename)) {
|
|
285
|
+
console.log(': ' + apiFilename.info + ' ' + 'already setup'.warn);
|
|
286
|
+
let apiDefinition;
|
|
274
287
|
|
|
275
|
-
|
|
276
|
-
try { result = json.parse(fs.readFileSync(filename).toString()); }
|
|
288
|
+
try { apiDefinition = json.parse(fs.readFileSync(apiFilename).toString()); }
|
|
277
289
|
catch (errRead) { return Promise.reject(errRead); }
|
|
278
|
-
return
|
|
290
|
+
return SwaggerClient.resolve({
|
|
291
|
+
spec: apiDefinition,
|
|
292
|
+
allowMetaPatches: false,
|
|
293
|
+
skipNormalization: true,
|
|
294
|
+
mode: 'strict',
|
|
295
|
+
})
|
|
296
|
+
.then((apiDefinitionResult) => {
|
|
297
|
+
if (apiDefinitionResult.errors.length !== 0) {
|
|
298
|
+
throw new Error('Errors while resolving definition');
|
|
299
|
+
}
|
|
300
|
+
fs.writeFileSync(apiFilename, JSON.stringify(apiDefinitionResult.spec, null, 2));
|
|
301
|
+
console.log(SUCCESS_CHECK.success);
|
|
302
|
+
return apiDefinitionResult.spec;
|
|
303
|
+
})
|
|
304
|
+
.catch((err) => {
|
|
305
|
+
console.log(ERR_CHECK.error);
|
|
306
|
+
const error = err;
|
|
307
|
+
|
|
308
|
+
error.message = `${error.message} - { "apiFilename": "${apiFilename}" }`;
|
|
309
|
+
throw error;
|
|
310
|
+
});
|
|
279
311
|
}
|
|
280
|
-
const url = `${
|
|
312
|
+
const url = `${API_PROVIDER}/${account}/${type}${API_SOURCE}/${version}/${SWAGGER}${EXTENSION}`;
|
|
281
313
|
|
|
282
314
|
process.stdout.write(' at (' + `${url}`.info + '): ');
|
|
283
315
|
const options = {
|
|
@@ -285,20 +317,36 @@ const getAPI = (directory, account, type, version, apiKey) => {
|
|
|
285
317
|
url,
|
|
286
318
|
};
|
|
287
319
|
|
|
288
|
-
if (
|
|
320
|
+
if (!basicAuth || basicAuth.username === DEFAULT_BITBUCKET_USERNAME || basicAuth.password === DEFAULT_BITBUCKET_PASSWORD) {
|
|
321
|
+
console.log(ERR_CHECK.error);
|
|
322
|
+
return Promise.reject(new Error('missing username/password for accessing Bitbucket'));
|
|
323
|
+
}
|
|
324
|
+
try { options.headers = { authorization: `Basic ${Base64.encode(`${basicAuth.username}:${basicAuth.password}`)}` }; }
|
|
325
|
+
catch (err) {
|
|
326
|
+
console.log(ERR_CHECK.error);
|
|
327
|
+
return Promise.reject(err);
|
|
328
|
+
}
|
|
289
329
|
return rp(options)
|
|
290
|
-
.
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
throw
|
|
330
|
+
.then((result) => SwaggerClient.resolve({
|
|
331
|
+
spec: yaml.load(result),
|
|
332
|
+
allowMetaPatches: false,
|
|
333
|
+
skipNormalization: true,
|
|
334
|
+
mode: 'strict',
|
|
335
|
+
}))
|
|
336
|
+
.then((apiDefinitionResult) => {
|
|
337
|
+
if (apiDefinitionResult.errors.length !== 0) {
|
|
338
|
+
throw new Error('Errors while resolving definition');
|
|
299
339
|
}
|
|
340
|
+
fs.writeFileSync(apiFilename, JSON.stringify(apiDefinitionResult.spec, null, 2));
|
|
300
341
|
console.log(SUCCESS_CHECK.success);
|
|
301
|
-
return
|
|
342
|
+
return apiDefinitionResult.spec;
|
|
343
|
+
})
|
|
344
|
+
.catch((err) => {
|
|
345
|
+
console.log(ERR_CHECK.error);
|
|
346
|
+
const error = err;
|
|
347
|
+
|
|
348
|
+
error.message = `${error.message} - { "apiFilename": "${apiFilename}" }`;
|
|
349
|
+
throw error;
|
|
302
350
|
});
|
|
303
351
|
};
|
|
304
352
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/local",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
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/eslint-plugin-dependencies": "^2.4.5",
|
|
33
|
+
"@mimik/eslint-plugin-document-env": "^1.0.5",
|
|
32
34
|
"@mimik/git-hooks": "^1.5.7",
|
|
33
|
-
"axios": "1.
|
|
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.5",
|
|
42
|
-
"@mimik/eslint-plugin-document-env": "^1.0.5",
|
|
43
|
-
"chai": "4.3.7",
|
|
44
|
-
"eslint": "8.30.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
|
+
"lodash": "4.17.21",
|
|
52
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.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
|
}
|