@opscompass/opscompass-cli 1.0.46 → 1.3.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.
@@ -1,6 +1,6 @@
1
- const { getOpsCompassClient } = require("../opscompass.js");
2
- const { ScriptType, cliCommand } = require("../environment/current.js");
3
- const {
1
+ import { getOpsCompassClient } from "../opscompass.js";
2
+ import { ScriptType, cliCommand } from "../environment/current.js";
3
+ import {
4
4
  downloadScriptsToHome,
5
5
  findOrCreateScriptTypeFolder,
6
6
  findOrCreateScriptsFolder,
@@ -8,14 +8,15 @@ const {
8
8
  BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH,
9
9
  getInstalledScriptVersion,
10
10
  previousScriptsDownloaded,
11
- } = require("../lib/homeInteraction.js");
12
- const { canReadFile } = require("../lib/cliHelpers.js");
11
+ } from "../lib/homeInteraction.js";
12
+ import { canReadFile } from "../lib/cliHelpers.js";
13
13
 
14
- const semver = require("semver");
15
- const path = require("path");
16
- const fs = require("fs-extra");
17
- const util = require("util");
18
- const exec = util.promisify(require("child_process").exec);
14
+ import semver from "semver";
15
+ import path from "path";
16
+ import fs from "fs-extra";
17
+ import util from "util";
18
+ import { exec as execSync } from "child_process";
19
+ const exec = util.promisify(execSync);
19
20
 
20
21
  /**
21
22
  * Lists script types that are locally downloaded
@@ -42,7 +43,7 @@ async function listLocalScripts(args) {
42
43
  let metaFile = path.join(
43
44
  baseScriptFolderPath,
44
45
  item.name,
45
- "metadata.json"
46
+ "metadata.json",
46
47
  );
47
48
  if (fs.existsSync(metaFile)) {
48
49
  const data = fs.readFileSync(metaFile);
@@ -108,7 +109,7 @@ async function downloadScripts(args) {
108
109
  scriptType,
109
110
  scriptVersion,
110
111
  company,
111
- client
112
+ client,
112
113
  );
113
114
 
114
115
  console.log("Downloaded %s (v%s)", scriptType, rcvdVersion);
@@ -136,9 +137,8 @@ async function listAvailableScripts(args) {
136
137
  try {
137
138
  const client = await getOpsCompassClient();
138
139
 
139
- const scriptsRemote = await client.dataGatheringScripts.getScriptVersions(
140
- company
141
- );
140
+ const scriptsRemote =
141
+ await client.dataGatheringScripts.getScriptVersions(company);
142
142
 
143
143
  if (!quiet) {
144
144
  // Go with compact output for this display
@@ -190,7 +190,7 @@ async function checkScriptUpdates(args) {
190
190
 
191
191
  if (!currentScriptVersion) {
192
192
  console.log(
193
- `Local scripts for type ${scriptType} not found. Please make sure they are downloaded.`
193
+ `Local scripts for type ${scriptType} not found. Please make sure they are downloaded.`,
194
194
  );
195
195
  console.log("If the issue persists, please contact your OpsCompass rep.");
196
196
  return;
@@ -204,11 +204,11 @@ async function checkScriptUpdates(args) {
204
204
  if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
205
205
  console.log(
206
206
  yellowText,
207
- `Warning! You are using version ${currentScriptVersion} of the the ${scriptType} scripts, but the latest version is ${latestScriptVersion.scriptVersion}. To update to the latest version, please run:`
207
+ `Warning! You are using version ${currentScriptVersion} of the the ${scriptType} scripts, but the latest version is ${latestScriptVersion.scriptVersion}. To update to the latest version, please run:`,
208
208
  );
209
209
  console.log(
210
210
  greenText,
211
- ` ${cliCommand} data-gathering-scripts download-scripts --company ${company} --scriptType ${scriptType} `
211
+ ` ${cliCommand} data-gathering-scripts download-scripts --company ${company} --scriptType ${scriptType} `,
212
212
  );
213
213
  if (autoUpdate) {
214
214
  console.log("Updating...");
@@ -218,7 +218,7 @@ async function checkScriptUpdates(args) {
218
218
  scriptType,
219
219
  undefined,
220
220
  company,
221
- client
221
+ client,
222
222
  );
223
223
 
224
224
  console.log("Downloaded %s (v%s)", scriptType, rcvdVersion);
@@ -231,7 +231,7 @@ async function checkScriptUpdates(args) {
231
231
  } else {
232
232
  console.log(
233
233
  greenText,
234
- `You are already using the latest version of ${scriptType} script, ${latestScriptVersion.scriptVersion}.`
234
+ `You are already using the latest version of ${scriptType} script, ${latestScriptVersion.scriptVersion}.`,
235
235
  );
236
236
  console.log();
237
237
  }
@@ -255,8 +255,8 @@ async function checkScriptUpdates(args) {
255
255
  return a.scriptType < b.scriptType
256
256
  ? -1
257
257
  : a.scriptType > b.scriptType
258
- ? 1
259
- : 0;
258
+ ? 1
259
+ : 0;
260
260
  });
261
261
 
262
262
  console.log("\nCheck-Updates fetching remote versions...");
@@ -264,12 +264,12 @@ async function checkScriptUpdates(args) {
264
264
 
265
265
  for (const scriptVer of scriptsLocal.versions) {
266
266
  const remoteVer = scriptsRemote.versions.find(
267
- (version) => version.scriptType === scriptVer.scriptType
267
+ (version) => version.scriptType === scriptVer.scriptType,
268
268
  );
269
269
 
270
270
  const needsUpdate = semver.gt(
271
271
  remoteVer.scriptVersion,
272
- scriptVer.scriptVersion
272
+ scriptVer.scriptVersion,
273
273
  );
274
274
 
275
275
  if (needsUpdate) {
@@ -277,11 +277,11 @@ async function checkScriptUpdates(args) {
277
277
  "\nmodule %s: Local=%s, needs update=%s",
278
278
  scriptVer.scriptType,
279
279
  scriptVer.scriptVersion,
280
- remoteVer.scriptVersion
280
+ remoteVer.scriptVersion,
281
281
  );
282
282
  console.log(
283
283
  greenText,
284
- ` ${cliCommand} data-gathering-scripts download-scripts --company ${company} --scriptType ${scriptVer.scriptType} \n`
284
+ ` ${cliCommand} data-gathering-scripts download-scripts --company ${company} --scriptType ${scriptVer.scriptType} \n`,
285
285
  );
286
286
  if (autoUpdate) {
287
287
  console.log("Updating...");
@@ -292,13 +292,13 @@ async function checkScriptUpdates(args) {
292
292
  undefined,
293
293
  company,
294
294
  client,
295
- scriptsRemote
295
+ scriptsRemote,
296
296
  );
297
297
 
298
298
  console.log(
299
299
  "Downloaded %s (v%s)",
300
300
  scriptVer.scriptType,
301
- rcvdVersion
301
+ rcvdVersion,
302
302
  );
303
303
  } catch (err) {
304
304
  console.log("Auto update script type %s failed...", scriptType);
@@ -310,7 +310,7 @@ async function checkScriptUpdates(args) {
310
310
  console.log(
311
311
  "\nmodule %s: Local=%s, is up to date",
312
312
  scriptVer.scriptType,
313
- scriptVer.scriptVersion
313
+ scriptVer.scriptVersion,
314
314
  );
315
315
  }
316
316
  }
@@ -340,7 +340,7 @@ async function autoCheckScriptUpdates(args) {
340
340
  const currentScriptVersion = await getInstalledScriptVersion(scriptType);
341
341
  if (!currentScriptVersion) {
342
342
  console.log(
343
- `Local scripts for type ${scriptType} not found. Please make sure they are downloaded.`
343
+ `Local scripts for type ${scriptType} not found. Please make sure they are downloaded.`,
344
344
  );
345
345
  console.log("If the issue persists, please contact your OpsCompass rep.");
346
346
  return;
@@ -353,12 +353,12 @@ async function autoCheckScriptUpdates(args) {
353
353
  if (semver.gt(latestScriptVersion.scriptVersion, currentScriptVersion)) {
354
354
  console.log(
355
355
  yellowText,
356
- `Warning! You are using version ${currentScriptVersion} of the the ${scriptType} scripts, but the latest version is ${latestScriptVersion.scriptVersion}. To update to the latest version, please run:`
356
+ `Warning! You are using version ${currentScriptVersion} of the the ${scriptType} scripts, but the latest version is ${latestScriptVersion.scriptVersion}. To update to the latest version, please run:`,
357
357
  );
358
358
  console.log();
359
359
  console.log(
360
360
  greenText,
361
- ` ${cliCommand} data-gathering-scripts download-scripts --company ${company} --scriptType ${scriptType} `
361
+ ` ${cliCommand} data-gathering-scripts download-scripts --company ${company} --scriptType ${scriptType} `,
362
362
  );
363
363
  console.log();
364
364
  }
@@ -371,12 +371,12 @@ async function autoCheckScriptUpdates(args) {
371
371
  async function manuallyRunScripts() {
372
372
  try {
373
373
  const baseScriptFolderPath = findOrCreateScriptTypeFolder(
374
- ScriptType.baseScripts
374
+ ScriptType.baseScripts,
375
375
  );
376
376
  const runAllFilePath = path.join(
377
377
  baseScriptFolderPath,
378
378
  SRC_FOLDER_NAME,
379
- BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH
379
+ BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH,
380
380
  );
381
381
 
382
382
  if (canReadFile(runAllFilePath)) {
@@ -403,7 +403,7 @@ async function printHelp() {
403
403
  console.log();
404
404
  console.log(
405
405
  "list-available",
406
- "Lists all script types and versions available for download"
406
+ "Lists all script types and versions available for download",
407
407
  );
408
408
  console.log("Parameters:");
409
409
  console.log("--company [company_slug]");
@@ -411,25 +411,25 @@ async function printHelp() {
411
411
  console.log();
412
412
  console.log(
413
413
  "list-local",
414
- "Lists all locally downloaded script types and versions"
414
+ "Lists all locally downloaded script types and versions",
415
415
  );
416
416
  console.log("Parameters:");
417
417
  console.log("--quiet does not generate output on stdout");
418
418
  console.log();
419
419
  console.log(
420
420
  "download-scripts",
421
- "Downloads scripts for the passed script type."
421
+ "Downloads scripts for the passed script type.",
422
422
  );
423
423
  console.log("Parameters:");
424
424
  console.log("--company [company_slug]");
425
425
  console.log("--script-type", JSON.stringify(Object.values(ScriptType)));
426
426
  console.log(
427
- "--script-version (optional) [version] if not provided, the latest script will be downloaded"
427
+ "--script-version (optional) [version] if not provided, the latest script will be downloaded",
428
428
  );
429
429
  console.log();
430
430
  console.log(
431
431
  "check-script-updates",
432
- "Checks local script version against the latest published version for the passed script type, or all locally downloaded script types if none specified"
432
+ "Checks local script version against the latest published version for the passed script type, or all locally downloaded script types if none specified",
433
433
  );
434
434
  console.log("Parameters:");
435
435
  console.log("--auto-update automatically downloads any needed updates");
@@ -438,7 +438,7 @@ async function printHelp() {
438
438
  console.log();
439
439
  console.log(
440
440
  "manually-run-scripts",
441
- "Do not run this unless you know what you are doing. This manually runs all the scripts."
441
+ "Do not run this unless you know what you are doing. This manually runs all the scripts.",
442
442
  );
443
443
  console.log();
444
444
  }
@@ -478,4 +478,4 @@ dataGatheringScriptsModule.requiresLogin = true;
478
478
  dataGatheringScriptsModule.description =
479
479
  "Provides access to OpsCompass data gathering scripts.";
480
480
 
481
- module.exports = dataGatheringScriptsModule;
481
+ export default dataGatheringScriptsModule;
@@ -1,7 +1,7 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const { opscompassHome } = require("../environment/current.js");
4
- const { maskTypes } = require("../lib/maskValues.js");
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { opscompassHome } from "../environment/current.js";
4
+ import { maskTypes } from "../lib/maskValues.js";
5
5
 
6
6
  const defaultsPath = path.join(opscompassHome, "defaults.json");
7
7
 
@@ -55,7 +55,7 @@ async function writeDefaults(args) {
55
55
  // If maskType is not valid then return with error
56
56
  if (!Object.values(maskTypes).includes(maskType)) {
57
57
  console.error(
58
- `Invalid maskType ${maskType} for property ${property}`
58
+ `Invalid maskType ${maskType} for property ${property}`,
59
59
  );
60
60
  return;
61
61
  }
@@ -64,7 +64,7 @@ async function writeDefaults(args) {
64
64
  defaults.maskValues = [];
65
65
  } else {
66
66
  defaults.maskValues = defaults.maskValues.filter(
67
- (maskValue) => maskValue.property !== property
67
+ (maskValue) => maskValue.property !== property,
68
68
  );
69
69
  }
70
70
 
@@ -94,18 +94,18 @@ function printHelp() {
94
94
  console.log();
95
95
  console.log(
96
96
  "set-defaults",
97
- "Allows you to set default parameter such as company, account, or monitoring configuration."
97
+ "Allows you to set default parameter such as company, account, or monitoring configuration.",
98
98
  );
99
99
  console.log("Parameters:");
100
100
  console.log(
101
- "--company 'value' --account 'value' --monitoring-configuration-id 'value'"
101
+ "--company 'value' --account 'value' --monitoring-configuration-id 'value'",
102
102
  );
103
103
  console.log(
104
104
  "--mask-values property=hash[,...]",
105
- `Mask values sent between OpsCompass and ${global.company}`
105
+ `Mask values sent between OpsCompass and ${global.company}`,
106
106
  );
107
107
  console.log(
108
- "\ne.g. opscompass defaults set-defaults --company 'opscompass' --account '231' --monitoring-configuration-id '34232'"
108
+ "\ne.g. opscompass defaults set-defaults --company 'opscompass' --account '231' --monitoring-configuration-id '34232'",
109
109
  );
110
110
  console.log();
111
111
  console.log("e.g. opscompass defaults set-defaults --mask-values server=md5");
@@ -133,5 +133,5 @@ defaultsModule.requiresLogin = false;
133
133
  defaultsModule.description =
134
134
  "View and set default parameters for OpsCompass CLI.";
135
135
 
136
- module.exports = { readDefaults, writeDefaults, defaultsPath };
137
- module.exports = defaultsModule;
136
+ export { readDefaults, writeDefaults, defaultsPath };
137
+ export default defaultsModule;
@@ -1,17 +1,17 @@
1
- const { getOpsCompassClient } = require("../opscompass.js");
1
+ import { getOpsCompassClient } from "../opscompass.js";
2
2
 
3
3
  async function listExpirationComponents(args) {
4
4
  for (let i = 0; i < args.length; i++) {
5
5
  switch (args[i].toLowerCase()) {
6
- case "--company":
6
+ case "--company":
7
7
  callParams.company = args[++i];
8
8
  break;
9
9
  }
10
10
  }
11
11
 
12
-
13
12
  const client = await getOpsCompassClient();
14
- const response = await client.expirationInfo.listExpirationComponents(callParams);
13
+ const response =
14
+ await client.expirationInfo.listExpirationComponents(callParams);
15
15
 
16
16
  console.log(JSON.stringify(response, null, 2));
17
17
  }
@@ -19,19 +19,19 @@ async function listExpirationComponents(args) {
19
19
  async function listExpirationComponentVersions(args) {
20
20
  for (let i = 0; i < args.length; i++) {
21
21
  switch (args[i].toLowerCase()) {
22
- case "--company":
22
+ case "--company":
23
23
  callParams.company = args[++i];
24
24
  break;
25
- case "--componentslug":
26
- case "--component-slug":
25
+ case "--componentslug":
26
+ case "--component-slug":
27
27
  callParams.componentSlug = args[++i];
28
28
  break;
29
29
  }
30
30
  }
31
31
 
32
-
33
32
  const client = await getOpsCompassClient();
34
- const response = await client.expirationInfo.listExpirationComponentVersions(callParams);
33
+ const response =
34
+ await client.expirationInfo.listExpirationComponentVersions(callParams);
35
35
 
36
36
  console.log(JSON.stringify(response, null, 2));
37
37
  }
@@ -54,7 +54,8 @@ async function saveExpirationComponentVersion(args) {
54
54
  }
55
55
 
56
56
  const client = await getOpsCompassClient();
57
- const response = await client.expirationInfo.saveExpirationComponentVersion(callParams);
57
+ const response =
58
+ await client.expirationInfo.saveExpirationComponentVersion(callParams);
58
59
 
59
60
  console.log(JSON.stringify(response, null, 2));
60
61
  }
@@ -77,7 +78,8 @@ async function deleteExpirationComponentVersion(args) {
77
78
  }
78
79
 
79
80
  const client = await getOpsCompassClient();
80
- const response = await client.expirationInfo.deleteExpirationComponentVersion(callParams);
81
+ const response =
82
+ await client.expirationInfo.deleteExpirationComponentVersion(callParams);
81
83
 
82
84
  console.log(JSON.stringify(response, null, 2));
83
85
  }
@@ -102,7 +104,7 @@ async function listExpirations(args) {
102
104
  const client = await getOpsCompassClient();
103
105
  const response = await client.expirationInfo.listExpirations(callParams);
104
106
 
105
- console.log(JSON.stringify(response, null, 2));
107
+ console.log(JSON.stringify(response, null, 2));
106
108
  }
107
109
 
108
110
  async function listTracked(args) {
@@ -117,42 +119,68 @@ async function listTracked(args) {
117
119
  const client = await getOpsCompassClient();
118
120
  const response = await client.expirationInfo.listTracked(callParams);
119
121
 
120
- console.log(JSON.stringify(response, null, 2));
122
+ console.log(JSON.stringify(response, null, 2));
121
123
  }
122
124
 
123
125
  async function printHelp() {
124
126
  console.log("Actions available for expiration info:");
125
127
  console.log();
126
- console.log("list-expiration-components", "Retrieves the list of available expiration components for a company.");
128
+ console.log(
129
+ "list-expiration-components",
130
+ "Retrieves the list of available expiration components for a company.",
131
+ );
127
132
  console.log("Parameters:");
128
133
  console.log("--company [company_slug]");
129
134
  console.log();
130
- console.log("list-expiration-component-versions", "Retrieves the list of available expiration component versions for a company.");
135
+ console.log(
136
+ "list-expiration-component-versions",
137
+ "Retrieves the list of available expiration component versions for a company.",
138
+ );
131
139
  console.log("Parameters:");
132
140
  console.log("--company [company_slug]");
133
141
  console.log("--component-slug [component_slug]");
134
142
  console.log();
135
- console.log("list-expirations", "Retrieves the list of expirations for a company.");
143
+ console.log(
144
+ "list-expirations",
145
+ "Retrieves the list of expirations for a company.",
146
+ );
136
147
  console.log("Parameters:");
137
148
  console.log("--company [company_slug]");
138
- console.log("--from-date (optional) [string] Example: '2021-01-01T00:00:00.000Z'");
139
- console.log("--to-date (optional) [string] Example: '2021-12-31T00:00:00.000Z'");
149
+ console.log(
150
+ "--from-date (optional) [string] Example: '2021-01-01T00:00:00.000Z'",
151
+ );
152
+ console.log(
153
+ "--to-date (optional) [string] Example: '2021-12-31T00:00:00.000Z'",
154
+ );
140
155
  console.log();
141
- console.log("list-tracked", "Retrieves the list of tracked expirations for a company.");
156
+ console.log(
157
+ "list-tracked",
158
+ "Retrieves the list of tracked expirations for a company.",
159
+ );
142
160
  console.log("Parameters:");
143
161
  console.log("--company [company_slug]");
144
162
  console.log();
145
- console.log("save-expiration-component-version", "Saves the expiration component version for a company.");
163
+ console.log(
164
+ "save-expiration-component-version",
165
+ "Saves the expiration component version for a company.",
166
+ );
146
167
  console.log("Parameters:");
147
168
  console.log("--company [company_slug]");
148
169
  console.log("--component-version [component_version] Example: 'vue/2'");
149
- console.log("--resource-id (optional) [string] a resource cloud_id. include if you want to tie this component version to a resource");
170
+ console.log(
171
+ "--resource-id (optional) [string] a resource cloud_id. include if you want to tie this component version to a resource",
172
+ );
150
173
  console.log();
151
- console.log("delete-expiration-component-version", "Deletes the expiration component version for a company.");
174
+ console.log(
175
+ "delete-expiration-component-version",
176
+ "Deletes the expiration component version for a company.",
177
+ );
152
178
  console.log("Parameters:");
153
179
  console.log("--company [company_slug]");
154
180
  console.log("--component-version [component_version] Example: 'vue/2'");
155
- console.log("--resource-id (optional) [string] a resource cloud_id. include if you want to delete the tie between this component version and this resource");
181
+ console.log(
182
+ "--resource-id (optional) [string] a resource cloud_id. include if you want to delete the tie between this component version and this resource",
183
+ );
156
184
  console.log();
157
185
  }
158
186
 
@@ -180,6 +208,7 @@ const expirationInfoModule = (action, ...args) => {
180
208
  };
181
209
 
182
210
  expirationInfoModule.requiresLogin = true;
183
- expirationInfoModule.description = "Provides access to details about expirations tracked OpsCompass.";
211
+ expirationInfoModule.description =
212
+ "Provides access to details about expirations tracked OpsCompass.";
184
213
 
185
- module.exports = expirationInfoModule;
214
+ export default expirationInfoModule;