@itentialopensource/adapter-aruba_airwave 0.1.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.
Files changed (58) hide show
  1. package/.eslintignore +6 -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 +0 -0
  9. package/CHANGELOG.md +9 -0
  10. package/CODE_OF_CONDUCT.md +48 -0
  11. package/CONTRIBUTING.md +158 -0
  12. package/LICENSE +201 -0
  13. package/README.md +544 -0
  14. package/adapter.js +2860 -0
  15. package/adapterBase.js +906 -0
  16. package/entities/.system/action.json +50 -0
  17. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  18. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  19. package/entities/.system/schema.json +19 -0
  20. package/entities/.system/schemaTokenReq.json +77 -0
  21. package/entities/.system/schemaTokenResp.json +65 -0
  22. package/entities/BatchExecuteAPCommandsAPIS/action.json +45 -0
  23. package/entities/BatchExecuteAPCommandsAPIS/schema.json +20 -0
  24. package/entities/ConfigurationAPIS/action.json +126 -0
  25. package/entities/ConfigurationAPIS/schema.json +90 -0
  26. package/entities/DeviceAPIS/action.json +46 -0
  27. package/entities/DeviceAPIS/schema.json +20 -0
  28. package/entities/LOGIN/action.json +24 -0
  29. package/entities/LOGIN/schema.json +41 -0
  30. package/entities/QueryAPIS/action.json +298 -0
  31. package/entities/QueryAPIS/schema.json +32 -0
  32. package/entities/ReportAPIS/action.json +25 -0
  33. package/entities/ReportAPIS/schema.json +30 -0
  34. package/entities/SearchAPIS/action.json +67 -0
  35. package/entities/SearchAPIS/schema.json +21 -0
  36. package/error.json +184 -0
  37. package/package.json +86 -0
  38. package/pronghorn.json +1589 -0
  39. package/propertiesSchema.json +801 -0
  40. package/refs?service=git-upload-pack +0 -0
  41. package/report/ArubaAirwavePostman.json-OpenApi3Json.json +1583 -0
  42. package/report/creationReport.json +381 -0
  43. package/sampleProperties.json +97 -0
  44. package/test/integration/adapterTestBasicGet.js +85 -0
  45. package/test/integration/adapterTestConnectivity.js +93 -0
  46. package/test/integration/adapterTestIntegration.js +1125 -0
  47. package/test/unit/adapterBaseTestUnit.js +929 -0
  48. package/test/unit/adapterTestUnit.js +1413 -0
  49. package/utils/artifactize.js +146 -0
  50. package/utils/basicGet.js +63 -0
  51. package/utils/packModificationScript.js +35 -0
  52. package/utils/pre-commit.sh +27 -0
  53. package/utils/setup.js +33 -0
  54. package/utils/tbScript.js +163 -0
  55. package/utils/tbUtils.js +372 -0
  56. package/utils/testRunner.js +298 -0
  57. package/utils/troubleshootingAdapter.js +219 -0
  58. package/workflows/README.md +3 -0
@@ -0,0 +1,219 @@
1
+ /* @copyright Itential, LLC 2020 */
2
+
3
+ /* eslint no-console: warn */
4
+ /* eslint import/no-unresolved: warn */
5
+ /* eslint global-require: warn */
6
+
7
+ // suppress eslint rule in adapter
8
+ /* eslint arrow-parens: warn */
9
+ /* eslint import/no-extraneous-dependencies: warn */
10
+ /* eslint import/no-dynamic-require: warn */
11
+
12
+ const path = require('path');
13
+ const rls = require('readline-sync');
14
+ const fs = require('fs-extra');
15
+
16
+ const utils = require('./tbUtils');
17
+ const basicGet = require('./basicGet');
18
+ const { name } = require('../package.json');
19
+ const sampleProperties = require('../sampleProperties.json');
20
+
21
+ // send interactive questions and collection answers
22
+ // return updated connection object
23
+ const collectAnswersSync = (questions, props) => {
24
+ const answers = [];
25
+ questions.forEach(q => {
26
+ const answer = rls.question(q);
27
+ answers.push(answer);
28
+ });
29
+ return utils.getNewProps(answers, props);
30
+ };
31
+
32
+ // change object into array of questions
33
+ const confirm = (props) => {
34
+ const questions = Object.keys(props).map(key => `${key}: (${props[key]}) `);
35
+ return collectAnswersSync(questions, props);
36
+ };
37
+
38
+ // allow user to change auth_method
39
+ const confirmAuthOptions = (authentication) => {
40
+ const authOptions = ['basic user_password', 'request_token', 'static_token', 'no_authentication'];
41
+ const displayAuthOptions = utils.getDisplayAuthOptions(authentication.auth_method, authOptions);
42
+ const index = rls.keyInSelect(displayAuthOptions, 'Which authentication?');
43
+ if (index === -1) {
44
+ return authentication.auth_method;
45
+ }
46
+ console.log(`${authOptions[index]} is selected.`);
47
+ return authOptions[index];
48
+ };
49
+
50
+ // helper function to update auth properties
51
+ const confirmAndUpdate = (auth, config) => {
52
+ const newAuth = confirm(auth);
53
+ return utils.updateAuth(newAuth, auth, config);
54
+ };
55
+
56
+ // extract basic auth properties
57
+ const updateBasicAuth = (config, authentication) => {
58
+ const auth = {
59
+ username: authentication.username,
60
+ password: authentication.password
61
+ };
62
+ return confirmAndUpdate(auth, config);
63
+ };
64
+
65
+ // extract static auth properties
66
+ const updateStaticAuth = (config, authentication) => {
67
+ const auth = {
68
+ token: authentication.token,
69
+ auth_field: authentication.auth_field,
70
+ auth_field_format: authentication.auth_field_format
71
+ };
72
+ return confirmAndUpdate(auth, config);
73
+ };
74
+
75
+ // troubleshooting connection and healthcheck endpoint setting of adapter
76
+ const VerifyHealthCheckEndpoint = (serviceItem, props, scriptFlag) => {
77
+ // Updates connectivity params and runs connectivity
78
+ let connConfig;
79
+ const result = {};
80
+ if (scriptFlag) {
81
+ const connection = utils.getConnection(serviceItem.properties);
82
+ const newConnection = confirm(connection);
83
+ utils.runConnectivity(newConnection.host, scriptFlag);
84
+ connConfig = utils.updateNewConnection(serviceItem, newConnection);
85
+ } else {
86
+ let { properties: { properties: { host } } } = serviceItem;
87
+ if (props.connProps) {
88
+ connConfig = utils.updateNewConnection(serviceItem, props.connProps);
89
+ host = connConfig.properties.properties.host;
90
+ } else {
91
+ connConfig = serviceItem;
92
+ }
93
+ result.connectivity = utils.runConnectivity(host, scriptFlag);
94
+ }
95
+ // Updates the healthcheck endpoing
96
+ const healthcheck = require('../entities/.system/action.json');
97
+ const healthCheckEndpoint = utils.getHealthCheckEndpoint(healthcheck);
98
+ let newHealthCheckEndpoint = healthCheckEndpoint;
99
+ if (scriptFlag) {
100
+ newHealthCheckEndpoint = confirm(healthCheckEndpoint);
101
+ utils.getHealthCheckEndpointURL(newHealthCheckEndpoint, connConfig);
102
+ } else if (props.healthCheckEndpoint) {
103
+ newHealthCheckEndpoint = props.healthCheckEndpoint;
104
+ }
105
+ // Updates the authorization params
106
+ const { authentication } = connConfig.properties.properties;
107
+ let updatedAdapter = connConfig;
108
+ if (scriptFlag) {
109
+ authentication.auth_method = confirmAuthOptions(authentication);
110
+ if (authentication.auth_method === 'basic user_password') {
111
+ updatedAdapter = updateBasicAuth(connConfig, authentication);
112
+ } else if (authentication.auth_method === 'static_token') {
113
+ updatedAdapter = updateStaticAuth(connConfig, authentication);
114
+ } else if (authentication.auth_method === 'request_token') {
115
+ console.log('current troubleshooting script does not support updating request_token authentication');
116
+ }
117
+ } else if (props.auth) {
118
+ updatedAdapter = utils.updateAuth(props.auth, authentication, connConfig);
119
+ }
120
+ // Writes the new healthcheck endpoint into action.json
121
+ utils.updateHealthCheckEndpoint(newHealthCheckEndpoint, healthCheckEndpoint, healthcheck);
122
+ return { result, updatedAdapter };
123
+ };
124
+
125
+ const getPronghornProps = (iapDir) => {
126
+ console.log('Retrieving properties.json file...');
127
+ const rawProps = require(path.join(iapDir, 'properties.json'));
128
+ console.log('Decrypting properties...');
129
+ const { Discovery } = require('@itential/itential-utils');
130
+ const discovery = new Discovery();
131
+ const pronghornProps = utils.decryptProperties(rawProps, __dirname, discovery);
132
+ console.log('Found properties.\n');
133
+ return pronghornProps;
134
+ };
135
+
136
+ // get database connection and existing adapter config
137
+ const getAdapterConfig = async () => {
138
+ const iapDir = path.join(__dirname, '../../../../');
139
+ const pronghornProps = getPronghornProps(iapDir);
140
+ console.log('Connecting to Database...');
141
+ const database = await basicGet.connect(pronghornProps);
142
+ console.log('Connection established.');
143
+ const serviceItem = await database.collection(utils.SERVICE_CONFIGS_COLLECTION).findOne(
144
+ { model: name }
145
+ );
146
+ return { database, serviceItem, pronghornProps };
147
+ };
148
+
149
+ const offline = async () => {
150
+ console.log('Start offline troubleshooting');
151
+ const { updatedAdapter } = VerifyHealthCheckEndpoint({ properties: sampleProperties }, {}, true);
152
+ const a = basicGet.getAdapterInstance(updatedAdapter);
153
+ const res = await utils.healthCheck(a);
154
+ if (!res) {
155
+ console.log('run `npm run troubleshoot` again to update settings');
156
+ process.exit(0);
157
+ }
158
+ console.log('Save changes to sampleProperties.json');
159
+ await fs.writeFile('sampleProperties.json', JSON.stringify(updatedAdapter.properties, null, 2));
160
+ if (rls.keyInYN('Test with more GET request')) {
161
+ await utils.runBasicGet(true);
162
+ }
163
+ };
164
+
165
+ const troubleshoot = async (props, scriptFlag, persistFlag, adapter) => {
166
+ // get database connection and existing adapter config
167
+ const { database, serviceItem } = await getAdapterConfig();
168
+ // where troubleshoot should start
169
+ if (serviceItem) {
170
+ if (!scriptFlag || rls.keyInYN(`Start verifying the connection and authentication properties for ${name}?`)) {
171
+ const { result, updatedAdapter } = VerifyHealthCheckEndpoint(serviceItem, props, scriptFlag);
172
+ let a;
173
+ if (scriptFlag) {
174
+ a = basicGet.getAdapterInstance(updatedAdapter);
175
+ } else {
176
+ a = adapter;
177
+ }
178
+ const healthRes = await utils.healthCheck(a);
179
+ result.healthCheck = healthRes;
180
+ if (scriptFlag && !healthRes) {
181
+ console.log('run `npm run troubleshoot` again to update settings');
182
+ process.exit(0);
183
+ }
184
+
185
+ if (persistFlag && healthRes) {
186
+ const update = { $set: { properties: updatedAdapter.properties } };
187
+ await database.collection(utils.SERVICE_CONFIGS_COLLECTION).updateOne(
188
+ { model: name }, update
189
+ );
190
+ if (scriptFlag) {
191
+ console.log(`${name} updated.`);
192
+ }
193
+ }
194
+ if (scriptFlag) {
195
+ if (rls.keyInYN('Test with more GET request')) {
196
+ await utils.runBasicGet(scriptFlag);
197
+ process.exit(0);
198
+ } else {
199
+ console.log('Exiting');
200
+ process.exit(0);
201
+ }
202
+ } else {
203
+ result.basicGet = await utils.runBasicGet(scriptFlag);
204
+ return result;
205
+ }
206
+ } else {
207
+ console.log('You can update healthCheckEndpoint in ./entities/.system/action.json');
208
+ console.log('You can update authentication credientials under Settings/Services');
209
+ console.log('Exiting');
210
+ process.exit(0);
211
+ }
212
+ } else {
213
+ console.log(`${name} not installed`);
214
+ console.log('run `npm run install:adapter` to install current adapter to IAP first. Exiting...');
215
+ }
216
+ return null;
217
+ };
218
+
219
+ module.exports = { troubleshoot, getAdapterConfig, offline };
@@ -0,0 +1,3 @@
1
+ # Adapter Workflows
2
+
3
+ This directory contains workflows that support the adapter use cases. These workflows can be imported into IAP. If the adapter is installed using App-Artifact the workflows should be automatically imported.