@itentialopensource/adapter-godaddy 0.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.
Files changed (106) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +18 -0
  3. package/.gitlab/.gitkeep +0 -0
  4. package/.gitlab/issue_templates/.gitkeep +0 -0
  5. package/.gitlab/issue_templates/Default.md +17 -0
  6. package/.gitlab/issue_templates/bugReportTemplate.md +76 -0
  7. package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
  8. package/.jshintrc +3 -0
  9. package/AUTH.md +34 -0
  10. package/BROKER.md +199 -0
  11. package/CALLS.md +748 -0
  12. package/CHANGELOG.md +9 -0
  13. package/CODE_OF_CONDUCT.md +43 -0
  14. package/CONTRIBUTING.md +13 -0
  15. package/ENHANCE.md +69 -0
  16. package/LICENSE +201 -0
  17. package/PROPERTIES.md +641 -0
  18. package/README.md +346 -0
  19. package/SUMMARY.md +9 -0
  20. package/SYSTEMINFO.md +13 -0
  21. package/TROUBLESHOOT.md +47 -0
  22. package/adapter.js +9144 -0
  23. package/adapterBase.js +1452 -0
  24. package/changelogs/CHANGELOG.md +0 -0
  25. package/entities/.generic/action.json +214 -0
  26. package/entities/.generic/schema.json +28 -0
  27. package/entities/.system/action.json +50 -0
  28. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  29. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  30. package/entities/.system/schema.json +19 -0
  31. package/entities/.system/schemaTokenReq.json +53 -0
  32. package/entities/.system/schemaTokenResp.json +53 -0
  33. package/entities/Abuse/action.json +66 -0
  34. package/entities/Abuse/schema.json +21 -0
  35. package/entities/Actions/action.json +66 -0
  36. package/entities/Actions/mockdatafiles/getV2CustomersCustomerIdDomainsDomainActions-default.json +126 -0
  37. package/entities/Actions/schema.json +21 -0
  38. package/entities/Aftermarket/action.json +44 -0
  39. package/entities/Aftermarket/schema.json +20 -0
  40. package/entities/Agreements/action.json +25 -0
  41. package/entities/Agreements/mockdatafiles/getAgreements-default.json +8 -0
  42. package/entities/Agreements/schema.json +19 -0
  43. package/entities/Certificate/action.json +517 -0
  44. package/entities/Certificate/mockdatafiles/certificateGetEntitlement-default.json +205 -0
  45. package/entities/Certificate/mockdatafiles/getDomainInformationByCertificateId-default.json +32 -0
  46. package/entities/Certificate/schema.json +43 -0
  47. package/entities/Countries/action.json +46 -0
  48. package/entities/Countries/schema.json +20 -0
  49. package/entities/Domains/action.json +696 -0
  50. package/entities/Domains/mockdatafiles/domainsForwardsGet-default.json +12 -0
  51. package/entities/Domains/mockdatafiles/getAgreement-default.json +8 -0
  52. package/entities/Domains/mockdatafiles/listDomains-default.json +198 -0
  53. package/entities/Domains/mockdatafiles/recordGet-default.json +24 -0
  54. package/entities/Domains/mockdatafiles/suggest-default.json +11 -0
  55. package/entities/Domains/mockdatafiles/tlds-default.json +14 -0
  56. package/entities/Domains/schema.json +52 -0
  57. package/entities/Notifications/action.json +107 -0
  58. package/entities/Notifications/mockdatafiles/getV2CustomersCustomerIdDomainsNotificationsOptIn-default.json +32 -0
  59. package/entities/Notifications/schema.json +23 -0
  60. package/entities/Orders/action.json +46 -0
  61. package/entities/Orders/schema.json +20 -0
  62. package/entities/Parking/action.json +46 -0
  63. package/entities/Parking/schema.json +20 -0
  64. package/entities/Shoppers/action.json +126 -0
  65. package/entities/Shoppers/schema.json +24 -0
  66. package/entities/Subscriptions/action.json +107 -0
  67. package/entities/Subscriptions/mockdatafiles/productGroups-default.json +10 -0
  68. package/entities/Subscriptions/schema.json +23 -0
  69. package/error.json +190 -0
  70. package/metadata.json +54 -0
  71. package/package.json +82 -0
  72. package/pronghorn.json +15805 -0
  73. package/propertiesDecorators.json +14 -0
  74. package/propertiesSchema.json +1661 -0
  75. package/refs?service=git-upload-pack +0 -0
  76. package/report/adapter-openapi.json +13714 -0
  77. package/report/adapter-openapi.yaml +20419 -0
  78. package/report/adapterInfo.json +10 -0
  79. package/report/creationReport.json +765 -0
  80. package/report/godaddy.json +13714 -0
  81. package/report/updateReport1706477552013.json +120 -0
  82. package/sampleProperties.json +254 -0
  83. package/test/integration/adapterTestBasicGet.js +83 -0
  84. package/test/integration/adapterTestConnectivity.js +142 -0
  85. package/test/integration/adapterTestIntegration.js +2925 -0
  86. package/test/unit/adapterBaseTestUnit.js +1024 -0
  87. package/test/unit/adapterTestUnit.js +4900 -0
  88. package/utils/adapterInfo.js +206 -0
  89. package/utils/addAuth.js +94 -0
  90. package/utils/artifactize.js +146 -0
  91. package/utils/basicGet.js +50 -0
  92. package/utils/checkMigrate.js +63 -0
  93. package/utils/entitiesToDB.js +179 -0
  94. package/utils/findPath.js +74 -0
  95. package/utils/methodDocumentor.js +273 -0
  96. package/utils/modify.js +152 -0
  97. package/utils/packModificationScript.js +35 -0
  98. package/utils/patches2bundledDeps.js +90 -0
  99. package/utils/pre-commit.sh +32 -0
  100. package/utils/removeHooks.js +20 -0
  101. package/utils/setup.js +33 -0
  102. package/utils/taskMover.js +309 -0
  103. package/utils/tbScript.js +239 -0
  104. package/utils/tbUtils.js +489 -0
  105. package/utils/testRunner.js +298 -0
  106. package/utils/troubleshootingAdapter.js +193 -0
@@ -0,0 +1,489 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+
3
+ /* eslint import/no-extraneous-dependencies: warn */
4
+ /* eslint global-require: warn */
5
+ /* eslint import/no-dynamic-require: warn */
6
+ /* eslint-disable no-console */
7
+
8
+ const path = require('path');
9
+ const cp = require('child_process');
10
+ const fs = require('fs-extra');
11
+
12
+ module.exports = {
13
+ SERVICE_CONFIGS_COLLECTION: 'service_configs',
14
+ IAP_PROFILES_COLLECTION: 'iap_profiles',
15
+
16
+ /**
17
+ * @summary update newConnection properties in adapter config
18
+ *
19
+ * @function updateNewConnection
20
+ * @param {Object} config - adaper configuration object required by IAP
21
+ * @param {Object} newConnection - connection related property collection from user
22
+ */
23
+ updateNewConnection: (config, newConnection) => {
24
+ const updatedConfig = JSON.parse(JSON.stringify(config));
25
+ Object.keys(newConnection).forEach((key) => {
26
+ updatedConfig.properties.properties[key] = newConnection[key];
27
+ });
28
+ return updatedConfig;
29
+ },
30
+
31
+ /**
32
+ * @summary assemble heathcheck endpoint into an URL
33
+ *
34
+ * @function getHealthCheckEndpointURL
35
+ * @param {Object} endpoint - user updated healthcheck endpoint object
36
+ * @param {Object} config - adaper configuration object required by IAP
37
+ */
38
+ getHealthCheckEndpointURL: (endpoint, config) => {
39
+ const p = config.properties.properties;
40
+ const healthCheckEndpointURL = `${p.protocol}://${p.host}${p.base_path}${p.version}${endpoint.healthCheckEndpoint}`;
41
+ console.log({ healthCheckEndpointURL });
42
+ return healthCheckEndpointURL;
43
+ },
44
+
45
+ /**
46
+ * @summary persist healthcheck endpoint when user make update
47
+ *
48
+ * @function updateHealthCheckEndpoint
49
+ * @param {Object} newHealthCheckEndpoint - user confirmed healthcheck object
50
+ * @param {Object} healthCheckEndpoint - existing healthcheck object
51
+ * @param {Object} healthcheck - ./entities/.system/action.json object
52
+ */
53
+ updateHealthCheckEndpoint: (newHealthCheckEndpoint, healthCheckEndpoint, healthcheck) => {
54
+ if (newHealthCheckEndpoint.healthCheckEndpoint !== healthCheckEndpoint.healthCheckEndpoint) {
55
+ const p = healthcheck.actions[1].entitypath;
56
+ const newEntitypath = p.slice(0, 21) + newHealthCheckEndpoint.healthCheckEndpoint + p.slice(p.length - 8);
57
+ const updatedHealthcheck = JSON.parse(JSON.stringify(healthcheck));
58
+ updatedHealthcheck.actions[1].entitypath = newEntitypath;
59
+ console.log('updating healthcheck setting');
60
+ fs.writeFileSync('./entities/.system/action.json', JSON.stringify(updatedHealthcheck, null, 2));
61
+ }
62
+ },
63
+
64
+ /**
65
+ * @summary update authentication property given new input value from user
66
+ * compare values from auth and newAuth, if there's difference
67
+ * update adapter config
68
+ * @function updateAuth
69
+ * @param {Object} newAuth - user confirmed authentication object
70
+ * @param {Object} auth - existing authentication object
71
+ * @param {Object} config - adaper configuration object required by IAP
72
+ */
73
+ updateAuth: (newAuth, auth, config) => {
74
+ const updatedConfig = JSON.parse(JSON.stringify(config));
75
+ if (Object.keys(newAuth).every((key) => newAuth[key] === auth[key])) {
76
+ return config;
77
+ }
78
+ Object.keys(newAuth).forEach((key) => {
79
+ updatedConfig.properties.properties.authentication[key] = newAuth[key];
80
+ });
81
+ console.log(updatedConfig.properties.properties.authentication);
82
+ return updatedConfig;
83
+ },
84
+
85
+ /**
86
+ * @summary add mark current auth_method with `(current)`
87
+ *
88
+ * @function getDisplayAuthOptions
89
+ * @param {String} currentAuth - current auth method in adapter config
90
+ * @param {Array} authOptions - available auth method
91
+ */
92
+ getDisplayAuthOptions: (currentAuth, authOptions) => {
93
+ const displayAuthOptions = JSON.parse(JSON.stringify(authOptions));
94
+ displayAuthOptions[authOptions.indexOf(currentAuth)] += ' (current)';
95
+ return displayAuthOptions;
96
+ },
97
+
98
+ /**
99
+ * @summary decrypt IAP properties
100
+ * code from pronghorn-core/migration_scripts/installService.js
101
+ *
102
+ * @function decryptProperties
103
+ */
104
+ decryptProperties: (props, iapDir) => {
105
+ const { PropertyEncryption } = require(path.join(iapDir, 'node_modules/@itential/itential-utils'));
106
+ const propertyEncryption = new PropertyEncryption({
107
+ algorithm: 'aes-256-ctr',
108
+ key: 'TG9uZ0Rpc3RhbmNlUnVubmVyUHJvbmdob3JuCg==',
109
+ encoding: 'utf-8'
110
+ });
111
+ return propertyEncryption.decryptProps(props);
112
+ },
113
+
114
+ /**
115
+ * @summary create connection object for verification
116
+ *
117
+ * @function getConnection
118
+ * @param {Object} props - adapter config.properties
119
+ */
120
+ getConnection: (props) => {
121
+ const connection = {
122
+ host: props.properties.host,
123
+ base_path: props.properties.base_path,
124
+ protocol: props.properties.protocol,
125
+ version: props.properties.version,
126
+ port: props.properties.port
127
+ };
128
+ return connection;
129
+ },
130
+
131
+ /**
132
+ * @summary update connection properties based on user answer
133
+ *
134
+ * @function getNewProps
135
+ * @param {Array} answers - values collected from CLI
136
+ * @param {Object} connection - connection property verified by user
137
+ */
138
+ getNewProps: (answers, connection) => {
139
+ if (answers.every((answer) => answer === '')) {
140
+ return connection;
141
+ }
142
+ const newConnection = {};
143
+ const properties = Object.keys(connection);
144
+ for (let i = 0; i < answers.length; i += 1) {
145
+ if (answers[i]) {
146
+ newConnection[properties[i]] = Number.isNaN(Number(answers[i])) ? answers[i] : Number(answers[i]);
147
+ } else {
148
+ newConnection[properties[i]] = connection[properties[i]];
149
+ }
150
+ }
151
+ return newConnection;
152
+ },
153
+
154
+ /**
155
+ * @summary extract endpoint string from healthcheck object
156
+ *
157
+ * @function getHealthCheckEndpoint
158
+ * @param {Object} healthcheck - {Object} healthcheck - ./entities/.system/action.json object
159
+ */
160
+ getHealthCheckEndpoint: (healthcheck) => {
161
+ const endpoint = healthcheck.actions[1].entitypath.slice(21, healthcheck.actions[1].entitypath.length - 8);
162
+ return { healthCheckEndpoint: endpoint };
163
+ },
164
+
165
+ /**
166
+ * @summary Verify that the adapter is in the correct directory
167
+ * - Within IAP
168
+ * - In node_modules/@ namespace
169
+ * verify the adapter is installed under node_modules/
170
+ * and is consistent with the name property of package.json
171
+ * and the node_modules/ is in the correct path within IAP
172
+ * @param {String} dirname - current path
173
+ * @param {String} name - name property from package.json
174
+ */
175
+ verifyInstallationDir: (dirname, name) => {
176
+ const pathArray = dirname.split(path.sep);
177
+ const expectedPath = `node_modules/${name}`;
178
+ const currentPath = pathArray.slice(pathArray.length - 3, pathArray.length).join('/');
179
+ if (currentPath.trim() !== expectedPath.trim()) {
180
+ throw new Error(`adapter should be installed under ${expectedPath} but is installed under ${currentPath}`);
181
+ }
182
+
183
+ const serverFile = path.join(dirname, '../../../', 'server.js');
184
+ if (!fs.existsSync(serverFile)) {
185
+ throw new Error(`adapter should be installed under IAP/${expectedPath}`);
186
+ }
187
+ console.log(`adapter correctly installed at ${currentPath}`);
188
+ },
189
+
190
+ /**
191
+ * @summary execute command and preserve the output the same as run command in shell
192
+ *
193
+ * @function systemSync
194
+ * @param {String} cmd - Command to execute
195
+ * @param {boolean} process - Whether stdout should be processed and returned
196
+ */
197
+ systemSync: function systemSync(cmd, process) {
198
+ if (process) {
199
+ let stdout;
200
+ try {
201
+ stdout = cp.execSync(cmd).toString();
202
+ } catch (error) {
203
+ console.log('execute command error', error.stdout.toString(), error.stderr.toString());
204
+ stdout = error.stdout.toString();
205
+ }
206
+ const output = this.getTestCount(stdout);
207
+ output.stdout = stdout;
208
+ return output;
209
+ }
210
+ try {
211
+ return cp.execSync(cmd, { stdio: 'inherit' });
212
+ } catch (error) {
213
+ return console.error(error.stdout);
214
+ }
215
+ },
216
+
217
+ /**
218
+ * @summary parses a string and returns the number parsed from startIndex backwards
219
+ *
220
+ * @function parseNum
221
+ * @param {String} inputStr - Any String
222
+ * @param {Number} startIndex - Index to begin parsing
223
+ */
224
+ parseNum: function parseNum(inputStr, startIndex) {
225
+ let count = '';
226
+ let currChar;
227
+ let start = startIndex;
228
+ while (currChar !== ' ') {
229
+ currChar = inputStr.charAt(start);
230
+ count = currChar + count;
231
+ start -= 1;
232
+ }
233
+ return parseInt(count, 10);
234
+ },
235
+
236
+ /**
237
+ * @summary Parses a mocha test result and returns the count of passing and failing tests
238
+ *
239
+ * @function getTestCount
240
+ * @param {String} testStr - Output from mocha test
241
+ */
242
+ getTestCount: function getTestCount(testStr) {
243
+ const passIndex = testStr.search('passing');
244
+ const failIndex = testStr.search('failing');
245
+ const passCount = passIndex >= 0 ? this.parseNum(testStr, passIndex - 2) : 0;
246
+ const failCount = failIndex >= 0 ? this.parseNum(testStr, failIndex - 2) : 0;
247
+ return { passCount, failCount };
248
+ },
249
+
250
+ /**
251
+ * @summary remove package-lock.json and node_modules directory if exists
252
+ * run npm install and print result to stdout
253
+ */
254
+ npmInstall: function npmInstall() {
255
+ fs.removeSync('../package-lock.json');
256
+ fs.removeSync('../node_modules/');
257
+ console.log('Run npm install ...');
258
+ this.systemSync('npm install');
259
+ },
260
+
261
+ /**
262
+ * @summary run lint, unit test and integration test
263
+ * print result to stdout
264
+ */
265
+ runTest: function runTest() {
266
+ this.systemSync('npm run lint:errors');
267
+ this.systemSync('npm run test:unit');
268
+ this.systemSync('npm run test:integration');
269
+ },
270
+
271
+ /**
272
+ * @summary run basicget with mocha
273
+ * @param {boolean} scriptFlag - whether the function is ran from a script
274
+ * print result to stdout
275
+ * returns mocha test results otherwise
276
+ */
277
+ runBasicGet: function runBasicGet(scriptFlag) {
278
+ const testPath = path.resolve(__dirname, '..', 'test/integration/adapterTestBasicGet.js');
279
+ return this.systemSync(`mocha ${testPath} --exit`, !scriptFlag);
280
+ },
281
+
282
+ /**
283
+ * @summary run connectivity with mocha
284
+ * @param {String} host - Host url to run healthcheck
285
+ * @param {boolean} scriptFlag - Whether the function is ran from a script
286
+ * print result to stdout if ran from script
287
+ * returns mocha test results otherwise
288
+ */
289
+ runConnectivity: function runConnectivity(host, scriptFlag) {
290
+ let testPath = 'test/integration/adapterTestConnectivity.js';
291
+ let executable = 'mocha';
292
+ if (!scriptFlag) {
293
+ testPath = path.resolve(__dirname, '..', testPath);
294
+ executable = path.join(__dirname, '..', 'node_modules/mocha/bin/mocha');
295
+ }
296
+ return this.systemSync(`${executable} ${testPath} --HOST=${host} --timeout 10000 --exit`, !scriptFlag);
297
+ },
298
+
299
+ /**
300
+ * @summary create Adapter property
301
+ *
302
+ * @function createAdapter
303
+ * @param {Object} pronghornProps - decrypted 'properties.json' from IAP root directory
304
+ * @param {Object} profileItem - pronghorn props saved in database
305
+ * @param {Object} adapterPronghorn - ./pronghorn.json in adapter dir
306
+ * @param {Object} sampleProperties - './sampleProperties.json' in adapter dir
307
+ */
308
+ createAdapter: function createAdapter(pronghornProps, profileItem, sampleProperties, adapterPronghorn) {
309
+ const iapDir = this.getIAPHome();
310
+ const packageFile = path.join(iapDir, 'package.json');
311
+ const info = JSON.parse(fs.readFileSync(packageFile));
312
+ const version = parseInt(info.version.split('.')[0], 10);
313
+
314
+ let adapter = {};
315
+ if (version >= 2020) {
316
+ adapter = {
317
+ isEncrypted: pronghornProps.pathProps.encrypted,
318
+ model: adapterPronghorn.id,
319
+ name: sampleProperties.id,
320
+ type: adapterPronghorn.type,
321
+ properties: sampleProperties,
322
+ loggerProps: profileItem.loggerProps
323
+ };
324
+ } else {
325
+ adapter = {
326
+ mongoProps: pronghornProps.mongoProps,
327
+ isEncrypted: pronghornProps.pathProps.encrypted,
328
+ model: adapterPronghorn.id,
329
+ name: sampleProperties.id,
330
+ type: adapterPronghorn.type,
331
+ properties: sampleProperties,
332
+ redisProps: profileItem.redisProps,
333
+ loggerProps: profileItem.loggerProps,
334
+ rabbitmq: profileItem.rabbitmq
335
+ };
336
+ adapter.mongoProps.pdb = true;
337
+ }
338
+
339
+ adapter.loggerProps.log_filename = `adapter-${adapter.name}.log`;
340
+ return adapter;
341
+ },
342
+
343
+ getPronghornProps: function getPronghornProps() {
344
+ const iapDir = this.getIAPHome();
345
+ console.log('Retrieving properties.json file...');
346
+ const rawProps = require(path.join(iapDir, 'properties.json'));
347
+ console.log('Decrypting properties...');
348
+ const pronghornProps = this.decryptProperties(rawProps, iapDir);
349
+ console.log('Found properties.\n');
350
+ return pronghornProps;
351
+ },
352
+
353
+ getAllAdapterInstances: async function getAllAdapterInstances() {
354
+ const database = await this.getIAPDatabaseConnection();
355
+ const { name } = require(path.join(__dirname, '..', 'package.json'));
356
+ const query = { model: name };
357
+ const options = { projection: { name: 1 } };
358
+ const adapterInstancesNames = await database.collection(this.SERVICE_CONFIGS_COLLECTION).find(
359
+ query,
360
+ options
361
+ ).toArray();
362
+ return adapterInstancesNames;
363
+ },
364
+
365
+ // get database connection and existing adapter config
366
+ getAdapterConfig: async function getAdapterConfig(adapterId) {
367
+ const database = await this.getIAPDatabaseConnection();
368
+ const { name } = require(path.join(__dirname, '..', 'package.json'));
369
+ let query = {};
370
+ if (!adapterId) {
371
+ query = { model: name };
372
+ } else {
373
+ query = { _id: adapterId };
374
+ }
375
+ const serviceItem = await database.collection(this.SERVICE_CONFIGS_COLLECTION).findOne(
376
+ query
377
+ );
378
+ const pronghornProps = await this.getPronghornProps();
379
+ return { database, serviceItem, pronghornProps };
380
+ },
381
+
382
+ /**
383
+ * @summary return async healthcheck result as a Promise
384
+ *
385
+ * @function request
386
+ * @param {Adapter} a - Adapter instance
387
+ */
388
+ request: function request(a) {
389
+ return new Promise((resolve, reject) => {
390
+ a.healthCheck(null, (data) => {
391
+ if (!data) reject(new Error('healthCheckEndpoint failed'));
392
+ resolve(data);
393
+ });
394
+ });
395
+ },
396
+
397
+ /**
398
+ * @summary deal with healthcheck response returned from adapter instace
399
+ *
400
+ * @function healthCheck
401
+ * @param {Adapter} a - Adapter instance
402
+ */
403
+ healthCheck: async function healthCheck(a) {
404
+ const result = await this.request(a)
405
+ .then((res) => {
406
+ console.log('healthCheckEndpoint OK');
407
+ return res;
408
+ })
409
+ .catch((error) => {
410
+ console.error(error.message);
411
+ return false;
412
+ });
413
+ return result;
414
+ },
415
+
416
+ /**
417
+ * @summary Obtain the IAP installation directory depending on how adapter is used:
418
+ * by IAP, or by npm run CLI interface
419
+ * @returns IAP installation directory or null if adapter running without IAP
420
+ * @function getIAPHome
421
+ */
422
+ getIAPHome: function getIAPHome() {
423
+ let IAPHomePath = null;
424
+ // check if adapter started via IAP, use path injected by core
425
+ if (process.env.iap_home) IAPHomePath = process.env.iap_home;
426
+ // check if adapter started via CLI `npm run <command>` so we have to be located under
427
+ // <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ directory
428
+ const currentExecutionPath = this.getCurrentExecutionPath();
429
+ if (currentExecutionPath.indexOf('/node_modules') >= 0) {
430
+ [IAPHomePath] = currentExecutionPath.split('/node_modules');
431
+ }
432
+ return IAPHomePath;
433
+ },
434
+
435
+ /**
436
+ * @summary get current execution path without resolving symbolic links,
437
+ * use `pwd` command wihout '-P' option (resolving symlinks) https://linux.die.net/man/1/pwd
438
+ * @returns
439
+ * @function getCurrentExecutionPAth
440
+ */
441
+ getCurrentExecutionPath: function getCurrentExecutionPAth() {
442
+ const { stdout } = this.systemSync('pwd', true);
443
+ return stdout.trim();
444
+ },
445
+
446
+ /**
447
+ * @summary checks if command executed from <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ location
448
+ * @returns true if command executed under <IAP_HOME>/node_modules/@itentialopensource/<adapter_name>/ path
449
+ * @function areWeUnderIAPinstallationDirectory
450
+ */
451
+ areWeUnderIAPinstallationDirectory: function areWeUnderIAPinstallationDirectory() {
452
+ return path.join(this.getCurrentExecutionPath(), '../../..') === this.getIAPHome();
453
+ },
454
+
455
+ getIAPDatabaseConnection: async function getIAPDatabaseConnection() {
456
+ const pronghornProps = await this.getPronghornProps();
457
+ const database = await this.connect(pronghornProps);
458
+ return database;
459
+ },
460
+
461
+ /**
462
+ * @summary connect to mongodb
463
+ *
464
+ * @function connect
465
+ * @param {Object} properties - pronghornProps
466
+ */
467
+ connect: async function connect(properties) {
468
+ let dbConnectionProperties = {};
469
+ if (properties.mongoProps) {
470
+ dbConnectionProperties = properties.mongoProps;
471
+ } else if (properties.mongo) {
472
+ if (properties.mongo.url) {
473
+ dbConnectionProperties.url = properties.mongo.url;
474
+ } else {
475
+ dbConnectionProperties.url = `mongodb://${properties.mongo.host}:${properties.mongo.port}`;
476
+ }
477
+ dbConnectionProperties.db = properties.mongo.database;
478
+ }
479
+ if (!dbConnectionProperties.url || !dbConnectionProperties.db) {
480
+ throw new Error('Mongo properties are not specified in IAP configuration!');
481
+ }
482
+ const iapDir = this.getIAPHome();
483
+ const { MongoDBConnection } = require(path.join(iapDir, 'node_modules/@itential/database'));
484
+ const connection = new MongoDBConnection(dbConnectionProperties);
485
+ const database = await connection.connect(true);
486
+ return database;
487
+ }
488
+
489
+ };