@itentialopensource/adapter-vmware_vcenter 0.5.3 → 0.7.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 (38) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +12 -12
  3. package/CHANGELOG.md +32 -0
  4. package/README.md +209 -29
  5. package/adapter.js +1476 -34
  6. package/adapterBase.js +289 -11
  7. package/entities/.generic/action.json +109 -0
  8. package/entities/.generic/schema.json +23 -0
  9. package/entities/.system/action.json +3 -3
  10. package/entities/.system/schemaTokenReq.json +2 -2
  11. package/entities/Vmtemplatelibraryitems/action.json +25 -0
  12. package/entities/Vmtemplatelibraryitems/schema.json +19 -0
  13. package/error.json +6 -0
  14. package/package.json +42 -21
  15. package/pronghorn.json +614 -0
  16. package/propertiesSchema.json +56 -9
  17. package/refs?service=git-upload-pack +0 -0
  18. package/report/updateReport1594310791028.json +95 -0
  19. package/report/updateReport1615860501665.json +95 -0
  20. package/report/updateReport1643047821981.json +95 -0
  21. package/sampleProperties.json +20 -5
  22. package/test/integration/adapterTestBasicGet.js +85 -0
  23. package/test/integration/adapterTestConnectivity.js +93 -0
  24. package/test/integration/adapterTestIntegration.js +59 -6
  25. package/test/unit/adapterBaseTestUnit.js +944 -0
  26. package/test/unit/adapterTestUnit.js +683 -10
  27. package/utils/addAuth.js +94 -0
  28. package/utils/basicGet.js +50 -0
  29. package/utils/checkMigrate.js +63 -0
  30. package/utils/entitiesToDB.js +224 -0
  31. package/utils/findPath.js +74 -0
  32. package/utils/modify.js +154 -0
  33. package/utils/packModificationScript.js +1 -1
  34. package/utils/patches2bundledDeps.js +90 -0
  35. package/utils/removeHooks.js +20 -0
  36. package/utils/tbScript.js +169 -0
  37. package/utils/tbUtils.js +451 -0
  38. package/utils/troubleshootingAdapter.js +190 -0
@@ -0,0 +1,90 @@
1
+ const fs = require('fs');
2
+ const semverSatisfies = require('semver/functions/satisfies');
3
+ const packageJson = require('../package.json');
4
+
5
+ try {
6
+ // pattern supplied by semver.org via https://regex101.com/r/vkijKf/1/ but removed gm from end to only match a single semver
7
+ // const semverPat = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
8
+ // pattern supplied by semver.org via https://regex101.com/r/Ly7O1x/3/ with following changes
9
+ // removed P's from before capturing group names and
10
+ // removed gm from end to only match a single semver
11
+ // const semverPat = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
12
+
13
+ const patches = (fs.existsSync('./patches')) ? fs.readdirSync('./patches', { withFileTypes: true }) : [];
14
+ if (!patches.length) {
15
+ console.error('\nno patches - nothing to do\n');
16
+ process.exitCode = 1;
17
+ }
18
+
19
+ const dependencies = packageJson.dependencies || {};
20
+ if (!Object.keys(dependencies).length) {
21
+ console.error('\nno dependencies - nothing to do\n');
22
+ process.exitCode = 1;
23
+ }
24
+
25
+ let changed = false;
26
+ console.error('\nprocessing patches');
27
+ const bundledDependencies = packageJson.bundledDependencies || packageJson.bundleDependencies || [];
28
+
29
+ patches.forEach((patch) => {
30
+ if (!patch.isFile()) {
31
+ console.error(`${patch.name} skipped, is not a regular file`);
32
+ return;
33
+ }
34
+ if (!patch.name.endsWith('.patch')) {
35
+ console.error(`${patch.name} skipped, does not end with .patch`);
36
+ return;
37
+ }
38
+ const splits = patch.name.slice(0, -6).split('+');
39
+ if (splits.length > 4) {
40
+ console.error(`${patch.name} skipped, does not follow the naming convention (cannot use '+' other than to separate scope/package/semver and at most once within semver)`);
41
+ return;
42
+ }
43
+ const scope = splits[0][0] === '@' ? splits.shift() : null;
44
+ const packageName = splits.shift();
45
+ const semver = splits.join('+');
46
+ // const { groups } = semver.match(semverPat);
47
+ const file = scope ? `${scope}/${packageName}` : packageName;
48
+ if (dependencies[file] && semverSatisfies(semver, dependencies[file])) {
49
+ if (!bundledDependencies.includes(file)) {
50
+ bundledDependencies.push(file);
51
+ console.error(`added ${file} to bundledDependencies`);
52
+ changed = true;
53
+ } else {
54
+ console.error(`bundledDependencies already has ${file}`);
55
+ }
56
+ } else {
57
+ const depmsg = dependencies[file] ? `version mismatch (${dependencies[file]}) in dependencies` : 'not found in dependencies';
58
+ console.error(`patch ${patch.name} ${depmsg}`);
59
+ }
60
+ });
61
+
62
+ if (!packageJson.bundledDependencies && bundledDependencies.length) {
63
+ delete packageJson.bundleDependencies;
64
+ packageJson.bundledDependencies = bundledDependencies;
65
+ console.error('renaming bundleDependencies to bundledDependencies');
66
+ changed = true;
67
+ }
68
+ if (changed) {
69
+ fs.writeFileSync('./package.json.new', JSON.stringify(packageJson, null, 2));
70
+ console.error('wrote package.json.new');
71
+ fs.renameSync('./package.json', './package.json.old');
72
+ console.error('moved package.json to package.json.old');
73
+ fs.renameSync('./package.json.new', './package.json');
74
+ console.error('moved package.json.new to package.json');
75
+ } else {
76
+ console.error('no changes\n');
77
+ process.exitCode = 1;
78
+ }
79
+ } catch (e) {
80
+ if (e) {
81
+ // caught error, exit with status 2 to signify abject failure
82
+ console.error(`\ncaught exception - ${e}\n`);
83
+ process.exitCode = 2;
84
+ } else {
85
+ // caught false, exit with status 1 to signify nothing done
86
+ process.exitCode = 1;
87
+ }
88
+ } finally {
89
+ console.error('done\n');
90
+ }
@@ -0,0 +1,20 @@
1
+ const fs = require('fs');
2
+
3
+ /**
4
+ * This script will uninstall pre-commit or pre-push hooks in case there's ever a need to
5
+ * commit/push something that has issues
6
+ */
7
+
8
+ const precommitPath = '.git/hooks/pre-commit';
9
+ const prepushPath = '.git/hooks/pre-push';
10
+ fs.unlink(precommitPath, (err) => {
11
+ if (err && err.code !== 'ENOENT') {
12
+ console.log(`${err.message}`);
13
+ }
14
+ });
15
+
16
+ fs.unlink(prepushPath, (err) => {
17
+ if (err && err.code !== 'ENOENT') {
18
+ console.log(`${err.message}`);
19
+ }
20
+ });
@@ -0,0 +1,169 @@
1
+ /* eslint no-console: warn */
2
+ /* eslint import/no-unresolved: warn */
3
+ /* eslint global-require: warn */
4
+
5
+ // suppress eslint rule in adapter
6
+ /* eslint arrow-parens: warn */
7
+ /* eslint import/no-extraneous-dependencies: warn */
8
+ /* eslint import/no-dynamic-require: warn */
9
+
10
+ const path = require('path');
11
+ const program = require('commander');
12
+ const rls = require('readline-sync');
13
+ const utils = require('./tbUtils');
14
+ const basicGet = require('./basicGet');
15
+ const { name } = require('../package.json');
16
+ const sampleProperties = require('../sampleProperties.json');
17
+ const adapterPronghorn = require('../pronghorn.json');
18
+ const { addAuthInfo } = require('./addAuth');
19
+
20
+ const { troubleshoot, offline } = require('./troubleshootingAdapter');
21
+
22
+ const main = async (command) => {
23
+ const dirname = utils.getDirname();
24
+ const iapDir = path.join(dirname, '../../../');
25
+ if (!utils.withinIAP(iapDir)) {
26
+ if (command === 'install') {
27
+ console.log('Not currently in IAP directory - installation not possible');
28
+ process.exit(0);
29
+ } else if (command === 'connectivity') {
30
+ const { host } = sampleProperties.properties;
31
+ console.log(`perform networking diagnositics to ${host}`);
32
+ await utils.runConnectivity(host);
33
+ process.exit(0);
34
+ } else if (command === 'healthcheck') {
35
+ const a = basicGet.getAdapterInstance({ properties: sampleProperties });
36
+ await utils.healthCheck(a);
37
+ process.exit(0);
38
+ } else if (command === 'basicget') {
39
+ await utils.runBasicGet();
40
+ process.exit(0);
41
+ }
42
+ if (rls.keyInYN('Troubleshooting without IAP?')) {
43
+ await offline();
44
+ }
45
+ process.exit(0);
46
+ }
47
+
48
+ if (command === undefined) {
49
+ await troubleshoot({}, true, true);
50
+ } else if (command === 'install') {
51
+ const { database, serviceItem, pronghornProps } = await utils.getAdapterConfig();
52
+ const filter = { id: pronghornProps.id };
53
+ const profileItem = await database.collection(utils.IAP_PROFILES_COLLECTION).findOne(filter);
54
+ if (!profileItem) {
55
+ console.log(`Could not find IAP profile for id ${pronghornProps.id}`);
56
+ process.exit(0);
57
+ }
58
+ if (serviceItem) {
59
+ console.log(`A service by the name ${name} already exits!`);
60
+ if (rls.keyInYN(`Do you want to completely remove ${name}?`)) {
61
+ console.log(`Removing ${name} from db...`);
62
+ await database.collection(utils.SERVICE_CONFIGS_COLLECTION).deleteOne({ model: name });
63
+ console.log(`${name} removed from db.`);
64
+ if (profileItem.services.includes(serviceItem.name)) {
65
+ const serviceIndex = profileItem.services.indexOf(serviceItem.name);
66
+ profileItem.services.splice(serviceIndex, 1);
67
+ const update = { $set: { services: profileItem.services } };
68
+ await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
69
+ { id: pronghornProps.id }, update
70
+ );
71
+ console.log(`${serviceItem.name} removed from profileItem.services.`);
72
+ console.log(`Rerun the script to reinstall ${serviceItem.name}.`);
73
+ process.exit(0);
74
+ } else {
75
+ process.exit(0);
76
+ }
77
+ } else {
78
+ console.log('Exiting...');
79
+ process.exit(0);
80
+ }
81
+ } else {
82
+ utils.verifyInstallationDir(dirname, name);
83
+ utils.runTest();
84
+ if (rls.keyInYN(`Do you want to install ${name} to IAP?`)) {
85
+ console.log('Creating database entries...');
86
+ const adapter = utils.createAdapter(
87
+ pronghornProps, profileItem, sampleProperties, adapterPronghorn
88
+ );
89
+
90
+ adapter.properties.properties = await addAuthInfo(adapter.properties.properties);
91
+
92
+ await database.collection(utils.SERVICE_CONFIGS_COLLECTION).insertOne(adapter);
93
+ profileItem.services.push(adapter.name);
94
+ const update = { $set: { services: profileItem.services } };
95
+ await database.collection(utils.IAP_PROFILES_COLLECTION).updateOne(
96
+ { id: pronghornProps.id }, update
97
+ );
98
+ console.log('Database entry creation complete.');
99
+ }
100
+ console.log('Exiting...');
101
+ process.exit(0);
102
+ }
103
+ } else if (['healthcheck', 'basicget', 'connectivity'].includes(command)) {
104
+ const { serviceItem } = await utils.getAdapterConfig();
105
+ if (serviceItem) {
106
+ const adapter = serviceItem;
107
+ const a = basicGet.getAdapterInstance(adapter);
108
+ if (command === 'healthcheck') {
109
+ await utils.healthCheck(a);
110
+ process.exit(0);
111
+ } else if (command === 'basicget') {
112
+ await utils.runBasicGet(true);
113
+ } else if (command === 'connectivity') {
114
+ const { host } = adapter.properties.properties;
115
+ console.log(`perform networking diagnositics to ${host}`);
116
+ await utils.runConnectivity(host, true);
117
+ process.exit(0);
118
+ }
119
+ } else {
120
+ console.log(`${name} not installed. Run npm \`run install:adapter\` to install.`);
121
+ process.exit(0);
122
+ }
123
+ }
124
+ };
125
+
126
+ program
127
+ .command('connectivity')
128
+ .alias('c')
129
+ .description('networking diagnostics')
130
+ .action(() => {
131
+ main('connectivity');
132
+ });
133
+
134
+ program
135
+ .command('install')
136
+ .alias('i')
137
+ .description('install current adapter')
138
+ .action(() => {
139
+ main('install');
140
+ });
141
+
142
+ program
143
+ .command('healthcheck')
144
+ .alias('hc')
145
+ .description('perfom none interative healthcheck with current setting')
146
+ .action(() => {
147
+ main('healthcheck');
148
+ });
149
+
150
+ program
151
+ .command('basicget')
152
+ .alias('bg')
153
+ .description('perfom basicget')
154
+ .action(() => {
155
+ main('basicget');
156
+ });
157
+
158
+ // Allow commander to parse `process.argv`
159
+ program.parse(process.argv);
160
+
161
+ if (process.argv.length < 3) {
162
+ main();
163
+ }
164
+ const allowedParams = ['install', 'healthcheck', 'basicget', 'connectivity'];
165
+ if (process.argv.length === 3 && !allowedParams.includes(process.argv[2])) {
166
+ console.log(`unknown parameter ${process.argv[2]}`);
167
+ console.log('try `node troubleshootingAdapter.js -h` to see allowed parameters. Exiting...');
168
+ process.exit(0);
169
+ }