@itentialopensource/adapter-f5_bigiq 0.5.7 → 0.6.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 (55) hide show
  1. package/.eslintrc.js +1 -0
  2. package/AUTH.md +4 -4
  3. package/BROKER.md +4 -4
  4. package/CALLS.md +621 -9
  5. package/ENHANCE.md +3 -3
  6. package/PROPERTIES.md +24 -9
  7. package/README.md +24 -23
  8. package/SUMMARY.md +2 -2
  9. package/SYSTEMINFO.md +1 -1
  10. package/TAB1.md +2 -2
  11. package/TAB2.md +9 -5
  12. package/TROUBLESHOOT.md +10 -1
  13. package/UTILITIES.md +473 -0
  14. package/adapter.js +11315 -5
  15. package/adapterBase.js +52 -16
  16. package/entities/BIGIPAuthentication/action.json +106 -0
  17. package/entities/BIGIPAuthentication/schema.json +23 -0
  18. package/entities/BIGIPConfigurationManagement/action.json +310 -0
  19. package/entities/BIGIPConfigurationManagement/schema.json +33 -0
  20. package/entities/BIGIPLocalTrafficManager/action.json +1042 -0
  21. package/entities/BIGIPLocalTrafficManager/schema.json +69 -0
  22. package/entities/BIGIPNetwork/action.json +432 -0
  23. package/entities/BIGIPNetwork/schema.json +39 -0
  24. package/entities/BIGIPSystem/action.json +209 -0
  25. package/entities/BIGIPSystem/schema.json +28 -0
  26. package/package.json +24 -28
  27. package/pronghorn.json +5973 -13
  28. package/propertiesSchema.json +68 -7
  29. package/report/adapterInfo.json +8 -8
  30. package/report/auto-adapter-openapi.json +20632 -0
  31. package/report/updateReport1748555375038.json +120 -0
  32. package/sampleProperties.json +4 -0
  33. package/test/integration/adapterTestBasicGet.js +88 -54
  34. package/test/integration/adapterTestConnectivity.js +15 -16
  35. package/test/integration/adapterTestIntegration.js +2597 -38
  36. package/test/unit/adapterBaseTestUnit.js +641 -39
  37. package/test/unit/adapterTestUnit.js +4822 -61
  38. package/utils/adapterInfo.js +114 -164
  39. package/utils/argParser.js +44 -0
  40. package/utils/checkMigrate.js +77 -38
  41. package/utils/entitiesToDB.js +53 -42
  42. package/utils/logger.js +26 -0
  43. package/utils/modify.js +56 -55
  44. package/utils/mongoDbConnection.js +79 -0
  45. package/utils/mongoUtils.js +162 -0
  46. package/utils/taskMover.js +31 -32
  47. package/utils/tbScript.js +36 -172
  48. package/utils/tbUtils.js +84 -226
  49. package/utils/troubleshootingAdapter.js +68 -84
  50. package/utils/updateAdapterConfig.js +158 -0
  51. package/utils/addAuth.js +0 -94
  52. package/utils/artifactize.js +0 -146
  53. package/utils/basicGet.js +0 -50
  54. package/utils/packModificationScript.js +0 -35
  55. package/utils/patches2bundledDeps.js +0 -90
@@ -6,10 +6,8 @@
6
6
 
7
7
  const path = require('path');
8
8
  const rls = require('readline-sync');
9
- const fs = require('fs-extra');
10
9
 
11
- const utils = require(path.join(__dirname, 'tbUtils'));
12
- const basicGet = require(path.join(__dirname, 'basicGet'));
10
+ const tbUtils = require(path.join(__dirname, 'tbUtils'));
13
11
  const { name } = require(path.join(__dirname, '..', 'package.json'));
14
12
  const sampleProperties = require(path.join(__dirname, '..', 'sampleProperties.json'));
15
13
 
@@ -21,7 +19,7 @@ const collectAnswersSync = (questions, props) => {
21
19
  const answer = rls.question(q);
22
20
  answers.push(answer);
23
21
  });
24
- return utils.getNewProps(answers, props);
22
+ return tbUtils.getNewProps(answers, props);
25
23
  };
26
24
 
27
25
  // change object into array of questions
@@ -33,7 +31,7 @@ const confirm = (props) => {
33
31
  // allow user to change auth_method
34
32
  const confirmAuthOptions = (authentication) => {
35
33
  const authOptions = ['basic user_password', 'request_token', 'static_token', 'no_authentication'];
36
- const displayAuthOptions = utils.getDisplayAuthOptions(authentication.auth_method, authOptions);
34
+ const displayAuthOptions = tbUtils.getDisplayAuthOptions(authentication.auth_method, authOptions);
37
35
  const index = rls.keyInSelect(displayAuthOptions, 'Which authentication?');
38
36
  if (index === -1) {
39
37
  return authentication.auth_method;
@@ -45,7 +43,7 @@ const confirmAuthOptions = (authentication) => {
45
43
  // helper function to update auth properties
46
44
  const confirmAndUpdate = (auth, config) => {
47
45
  const newAuth = confirm(auth);
48
- return utils.updateAuth(newAuth, auth, config);
46
+ return tbUtils.updateAuth(newAuth, auth, config);
49
47
  };
50
48
 
51
49
  // extract basic auth properties
@@ -69,34 +67,40 @@ const updateStaticAuth = (config, authentication) => {
69
67
 
70
68
  // troubleshooting connection and healthcheck endpoint setting of adapter
71
69
  const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
72
- // Updates connectivity params and runs connectivity
73
70
  let connConfig;
74
71
  const result = {};
72
+
75
73
  if (scriptFlag) {
76
- const connection = utils.getConnection(serviceItem.properties);
74
+ const connection = tbUtils.getConnection(serviceItem.properties);
77
75
  const newConnection = confirm(connection);
78
- utils.runConnectivity(newConnection.host, scriptFlag);
79
- connConfig = utils.updateNewConnection(serviceItem, newConnection);
76
+ tbUtils.runConnectivity(newConnection.host, scriptFlag);
77
+ connConfig = tbUtils.updateNewConnection(serviceItem, newConnection);
80
78
  } else {
81
79
  let { properties: { properties: { host } } } = serviceItem;
80
+
81
+ connConfig = props.connProps
82
+ ? tbUtils.updateNewConnection(serviceItem, props.connProps)
83
+ : serviceItem;
84
+
82
85
  if (props.connProps) {
83
- connConfig = utils.updateNewConnection(serviceItem, props.connProps);
84
86
  host = connConfig.properties.properties.host;
85
- } else {
86
- connConfig = serviceItem;
87
87
  }
88
- result.connectivity = utils.runConnectivity(host, scriptFlag);
88
+
89
+ result.connectivity = tbUtils.runConnectivity(host, scriptFlag);
89
90
  }
90
- // Updates the healthcheck endpoing
91
- const healthcheck = require('../entities/.system/action.json');
92
- const healthCheckEndpoint = utils.getHealthCheckEndpoint(healthcheck);
91
+
92
+ // Updates the healthcheck endpoint
93
+ const healthcheck = require(path.resolve(__dirname, '../entities/.system/action.json'));
94
+ const healthCheckEndpoint = tbUtils.getHealthCheckEndpoint(healthcheck);
93
95
  let newHealthCheckEndpoint = healthCheckEndpoint;
96
+
94
97
  if (scriptFlag) {
95
98
  newHealthCheckEndpoint = confirm(healthCheckEndpoint);
96
- utils.getHealthCheckEndpointURL(newHealthCheckEndpoint, connConfig);
99
+ tbUtils.getHealthCheckEndpointURL(newHealthCheckEndpoint, connConfig);
97
100
  } else if (props.healthCheckEndpoint) {
98
101
  newHealthCheckEndpoint = props.healthCheckEndpoint;
99
102
  }
103
+
100
104
  // Updates the authorization params
101
105
  const { authentication } = connConfig.properties.properties;
102
106
  let updatedAdapter = connConfig;
@@ -110,84 +114,64 @@ const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
110
114
  console.log('current troubleshooting script does not support updating request_token authentication');
111
115
  }
112
116
  } else if (props.auth) {
113
- updatedAdapter = utils.updateAuth(props.auth, authentication, connConfig);
117
+ updatedAdapter = tbUtils.updateAuth(props.auth, authentication, connConfig);
114
118
  }
115
- // Writes the new healthcheck endpoint into action.json
116
- utils.updateHealthCheckEndpoint(newHealthCheckEndpoint, healthCheckEndpoint, healthcheck);
117
119
  return { result, updatedAdapter };
118
120
  };
119
121
 
120
- const offline = async () => {
121
- console.log('Start offline troubleshooting');
122
- const { updatedAdapter } = VerifyHealthCheckEndpoint({ properties: sampleProperties }, {}, true);
123
- const a = basicGet.getAdapterInstance(updatedAdapter);
124
- const res = await utils.healthCheck(a);
125
- if (!res) {
126
- console.log('run `npm run troubleshoot` again to update settings');
127
- process.exit(0);
128
- }
129
- console.log('Save changes to sampleProperties.json');
130
- await fs.writeFile('sampleProperties.json', JSON.stringify(updatedAdapter.properties, null, 2));
131
- if (rls.keyInYN('Test with more GET request')) {
132
- await utils.runBasicGet(true);
133
- }
134
- };
135
-
136
- const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
122
+ const troubleshoot = async (props, scriptFlag, adapter) => {
137
123
  let serviceItem;
124
+
138
125
  if (adapter && adapter.allProps) {
139
126
  serviceItem = { properties: { properties: adapter.allProps } };
140
- }
141
- if (adapter && adapter.properties && adapter.properties.properties) {
127
+ } else if (adapter && adapter.properties && adapter.properties.properties) {
142
128
  serviceItem = adapter.properties;
129
+ } else {
130
+ serviceItem = { properties: sampleProperties };
131
+ }
132
+
133
+ if (!serviceItem) {
134
+ console.log(`${name} not installed`);
135
+ console.log('run `npm run install:adapter` to install current adapter to IAP first. Exiting...');
136
+ if (scriptFlag) {
137
+ process.exit(1);
138
+ }
139
+ return null;
140
+ }
141
+
142
+ const shouldRun = !scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`);
143
+ if (!shouldRun) {
144
+ console.log('You can update healthCheckEndpoint in ./entities/.system/action.json');
145
+ console.log('You can update authentication credientials under Settings/Services');
146
+ if (scriptFlag) {
147
+ process.exit(0);
148
+ }
149
+ return null;
150
+ }
151
+
152
+ const { result, updatedAdapter } = VerifyHealthCheckEndpoint(serviceItem, props, scriptFlag);
153
+ const a = scriptFlag ? tbUtils.getAdapterInstance(updatedAdapter) : adapter;
154
+
155
+ const healthRes = await tbUtils.healthCheck(a);
156
+ result.healthCheck = healthRes;
157
+
158
+ if (scriptFlag && !healthRes) {
159
+ console.log('run `npm run troubleshoot` again to update settings');
160
+ process.exit(1);
143
161
  }
144
- if (serviceItem) {
145
- if (!scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`)) {
146
- const { result, updatedAdapter } = VerifyHealthCheckEndpoint(serviceItem, props, scriptFlag);
147
- let a;
148
- if (scriptFlag) {
149
- a = basicGet.getAdapterInstance(updatedAdapter);
150
- } else {
151
- a = adapter;
152
- }
153
- const healthRes = await utils.healthCheck(a);
154
- result.healthCheck = healthRes;
155
- if (scriptFlag && !healthRes) {
156
- console.log('run `npm run troubleshoot` again to update settings');
157
- process.exit(0);
158
- }
159
-
160
- if (persistFlag && healthRes) {
161
- const { database } = await utils.getIAPDatabaseConnection();
162
- const update = { $set: { properties: updatedAdapter.properties } };
163
- await database.collection(utils.SERVICE_CONFIGS_COLLECTION).updateOne({ model: name }, update);
164
- if (scriptFlag) {
165
- console.log(`${name} updated.`);
166
- }
167
- }
168
- if (scriptFlag) {
169
- if (rls.keyInYN('Test with more GET request')) {
170
- await utils.runBasicGet(scriptFlag);
171
- process.exit(0);
172
- } else {
173
- console.log('Exiting');
174
- process.exit(0);
175
- }
176
- } else {
177
- result.basicGet = await utils.runBasicGet(scriptFlag);
178
- return result;
179
- }
162
+
163
+ if (scriptFlag) {
164
+ if (rls.keyInYN('Test with more GET request')) {
165
+ await tbUtils.runBasicGet(serviceItem.properties.properties, true);
180
166
  } else {
181
- console.log('You can update healthCheckEndpoint in ./entities/.system/action.json');
182
- console.log('You can update authentication credientials under Settings/Services');
183
167
  console.log('Exiting');
184
- process.exit(0);
185
168
  }
186
- } else {
187
- console.log(`${name} not installed`);
188
- console.log('run `npm run install:adapter` to install current adapter to IAP first. Exiting...');
169
+ process.exit(0);
189
170
  }
190
- return null;
171
+
172
+ result.basicGet = await tbUtils.runBasicGet(serviceItem.properties.properties, false);
173
+
174
+ return result;
191
175
  };
192
176
 
193
- module.exports = { troubleshoot, offline };
177
+ module.exports = { troubleshoot };
@@ -0,0 +1,158 @@
1
+ /* @copyright Itential, LLC 2025 */
2
+
3
+ // Set globals
4
+ /* global log */
5
+
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
9
+ const MongoDBConnection = require('./mongoDbConnection');
10
+
11
+ const propUtil = new PropUtilCl();
12
+
13
+ /**
14
+ * Updates action configuration in the document
15
+ * @param {Object} doc - Document to update
16
+ * @param {string} action - Action name
17
+ * @param {Object} changes - Changes to apply
18
+ * @returns {Object} Updated document
19
+ */
20
+ function updateActionConfig(doc, action, changes) {
21
+ const updateDoc = { ...doc };
22
+ if (!updateDoc.actions) updateDoc.actions = [];
23
+ const actionIndex = updateDoc.actions.findIndex((a) => a.name === action);
24
+ if (actionIndex >= 0) {
25
+ updateDoc.actions[actionIndex] = propUtil.mergeProperties(changes, updateDoc.actions[actionIndex]);
26
+ } else {
27
+ updateDoc.actions.push({ name: action, ...changes });
28
+ }
29
+ return updateDoc;
30
+ }
31
+
32
+ /**
33
+ * Updates schema configuration in the document
34
+ * @param {Object} doc - Document to update
35
+ * @param {string} configFile - Configuration file name
36
+ * @param {Object} changes - Changes to apply
37
+ * @returns {Object} Updated document
38
+ */
39
+ function updateSchemaConfig(doc, configFile, changes) {
40
+ const updateDoc = { ...doc };
41
+ if (!updateDoc.schema) updateDoc.schema = [];
42
+ const schemaIndex = updateDoc.schema.findIndex((s) => s.name === configFile);
43
+ if (schemaIndex >= 0) {
44
+ updateDoc.schema[schemaIndex].schema = propUtil.mergeProperties(changes, updateDoc.schema[schemaIndex].schema);
45
+ } else {
46
+ updateDoc.schema.push({ name: configFile, schema: changes });
47
+ }
48
+ return updateDoc;
49
+ }
50
+
51
+ /**
52
+ * Updates mock data configuration in the document
53
+ * @param {Object} doc - Document to update
54
+ * @param {string} configFile - Configuration file name
55
+ * @param {Object} changes - Changes to apply
56
+ * @param {boolean} replace - Whether to replace or merge
57
+ * @returns {Object} Updated document
58
+ */
59
+ function updateMockConfig(doc, configFile, changes, replace) {
60
+ const updateDoc = { ...doc };
61
+ if (!updateDoc.mockdatafiles) updateDoc.mockdatafiles = {};
62
+ updateDoc.mockdatafiles[configFile] = replace ? changes : propUtil.mergeProperties(changes, updateDoc.mockdatafiles[configFile] || {});
63
+ return updateDoc;
64
+ }
65
+
66
+ /**
67
+ * Configuration update strategies for different types
68
+ */
69
+ const updateStrategies = {
70
+ action: (doc, configFile, changes, action) => (!action ? doc : updateActionConfig(doc, action, changes)),
71
+ schema: (doc, configFile, changes) => updateSchemaConfig(doc, configFile, changes),
72
+ mock: (doc, configFile, changes, replace) => updateMockConfig(doc, configFile, changes, replace)
73
+ };
74
+
75
+ /**
76
+ * Updates MongoDB configuration for an adapter entity
77
+ * @param {Object} options - Configuration options
78
+ * @param {string} options.id - Adapter ID
79
+ * @param {Object} options.mongoProps - MongoDB connection properties
80
+ * @param {string} options.entity - Entity name
81
+ * @param {string} options.type - Update type (action/schema/mock)
82
+ * @param {string} options.configFile - Configuration file name
83
+ * @param {Object} options.changes - Changes to apply
84
+ * @param {string} options.action - Action name (for action type updates)
85
+ * @param {boolean} options.replace - Whether to replace or merge (for mock type updates)
86
+ * @returns {Promise<void>}
87
+ */
88
+ async function updateMongoDBConfig(options) {
89
+ const {
90
+ id,
91
+ mongoProps,
92
+ entity,
93
+ type,
94
+ configFile,
95
+ changes,
96
+ action,
97
+ replace
98
+ } = options;
99
+
100
+ if (!mongoProps) {
101
+ log.error('MongoDB properties not found');
102
+ return;
103
+ }
104
+
105
+ let mongoConnection = null;
106
+ try {
107
+ // Get adapter type from pronghorn.json
108
+ const pronghornPath = path.join(__dirname, '../pronghorn.json');
109
+ const pronghornData = JSON.parse(fs.readFileSync(pronghornPath, 'utf8'));
110
+ const adapterType = pronghornData.id;
111
+
112
+ mongoConnection = new MongoDBConnection(mongoProps);
113
+ await mongoConnection.connect();
114
+
115
+ const collection = mongoConnection.db.collection('adapter_configs');
116
+ const query = {
117
+ id,
118
+ type: adapterType,
119
+ entity
120
+ };
121
+
122
+ const existingConfig = await collection.findOne(query);
123
+ if (!existingConfig) {
124
+ log.debug(`No existing configuration found for entity ${entity}`);
125
+ return;
126
+ }
127
+
128
+ // Update the configuration based on type
129
+ const updateStrategy = updateStrategies[type];
130
+ if (!updateStrategy) {
131
+ log.error(`Unsupported update type: ${type}`);
132
+ return;
133
+ }
134
+
135
+ const updatedDoc = updateStrategy(existingConfig, configFile, changes, action || replace);
136
+
137
+ // Remove _id from updateDoc as it can't be modified
138
+ const { _id, ...updateDocWithoutId } = updatedDoc;
139
+ const updateResult = await collection.updateOne(
140
+ { id, type: adapterType, entity },
141
+ { $set: updateDocWithoutId }
142
+ );
143
+
144
+ if (updateResult.modifiedCount === 0) {
145
+ log.warn(`No documents were modified for entity ${entity}`);
146
+ }
147
+ log.info(`Successfully updated MongoDB configuration for entity ${entity}`);
148
+ } catch (error) {
149
+ log.error(`Error updating MongoDB configuration: ${error.message}`);
150
+ throw error;
151
+ } finally {
152
+ if (mongoConnection) {
153
+ await mongoConnection.closeConnection();
154
+ }
155
+ }
156
+ }
157
+
158
+ module.exports = { updateMongoDBConfig };
package/utils/addAuth.js DELETED
@@ -1,94 +0,0 @@
1
- /* eslint-disable no-plusplus */
2
- /* eslint global-require: warn */
3
- /* eslint import/no-dynamic-require: warn */
4
-
5
- const path = require('path');
6
- const fs = require('fs');
7
- const rls = require('readline-sync');
8
-
9
- function getQuestions(props, obj) {
10
- const questions = props.map((p) => `${p}: ${(obj[p] !== undefined) ? `(${obj[p]})` : ''} `);
11
- return questions;
12
- }
13
-
14
- // function outputs each property for user to edit/confirm
15
- // props are the fields that need to be changed depending on what the user selects
16
- // obj is the JSON object that's being updated
17
- function confirm(props, obj) {
18
- // create array of questions
19
- const updatedObj = obj;
20
- getQuestions(props, obj).forEach((q) => {
21
- const answer = rls.question(q);
22
- // only update the field if the answer is NOT and empty string
23
- if (answer) {
24
- updatedObj[q.split(':')[0].trim()] = answer;
25
- }
26
- });
27
- return updatedObj;
28
- }
29
-
30
- const updateBasicAuth = (auth) => {
31
- const propsToUpdate = ['username', 'password', 'auth_field', 'auth_field_format'];
32
- return confirm(propsToUpdate, auth);
33
- };
34
-
35
- const updateStaticTokenAuth = (auth) => {
36
- const propsToUpdate = ['token', 'auth_field', 'auth_field_format'];
37
- return confirm(propsToUpdate, auth);
38
- };
39
-
40
- function updateTokenSchemas(user, pw, token) {
41
- let schemaPath = path.join(__dirname, '..', 'entities/.system/schemaTokenReq.json');
42
- const reqSchema = require(schemaPath);
43
- reqSchema.properties.username.external_name = user;
44
- reqSchema.properties.password.external_name = pw;
45
- fs.writeFileSync(schemaPath, JSON.stringify(reqSchema, null, 2));
46
- schemaPath = path.join(__dirname, '..', 'entities/.system/schemaTokenResp.json');
47
- const respSchema = require(schemaPath);
48
- respSchema.properties.token.external_name = token;
49
- fs.writeFileSync(schemaPath, JSON.stringify(respSchema, null, 2));
50
- }
51
-
52
- function updateRequestToken(auth) {
53
- const propsToUpdate = [
54
- 'username',
55
- 'password',
56
- 'auth_field',
57
- 'auth_field_format',
58
- 'token_user_field',
59
- 'token_password_field',
60
- 'token_result_field',
61
- 'token_URI_path'
62
- ];
63
- const newAuth = confirm(propsToUpdate, auth);
64
- updateTokenSchemas(newAuth.token_user_field, newAuth.token_password_field, newAuth.token_result_field);
65
-
66
- return newAuth;
67
- }
68
-
69
- // prompt users to pick an auth method from the list above
70
- const addAuthInfo = (props) => {
71
- const authOptions = [
72
- 'basic user_password',
73
- 'static_token',
74
- 'request_token',
75
- 'no_authentication'
76
- ];
77
- const newProps = confirm(['host', 'port', 'base_path'], props);
78
-
79
- const newAuthMethod = authOptions[rls.keyInSelect(authOptions, 'Which authentication method?')];
80
- newProps.authentication.auth_method = newAuthMethod;
81
-
82
- if (newAuthMethod === 'basic user_password') {
83
- newProps.authentication = updateBasicAuth(newProps.authentication);
84
- } else if (newAuthMethod === 'static_token') {
85
- newProps.authentication = updateStaticTokenAuth(newProps.authentication);
86
- } else if (newAuthMethod === 'request_token') {
87
- newProps.authentication = updateRequestToken(newProps.authentication);
88
- }
89
- console.log('Connectivity and authentication properties have been configured');
90
- console.log('If you want to make changes, rerun this script to reinstall the adapter');
91
- return newProps;
92
- };
93
-
94
- module.exports = { addAuthInfo };
@@ -1,146 +0,0 @@
1
- #!/usr/bin/env node
2
- /* @copyright Itential, LLC 2019 */
3
-
4
- const path = require('path');
5
- const fs = require('fs-extra');
6
-
7
- async function createBundle(adapterOldDir) {
8
- // set directories
9
- const artifactDir = path.join(adapterOldDir, '../artifactTemp');
10
- const workflowsDir = path.join(adapterOldDir, 'workflows');
11
-
12
- // read adapter's package and set names
13
- const adapterPackage = fs.readJSONSync(path.join(adapterOldDir, 'package.json'));
14
- const originalName = adapterPackage.name.substring(adapterPackage.name.lastIndexOf('/') + 1);
15
- const shortenedName = originalName.replace('adapter-', '');
16
- const artifactName = originalName.replace('adapter', 'bundled-adapter');
17
-
18
- const adapterNewDir = path.join(artifactDir, 'bundles', 'adapters', originalName);
19
- fs.ensureDirSync(adapterNewDir);
20
-
21
- const ops = [];
22
-
23
- // copy old adapterDir to bundled hierarchy location
24
- ops.push(() => fs.copySync(adapterOldDir, adapterNewDir));
25
-
26
- // copy readme
27
- ops.push(() => fs.copySync(path.join(adapterOldDir, 'README.md'), path.join(artifactDir, 'README.md')));
28
-
29
- // copy changelog
30
- if (fs.existsSync(path.join(adapterOldDir, 'CHANGELOG.md'))) {
31
- ops.push(() => fs.copySync(path.join(adapterOldDir, 'CHANGELOG.md'), path.join(artifactDir, 'CHANGELOG.md')));
32
- }
33
-
34
- // copy license
35
- if (fs.existsSync(path.join(adapterOldDir, 'LICENSE'))) {
36
- ops.push(() => fs.copySync(path.join(adapterOldDir, 'LICENSE'), path.join(artifactDir, 'LICENSE')));
37
- }
38
-
39
- // create package
40
- const artifactPackage = {
41
- name: artifactName,
42
- version: adapterPackage.version,
43
- description: `A bundled version of the ${originalName} to be used in adapter-artifacts for easy installation`,
44
- scripts: {
45
- test: 'echo "Error: no test specified" && exit 1',
46
- deploy: 'npm publish --registry=http://registry.npmjs.org'
47
- },
48
- keywords: [
49
- 'IAP',
50
- 'artifacts',
51
- 'Itential',
52
- 'Pronghorn',
53
- 'Adapter',
54
- 'Adapter-Artifacts',
55
- shortenedName
56
- ],
57
- author: 'Itential Artifacts',
58
- license: 'Apache-2.0',
59
- repository: adapterPackage.repository,
60
- private: false,
61
- devDependencies: {
62
- r2: '^2.0.1',
63
- ajv: '6.10.0',
64
- 'better-ajv-errors': '^0.6.1',
65
- 'fs-extra': '^7.0.1'
66
- }
67
- };
68
-
69
- ops.push(() => fs.writeJSONSync(path.join(artifactDir, 'package.json'), artifactPackage, { spaces: 2 }));
70
-
71
- // create manifest
72
- const manifest = {
73
- bundleName: originalName,
74
- version: adapterPackage.version,
75
- fingerprint: 'Some verifiable token',
76
- createdEpoch: '1554836984020',
77
- artifacts: [
78
- {
79
- id: `${shortenedName}-adapter`,
80
- name: `${shortenedName}-adapter`,
81
- type: 'adapter',
82
- location: `/bundles/adapters/${originalName}`,
83
- description: artifactPackage.description,
84
- properties: {
85
- entryPoint: false
86
- }
87
- }
88
- ]
89
- };
90
-
91
- // add workflows into artifact
92
- if (fs.existsSync(workflowsDir)) {
93
- const workflowFileNames = fs.readdirSync(workflowsDir);
94
-
95
- // if folder isnt empty and only file is not readme
96
- if (workflowFileNames.length !== 0 && (!(workflowFileNames.length === 1 && workflowFileNames[0].split('.')[1] === 'md'))) {
97
- // add workflows to correct location in bundle
98
- ops.push(() => fs.copySync(workflowsDir, path.join(artifactDir, 'bundles', 'workflows')));
99
-
100
- // add workflows to manifest
101
- workflowFileNames.forEach((filename) => {
102
- const [filenameNoExt, ext] = filename.split('.');
103
- if (ext === 'json') {
104
- manifest.artifacts.push({
105
- id: `workflow-${filenameNoExt}`,
106
- name: filenameNoExt,
107
- type: 'workflow',
108
- location: `/bundles/workflows/${filename}`,
109
- description: 'Main entry point to artifact',
110
- properties: {
111
- entryPoint: false
112
- }
113
- });
114
- }
115
- });
116
- }
117
- }
118
-
119
- ops.push(() => fs.writeJSONSync(path.join(artifactDir, 'manifest.json'), manifest, { spaces: 2 }));
120
-
121
- // Run the commands in parallel
122
- try {
123
- await Promise.all(ops.map(async (op) => op()));
124
- } catch (e) {
125
- throw new Error(e);
126
- }
127
-
128
- const pathObj = {
129
- bundlePath: artifactDir,
130
- bundledAdapterPath: path.join(artifactDir, 'bundles', 'adapters', originalName)
131
- };
132
- return pathObj;
133
- }
134
-
135
- async function artifactize(entryPathToAdapter) {
136
- const truePath = path.resolve(entryPathToAdapter);
137
- const packagePath = path.join(truePath, 'package');
138
- // remove adapter from package and move bundle in
139
- const pathObj = await createBundle(packagePath);
140
- const { bundlePath } = pathObj;
141
- fs.removeSync(packagePath);
142
- fs.moveSync(bundlePath, packagePath);
143
- return 'Bundle successfully created and old folder system removed';
144
- }
145
-
146
- module.exports = { createBundle, artifactize };
package/utils/basicGet.js DELETED
@@ -1,50 +0,0 @@
1
- /* @copyright Itential, LLC 2020 */
2
-
3
- /* eslint object-shorthand: warn */
4
- /* eslint import/no-extraneous-dependencies: warn */
5
- /* eslint global-require: warn */
6
- /* eslint import/no-unresolved: warn */
7
- /* eslint import/no-dynamic-require: warn */
8
-
9
- const winston = require('winston');
10
-
11
- const logLevel = 'none';
12
- const myCustomLevels = {
13
- levels: {
14
- spam: 6,
15
- trace: 5,
16
- debug: 4,
17
- info: 3,
18
- warn: 2,
19
- error: 1,
20
- none: 0
21
- }
22
- };
23
-
24
- const basicGet = {
25
- /**
26
- * @summary create Adapter instance
27
- *
28
- * @function getAdapterInstance
29
- * @param {Object} adapter - adaper configuration object required by IAP
30
- */
31
- getAdapterInstance: (adapter) => {
32
- const Adapter = require('../adapter');
33
- const adapterProps = JSON.parse(JSON.stringify(adapter.properties.properties));
34
- adapterProps.stub = false;
35
- // need to set global logging
36
- global.log = winston.createLogger({
37
- level: logLevel,
38
- levels: myCustomLevels.levels,
39
- transports: [
40
- new winston.transports.Console()
41
- ]
42
- });
43
- return new Adapter(
44
- adapter.id,
45
- adapterProps
46
- );
47
- }
48
- };
49
-
50
- module.exports = basicGet;