@itentialopensource/adapter-tufin_secureapp 0.2.3 → 0.3.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 (48) hide show
  1. package/.eslintignore +1 -0
  2. package/AUTH.md +39 -0
  3. package/BROKER.md +199 -0
  4. package/CALLS.md +169 -0
  5. package/CHANGELOG.md +39 -8
  6. package/CODE_OF_CONDUCT.md +12 -17
  7. package/CONTRIBUTING.md +88 -74
  8. package/ENHANCE.md +69 -0
  9. package/PROPERTIES.md +641 -0
  10. package/README.md +228 -420
  11. package/SUMMARY.md +9 -0
  12. package/SYSTEMINFO.md +11 -0
  13. package/TROUBLESHOOT.md +47 -0
  14. package/adapter.js +1628 -170
  15. package/adapterBase.js +1270 -238
  16. package/entities/.generic/action.json +214 -0
  17. package/entities/.generic/schema.json +28 -0
  18. package/error.json +12 -0
  19. package/package.json +41 -18
  20. package/pronghorn.json +577 -2
  21. package/propertiesDecorators.json +14 -0
  22. package/propertiesSchema.json +472 -4
  23. package/refs?service=git-upload-pack +0 -0
  24. package/report/adapterInfo.json +10 -0
  25. package/report/updateReport1615840744335.json +95 -0
  26. package/report/updateReport1653613470041.json +120 -0
  27. package/sampleProperties.json +102 -5
  28. package/test/integration/adapterTestBasicGet.js +85 -0
  29. package/test/integration/adapterTestConnectivity.js +93 -0
  30. package/test/integration/adapterTestIntegration.js +29 -98
  31. package/test/unit/adapterBaseTestUnit.js +949 -0
  32. package/test/unit/adapterTestUnit.js +642 -109
  33. package/utils/adapterInfo.js +206 -0
  34. package/utils/addAuth.js +94 -0
  35. package/utils/basicGet.js +50 -0
  36. package/utils/checkMigrate.js +63 -0
  37. package/utils/entitiesToDB.js +179 -0
  38. package/utils/findPath.js +74 -0
  39. package/utils/modify.js +154 -0
  40. package/utils/packModificationScript.js +1 -1
  41. package/utils/patches2bundledDeps.js +90 -0
  42. package/utils/pre-commit.sh +3 -0
  43. package/utils/removeHooks.js +20 -0
  44. package/utils/tbScript.js +184 -0
  45. package/utils/tbUtils.js +469 -0
  46. package/utils/testRunner.js +16 -16
  47. package/utils/troubleshootingAdapter.js +190 -0
  48. package/img/adapter.png +0 -0
@@ -0,0 +1,190 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+ /* eslint global-require: warn */
3
+ /* eslint no-console: warn */
4
+ /* eslint import/no-unresolved: warn */
5
+ /* eslint import/no-dynamic-require: warn */
6
+
7
+ const path = require('path');
8
+ const rls = require('readline-sync');
9
+ const fs = require('fs-extra');
10
+
11
+ const utils = require(path.join(__dirname, 'tbUtils'));
12
+ const basicGet = require(path.join(__dirname, 'basicGet'));
13
+ const { name } = require(path.join(__dirname, '..', 'package.json'));
14
+ const sampleProperties = require(path.join(__dirname, '..', 'sampleProperties.json'));
15
+
16
+ // send interactive questions and collection answers
17
+ // return updated connection object
18
+ const collectAnswersSync = (questions, props) => {
19
+ const answers = [];
20
+ questions.forEach((q) => {
21
+ const answer = rls.question(q);
22
+ answers.push(answer);
23
+ });
24
+ return utils.getNewProps(answers, props);
25
+ };
26
+
27
+ // change object into array of questions
28
+ const confirm = (props) => {
29
+ const questions = Object.keys(props).map((key) => `${key}: (${props[key]}) `);
30
+ return collectAnswersSync(questions, props);
31
+ };
32
+
33
+ // allow user to change auth_method
34
+ const confirmAuthOptions = (authentication) => {
35
+ const authOptions = ['basic user_password', 'request_token', 'static_token', 'no_authentication'];
36
+ const displayAuthOptions = utils.getDisplayAuthOptions(authentication.auth_method, authOptions);
37
+ const index = rls.keyInSelect(displayAuthOptions, 'Which authentication?');
38
+ if (index === -1) {
39
+ return authentication.auth_method;
40
+ }
41
+ console.log(`${authOptions[index]} is selected.`);
42
+ return authOptions[index];
43
+ };
44
+
45
+ // helper function to update auth properties
46
+ const confirmAndUpdate = (auth, config) => {
47
+ const newAuth = confirm(auth);
48
+ return utils.updateAuth(newAuth, auth, config);
49
+ };
50
+
51
+ // extract basic auth properties
52
+ const updateBasicAuth = (config, authentication) => {
53
+ const auth = {
54
+ username: authentication.username,
55
+ password: authentication.password
56
+ };
57
+ return confirmAndUpdate(auth, config);
58
+ };
59
+
60
+ // extract static auth properties
61
+ const updateStaticAuth = (config, authentication) => {
62
+ const auth = {
63
+ token: authentication.token,
64
+ auth_field: authentication.auth_field,
65
+ auth_field_format: authentication.auth_field_format
66
+ };
67
+ return confirmAndUpdate(auth, config);
68
+ };
69
+
70
+ // troubleshooting connection and healthcheck endpoint setting of adapter
71
+ const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
72
+ // Updates connectivity params and runs connectivity
73
+ let connConfig;
74
+ const result = {};
75
+ if (scriptFlag) {
76
+ const connection = utils.getConnection(serviceItem.properties);
77
+ const newConnection = confirm(connection);
78
+ utils.runConnectivity(newConnection.host, scriptFlag);
79
+ connConfig = utils.updateNewConnection(serviceItem, newConnection);
80
+ } else {
81
+ let { properties: { properties: { host } } } = serviceItem;
82
+ if (props.connProps) {
83
+ connConfig = utils.updateNewConnection(serviceItem, props.connProps);
84
+ host = connConfig.properties.properties.host;
85
+ } else {
86
+ connConfig = serviceItem;
87
+ }
88
+ result.connectivity = utils.runConnectivity(host, scriptFlag);
89
+ }
90
+ // Updates the healthcheck endpoing
91
+ const healthcheck = require('../entities/.system/action.json');
92
+ const healthCheckEndpoint = utils.getHealthCheckEndpoint(healthcheck);
93
+ let newHealthCheckEndpoint = healthCheckEndpoint;
94
+ if (scriptFlag) {
95
+ newHealthCheckEndpoint = confirm(healthCheckEndpoint);
96
+ utils.getHealthCheckEndpointURL(newHealthCheckEndpoint, connConfig);
97
+ } else if (props.healthCheckEndpoint) {
98
+ newHealthCheckEndpoint = props.healthCheckEndpoint;
99
+ }
100
+ // Updates the authorization params
101
+ const { authentication } = connConfig.properties.properties;
102
+ let updatedAdapter = connConfig;
103
+ if (scriptFlag) {
104
+ authentication.auth_method = confirmAuthOptions(authentication);
105
+ if (authentication.auth_method === 'basic user_password') {
106
+ updatedAdapter = updateBasicAuth(connConfig, authentication);
107
+ } else if (authentication.auth_method === 'static_token') {
108
+ updatedAdapter = updateStaticAuth(connConfig, authentication);
109
+ } else if (authentication.auth_method === 'request_token') {
110
+ console.log('current troubleshooting script does not support updating request_token authentication');
111
+ }
112
+ } else if (props.auth) {
113
+ updatedAdapter = utils.updateAuth(props.auth, authentication, connConfig);
114
+ }
115
+ // Writes the new healthcheck endpoint into action.json
116
+ utils.updateHealthCheckEndpoint(newHealthCheckEndpoint, healthCheckEndpoint, healthcheck);
117
+ return { result, updatedAdapter };
118
+ };
119
+
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) => {
137
+ // get database connection and existing adapter config
138
+ const { database, serviceItem } = await utils.getAdapterConfig();
139
+ // where troubleshoot should start
140
+ if (serviceItem) {
141
+ if (!scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`)) {
142
+ const { result, updatedAdapter } = VerifyHealthCheckEndpoint(serviceItem, props, scriptFlag);
143
+ let a;
144
+ if (scriptFlag) {
145
+ a = basicGet.getAdapterInstance(updatedAdapter);
146
+ } else {
147
+ a = adapter;
148
+ }
149
+ const healthRes = await utils.healthCheck(a);
150
+ result.healthCheck = healthRes;
151
+ if (scriptFlag && !healthRes) {
152
+ console.log('run `npm run troubleshoot` again to update settings');
153
+ process.exit(0);
154
+ }
155
+
156
+ if (persistFlag && healthRes) {
157
+ const update = { $set: { properties: updatedAdapter.properties } };
158
+ await database.collection(utils.SERVICE_CONFIGS_COLLECTION).updateOne(
159
+ { model: name }, update
160
+ );
161
+ if (scriptFlag) {
162
+ console.log(`${name} updated.`);
163
+ }
164
+ }
165
+ if (scriptFlag) {
166
+ if (rls.keyInYN('Test with more GET request')) {
167
+ await utils.runBasicGet(scriptFlag);
168
+ process.exit(0);
169
+ } else {
170
+ console.log('Exiting');
171
+ process.exit(0);
172
+ }
173
+ } else {
174
+ result.basicGet = await utils.runBasicGet(scriptFlag);
175
+ return result;
176
+ }
177
+ } else {
178
+ console.log('You can update healthCheckEndpoint in ./entities/.system/action.json');
179
+ console.log('You can update authentication credientials under Settings/Services');
180
+ console.log('Exiting');
181
+ process.exit(0);
182
+ }
183
+ } else {
184
+ console.log(`${name} not installed`);
185
+ console.log('run `npm run install:adapter` to install current adapter to IAP first. Exiting...');
186
+ }
187
+ return null;
188
+ };
189
+
190
+ module.exports = { troubleshoot, offline };
package/img/adapter.png DELETED
Binary file