@opscompass/opscompass-cli 1.3.5 → 1.3.6

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,7 +1,9 @@
1
1
  import fs from "fs";
2
2
  import os from "os";
3
3
  import path from "path";
4
- import * as tar from "tar";
4
+ import crypto from "crypto";
5
+ import * as tarModule from "tar";
6
+ const tar = tarModule.create ? tarModule : tarModule.default;
5
7
  import * as openpgp from "openpgp";
6
8
 
7
9
  import { getOpsCompassClient } from "../../opscompass.js";
@@ -689,6 +691,89 @@ function isArchiveFile(filePath) {
689
691
  const lower = filePath.toLowerCase();
690
692
  return lower.endsWith(".tgz") || lower.endsWith(".tar.gz");
691
693
  }
694
+ function logCheckpointKey(company, account, logDirectory) {
695
+ return `${company}\u0000${account || ""}\u0000${path.resolve(logDirectory)}`;
696
+ }
697
+
698
+ function collectEligibleLogs(logDirectory, checkpointMs, startedAtMs) {
699
+ if (!fs.existsSync(logDirectory)) return { files: [], reason: "directory-missing" };
700
+ const stat = fs.statSync(logDirectory);
701
+ if (!stat.isDirectory()) return { files: [], reason: "not-a-directory" };
702
+ const files = fs.readdirSync(logDirectory, { withFileTypes: true })
703
+ .filter((entry) => entry.isFile() && !entry.isSymbolicLink())
704
+ .map((entry) => path.join(logDirectory, entry.name))
705
+ .filter((filePath) => {
706
+ try {
707
+ const mtimeMs = fs.statSync(filePath).mtimeMs;
708
+ return mtimeMs > checkpointMs && mtimeMs <= startedAtMs;
709
+ } catch (error) {
710
+ if (error?.code === "ENOENT") return false;
711
+ throw error;
712
+ }
713
+ });
714
+ return { files };
715
+ }
716
+
717
+ async function createLogsArchive(logDirectory, checkpointMs, startedAtMs) {
718
+ const eligible = collectEligibleLogs(logDirectory, checkpointMs, startedAtMs);
719
+ if (eligible.reason || eligible.files.length === 0) return eligible;
720
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "opscompass-send-dg-logs-"));
721
+ const archivePath = path.join(
722
+ tempDir,
723
+ `opscompass-dg-logs_${toTimestamp()}_${crypto.randomUUID()}.tgz`,
724
+ );
725
+ try {
726
+ await tar.create({
727
+ file: archivePath,
728
+ gzip: true,
729
+ cwd: logDirectory,
730
+ }, eligible.files.map((filePath) => path.basename(filePath)));
731
+ } catch (error) {
732
+ fs.rmSync(tempDir, { recursive: true, force: true });
733
+ throw error;
734
+ }
735
+ return { files: eligible.files, archivePath, tempDir };
736
+ }
737
+
738
+ async function augmentArchiveWithLogs(archivePath, logsArchivePath, encrypted, account) {
739
+ const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "opscompass-send-dg-repack-"));
740
+ const inputArchive = path.join(tempRoot, "input.tgz");
741
+ const outputArchive = path.join(tempRoot, "output.tgz");
742
+ try {
743
+ if (encrypted) {
744
+ const encryptedBytes = fs.readFileSync(archivePath);
745
+ const message = await openpgp.readMessage({ binaryMessage: encryptedBytes });
746
+ const { data } = await openpgp.decrypt({
747
+ message,
748
+ passwords: [`${utilsModule.hobKey}${account}`],
749
+ format: "binary",
750
+ });
751
+ fs.writeFileSync(inputArchive, Buffer.from(data));
752
+ } else {
753
+ fs.copyFileSync(archivePath, inputArchive);
754
+ }
755
+ const extractedDir = path.join(tempRoot, "extracted");
756
+ fs.mkdirSync(extractedDir);
757
+ await tar.extract({ file: inputArchive, cwd: extractedDir });
758
+ fs.copyFileSync(logsArchivePath, path.join(extractedDir, path.basename(logsArchivePath)));
759
+ const entries = fs.readdirSync(extractedDir);
760
+ await tar.create({ file: outputArchive, gzip: true, cwd: extractedDir }, entries);
761
+ if (!encrypted) {
762
+ fs.copyFileSync(outputArchive, archivePath);
763
+ return { filePath: archivePath };
764
+ }
765
+ const encryptedOutput = await encryptFile(outputArchive, account);
766
+ const stableOutputDir = fs.mkdtempSync(path.join(os.tmpdir(), "opscompass-send-dg-log-upload-"));
767
+ const stableOutput = path.join(
768
+ stableOutputDir,
769
+ `${path.basename(archivePath).replace(/\.gpg$/i, "")}.gpg`,
770
+ );
771
+ fs.copyFileSync(encryptedOutput, stableOutput);
772
+ return { filePath: stableOutput, tempDir: stableOutputDir };
773
+ } finally {
774
+ fs.rmSync(tempRoot, { recursive: true, force: true });
775
+ }
776
+ }
692
777
 
693
778
  async function sendDgAction(args = [], logger = { emit: () => {} }) {
694
779
  const params = {
@@ -699,6 +784,7 @@ async function sendDgAction(args = [], logger = { emit: () => {} }) {
699
784
  company: undefined,
700
785
  account: undefined,
701
786
  directory: process.cwd(),
787
+ logDirectory: path.join(utilsModule.opscompassHome, "log"),
702
788
  };
703
789
 
704
790
  function readFlagValue(arr, idx, flag) {
@@ -740,6 +826,10 @@ async function sendDgAction(args = [], logger = { emit: () => {} }) {
740
826
  params.directory = readFlagValue(args, i, arg);
741
827
  i += 1;
742
828
  break;
829
+ case "--log-directory":
830
+ params.logDirectory = readFlagValue(args, i, arg);
831
+ i += 1;
832
+ break;
743
833
  default:
744
834
  if (arg.startsWith("--")) {
745
835
  throw new DataGatheringError(`Unknown flag: ${arg}`, {
@@ -857,6 +947,52 @@ async function sendDgAction(args = [], logger = { emit: () => {} }) {
857
947
  seq = nextSeq(archiveSeq);
858
948
  }
859
949
  }
950
+ const startedAtMs = Date.now();
951
+ const checkpointKey = logCheckpointKey(params.company, params.account, params.logDirectory);
952
+ const previousCheckpoint = Number(state.logCheckpoints?.[checkpointKey]?.successfulAtMs || 0);
953
+ let logArchivePath;
954
+ let logArchiveTempDir;
955
+ const stableOutputTempDirs = new Set();
956
+ let logFiles = [];
957
+ let logSendItem;
958
+ let logSendSucceeded = false;
959
+ try {
960
+ const logResult = await createLogsArchive(path.resolve(params.logDirectory), previousCheckpoint, startedAtMs);
961
+ logArchiveTempDir = logResult.tempDir;
962
+ if (logResult.reason || !logResult.archivePath) {
963
+ logger.emit("send-dg.logs-skipped", { directory: params.logDirectory, reason: logResult.reason || "no-eligible-files" });
964
+ } else {
965
+ logArchivePath = logResult.archivePath;
966
+ logFiles = logResult.files;
967
+ const target = toSend.find((item) => isArchiveFile(item.filePath) || isEncryptedFile(item.filePath));
968
+ if (target) {
969
+ const originalPath = target.filePath;
970
+ const augmented = await augmentArchiveWithLogs(
971
+ originalPath,
972
+ logArchivePath,
973
+ isEncryptedFile(originalPath),
974
+ params.account,
975
+ );
976
+ target.filePath = augmented.filePath;
977
+ if (augmented.tempDir) stableOutputTempDirs.add(augmented.tempDir);
978
+ logSendItem = target;
979
+ }
980
+ }
981
+ } catch (error) {
982
+ logFiles = [];
983
+ logArchivePath = undefined;
984
+ logger.emit("send-dg.logs-skipped", {
985
+ directory: params.logDirectory,
986
+ reason: "archive-failed",
987
+ message: error?.message || String(error),
988
+ });
989
+ }
990
+ if (logArchiveTempDir) {
991
+ fs.rmSync(logArchiveTempDir, { recursive: true, force: true });
992
+ logArchiveTempDir = undefined;
993
+ }
994
+
995
+ try {
860
996
 
861
997
  for (const sendItem of toSend) {
862
998
  const filePath = sendItem.filePath;
@@ -935,6 +1071,9 @@ async function sendDgAction(args = [], logger = { emit: () => {} }) {
935
1071
  );
936
1072
  }
937
1073
  logger.emit("send-dg.sent", { file: path.basename(encrypted), logicalName });
1074
+ if (sendItem === logSendItem) {
1075
+ logSendSucceeded = true;
1076
+ }
938
1077
 
939
1078
  try {
940
1079
  if (!isEncryptedFile(filePath) && generatedArchives.has(filePath) && fs.existsSync(filePath)) {
@@ -952,7 +1091,20 @@ async function sendDgAction(args = [], logger = { emit: () => {} }) {
952
1091
  }
953
1092
  }
954
1093
 
1094
+ if (logSendSucceeded && logFiles.length > 0) {
1095
+ await withStateLock(async () => {
1096
+ const currentState = loadState();
1097
+ currentState.logCheckpoints = currentState.logCheckpoints || {};
1098
+ currentState.logCheckpoints[checkpointKey] = { successfulAtMs: startedAtMs };
1099
+ saveState(currentState);
1100
+ });
1101
+ }
955
1102
  return { exitCode: DATA_GATHERING_EXIT_CODES.success };
1103
+ } finally {
1104
+ for (const tempDir of stableOutputTempDirs) {
1105
+ fs.rmSync(tempDir, { recursive: true, force: true });
1106
+ }
1107
+ }
956
1108
  }
957
1109
 
958
1110
  function nextSeq(value) {
@@ -28,6 +28,25 @@ const DATA_GATHERING_OUTPUT_EVENT_TYPE = Object.freeze({
28
28
  stdout: "process.stdout",
29
29
  stderr: "process.stderr",
30
30
  });
31
+ const DATA_GATHERING_CAPABILITIES = Object.freeze({
32
+ sendDg: true,
33
+ logDirectory: true,
34
+ });
35
+
36
+ // WHY: filemon runs independently from the CLI package and needs a stable runtime contract.
37
+ // DECISION: expose capabilities directly instead of making callers infer support from versions or help text.
38
+ function printDataGatheringCapabilities() {
39
+ const capabilities = {
40
+ version: 1,
41
+ sendDg: DATA_GATHERING_CAPABILITIES.sendDg,
42
+ logDirectory: DATA_GATHERING_CAPABILITIES.logDirectory,
43
+ };
44
+ console.log(JSON.stringify(capabilities));
45
+ return {
46
+ exitCode: DATA_GATHERING_EXIT_CODES.success,
47
+ capabilities,
48
+ };
49
+ }
31
50
 
32
51
  function parseDataGatheringGlobalArgs(args) {
33
52
  const options = {
@@ -555,7 +574,7 @@ async function printDataGatheringHelp(ui = createDataGatheringUi()) {
555
574
  ui.blank();
556
575
  ui.section("Actions");
557
576
  ui.item("run", "Run downloaded data-gathering scripts or emit a dry-run plan.");
558
- ui.item("list-modules", "List installed script modules visible to the CLI.");
577
+ ui.item("capabilities", "Print machine-readable data-gathering CLI capabilities.");
559
578
  ui.item("validate-install", "Check required data-gathering dependencies.");
560
579
  ui.item("setup", "Run the data-gathering setup wizard.");
561
580
  ui.item("send-dg", "Package, encrypt, and transfer DG artifacts. Plain-file batches reject duplicate basenames.");
@@ -615,6 +634,8 @@ async function runDataGatheringAction(action, args) {
615
634
  return await runDataGathering(remainingArgs, logger);
616
635
  case "list-modules":
617
636
  return await listModules(logger);
637
+ case "capabilities":
638
+ return printDataGatheringCapabilities();
618
639
  case "validate-install":
619
640
  return await runValidateInstallCommand(remainingArgs, logger, { ui });
620
641
  case "setup":
@@ -721,6 +742,7 @@ export {
721
742
  parsePositiveInteger,
722
743
  parseRunArgs,
723
744
  printDataGatheringHelp,
745
+ printDataGatheringCapabilities,
724
746
  readRequiredFlagValue,
725
747
  resolveTargetModules,
726
748
  runDataGathering,
@@ -250,6 +250,7 @@ async function getMssqlAssessmentResources(args) {
250
250
  }
251
251
 
252
252
  async function checkMssqlConfigMetadata(args) {
253
+ let callParams = {};
253
254
  for (let i = 0; i < args.length - 1; i++) {
254
255
  switch (args[i].toLowerCase()) {
255
256
  case "--account-id":
@@ -469,6 +470,7 @@ async function getMssqlConfiguration(args) {
469
470
  }
470
471
 
471
472
  async function updateMssqlConfiguration(args) {
473
+ let callParams = {};
472
474
  for (let i = 0; i < args.length - 1; i++) {
473
475
  switch (args[i].toLowerCase()) {
474
476
  case "--id":
@@ -0,0 +1,462 @@
1
+ import { getOpsCompassClient } from "../../opscompass.js";
2
+
3
+ /**
4
+ * Guard that the next argument in args at i+1 is present and not another flag.
5
+ * If invalid, prints an error to stderr and returns false.
6
+ * @param {string[]} args - CLI arguments array
7
+ * @param {number} i - Current index in args
8
+ * @param {string} flagName - Flag name for error messages (without -- prefix)
9
+ * @returns {boolean} true if the next argument is a valid value
10
+ */
11
+ function requireArgValue(args, i, flagName) {
12
+ if (i + 1 >= args.length || args[i + 1] === undefined) {
13
+ console.error(`ERROR: --${flagName} requires a value.`);
14
+ return false;
15
+ }
16
+ if (args[i + 1].startsWith("--")) {
17
+ console.error(`ERROR: --${flagName} requires a value (got "${args[i + 1]}").`);
18
+ return false;
19
+ }
20
+ return true;
21
+ }
22
+
23
+ /**
24
+ * Validate that raw string value is a positive integer.
25
+ * Prints an error to stderr on failure.
26
+ * @param {string} value - Raw string value to validate
27
+ * @param {string} flagName - Flag name for error messages
28
+ * @returns {number|undefined} The parsed positive integer, or undefined on error
29
+ */
30
+ function validatePositiveIntFlag(value, flagName) {
31
+ const n = Number(value);
32
+ if (isNaN(n) || n < 1 || !Number.isSafeInteger(n)) {
33
+ console.error(`ERROR: --${flagName} must be a positive integer (got "${value}").`);
34
+ return undefined;
35
+ }
36
+ return n;
37
+ }
38
+
39
+ /**
40
+ * Validate that raw string value is a non-negative integer (0 or greater).
41
+ * Prints an error to stderr on failure.
42
+ * @param {string} value - Raw string value to validate
43
+ * @param {string} flagName - Flag name for error messages
44
+ * @returns {number|undefined} The parsed non-negative integer, or undefined on error
45
+ */
46
+ function validateNonNegativeIntFlag(value, flagName) {
47
+ const n = Number(value);
48
+ if (isNaN(n) || n < 0 || !Number.isSafeInteger(n)) {
49
+ console.error(`ERROR: --${flagName} must be a non-negative integer (got "${value}").`);
50
+ return undefined;
51
+ }
52
+ return n;
53
+ }
54
+
55
+ /**
56
+ * Client-side maximum pagination values for Oracle entitlement commands.
57
+ * These match the public API contract enforced by the service, allowing the CLI
58
+ * to reject obviously invalid requests before sending them.
59
+ */
60
+ const MAX_PAGINATION_LIMIT = 1000;
61
+ const MAX_PAGINATION_OFFSET = 10000;
62
+
63
+ /**
64
+ * @module license-manager:oracle
65
+ * @description License Manager Oracle entitlement read-only module for OpsCompass CLI
66
+ */
67
+
68
+ async function getOracleCurrentEntitlements(args) {
69
+ let companySlug = global.company;
70
+ let accountId = undefined;
71
+ let limit = undefined;
72
+ let offset = undefined;
73
+ for (let i = 0; i < args.length - 1; i++) {
74
+ switch (args[i].toLowerCase()) {
75
+ case "--company":
76
+ if (!requireArgValue(args, i, "company")) return;
77
+ companySlug = args[++i];
78
+ break;
79
+ case "--account-id":
80
+ case "--accountid":
81
+ if (!requireArgValue(args, i, "account-id")) return;
82
+ accountId = args[++i];
83
+ break;
84
+ case "--limit":
85
+ if (!requireArgValue(args, i, "limit")) return;
86
+ limit = args[++i];
87
+ break;
88
+ case "--offset":
89
+ if (!requireArgValue(args, i, "offset")) return;
90
+ offset = args[++i];
91
+ break;
92
+ }
93
+ }
94
+
95
+ if (accountId === undefined || accountId === null) {
96
+ console.error("ERROR: --account-id is required.");
97
+ return;
98
+ }
99
+
100
+ const parsedAccountId = validatePositiveIntFlag(accountId, "account-id");
101
+ if (parsedAccountId === undefined) return;
102
+
103
+ const options = {};
104
+ if (limit !== undefined) {
105
+ const n = validatePositiveIntFlag(limit, "limit");
106
+ if (n === undefined) return;
107
+ if (n > MAX_PAGINATION_LIMIT) {
108
+ console.error(`ERROR: --limit must not exceed ${MAX_PAGINATION_LIMIT} (got ${n}).`);
109
+ return;
110
+ }
111
+ options.limit = n;
112
+ }
113
+ if (offset !== undefined) {
114
+ const n = validateNonNegativeIntFlag(offset, "offset");
115
+ if (n === undefined) return;
116
+ if (n > MAX_PAGINATION_OFFSET) {
117
+ console.error(`ERROR: --offset must not exceed ${MAX_PAGINATION_OFFSET} (got ${n}).`);
118
+ return;
119
+ }
120
+ options.offset = n;
121
+ }
122
+
123
+ const client = await getOpsCompassClient();
124
+ const result = await client.licenseManager.getOracleCurrentEntitlements(
125
+ companySlug,
126
+ parsedAccountId,
127
+ Object.keys(options).length > 0 ? options : undefined,
128
+ );
129
+ console.log(JSON.stringify(result, null, 2));
130
+ }
131
+
132
+ async function listOracleMetrics(args) {
133
+ let companySlug = global.company;
134
+ let limit = undefined;
135
+ let offset = undefined;
136
+ for (let i = 0; i < args.length - 1; i++) {
137
+ switch (args[i].toLowerCase()) {
138
+ case "--company":
139
+ if (!requireArgValue(args, i, "company")) return;
140
+ companySlug = args[++i];
141
+ break;
142
+ case "--limit":
143
+ if (!requireArgValue(args, i, "limit")) return;
144
+ limit = args[++i];
145
+ break;
146
+ case "--offset":
147
+ if (!requireArgValue(args, i, "offset")) return;
148
+ offset = args[++i];
149
+ break;
150
+ }
151
+ }
152
+
153
+ const options = {};
154
+ if (limit !== undefined) {
155
+ const n = validatePositiveIntFlag(limit, "limit");
156
+ if (n === undefined) return;
157
+ if (n > MAX_PAGINATION_LIMIT) {
158
+ console.error(`ERROR: --limit must not exceed ${MAX_PAGINATION_LIMIT} (got ${n}).`);
159
+ return;
160
+ }
161
+ options.limit = n;
162
+ }
163
+ if (offset !== undefined) {
164
+ const n = validateNonNegativeIntFlag(offset, "offset");
165
+ if (n === undefined) return;
166
+ if (n > MAX_PAGINATION_OFFSET) {
167
+ console.error(`ERROR: --offset must not exceed ${MAX_PAGINATION_OFFSET} (got ${n}).`);
168
+ return;
169
+ }
170
+ options.offset = n;
171
+ }
172
+
173
+ const client = await getOpsCompassClient();
174
+ const result = await client.licenseManager.listOracleMetrics(
175
+ companySlug,
176
+ Object.keys(options).length > 0 ? options : undefined,
177
+ );
178
+ console.log(JSON.stringify(result, null, 2));
179
+ }
180
+
181
+ async function listOracleLimitations(args) {
182
+ let companySlug = global.company;
183
+ let limit = undefined;
184
+ let offset = undefined;
185
+ for (let i = 0; i < args.length - 1; i++) {
186
+ switch (args[i].toLowerCase()) {
187
+ case "--company":
188
+ if (!requireArgValue(args, i, "company")) return;
189
+ companySlug = args[++i];
190
+ break;
191
+ case "--limit":
192
+ if (!requireArgValue(args, i, "limit")) return;
193
+ limit = args[++i];
194
+ break;
195
+ case "--offset":
196
+ if (!requireArgValue(args, i, "offset")) return;
197
+ offset = args[++i];
198
+ break;
199
+ }
200
+ }
201
+
202
+ const options = {};
203
+ if (limit !== undefined) {
204
+ const n = validatePositiveIntFlag(limit, "limit");
205
+ if (n === undefined) return;
206
+ if (n > MAX_PAGINATION_LIMIT) {
207
+ console.error(`ERROR: --limit must not exceed ${MAX_PAGINATION_LIMIT} (got ${n}).`);
208
+ return;
209
+ }
210
+ options.limit = n;
211
+ }
212
+ if (offset !== undefined) {
213
+ const n = validateNonNegativeIntFlag(offset, "offset");
214
+ if (n === undefined) return;
215
+ if (n > MAX_PAGINATION_OFFSET) {
216
+ console.error(`ERROR: --offset must not exceed ${MAX_PAGINATION_OFFSET} (got ${n}).`);
217
+ return;
218
+ }
219
+ options.offset = n;
220
+ }
221
+
222
+ const client = await getOpsCompassClient();
223
+ const result = await client.licenseManager.listOracleLimitations(
224
+ companySlug,
225
+ Object.keys(options).length > 0 ? options : undefined,
226
+ );
227
+ console.log(JSON.stringify(result, null, 2));
228
+ }
229
+
230
+ async function listOracleProductAliases(args) {
231
+ let companySlug = global.company;
232
+ let limit = undefined;
233
+ let offset = undefined;
234
+ for (let i = 0; i < args.length - 1; i++) {
235
+ switch (args[i].toLowerCase()) {
236
+ case "--company":
237
+ if (!requireArgValue(args, i, "company")) return;
238
+ companySlug = args[++i];
239
+ break;
240
+ case "--limit":
241
+ if (!requireArgValue(args, i, "limit")) return;
242
+ limit = args[++i];
243
+ break;
244
+ case "--offset":
245
+ if (!requireArgValue(args, i, "offset")) return;
246
+ offset = args[++i];
247
+ break;
248
+ }
249
+ }
250
+
251
+ const options = {};
252
+ if (limit !== undefined) {
253
+ const n = validatePositiveIntFlag(limit, "limit");
254
+ if (n === undefined) return;
255
+ if (n > MAX_PAGINATION_LIMIT) {
256
+ console.error(`ERROR: --limit must not exceed ${MAX_PAGINATION_LIMIT} (got ${n}).`);
257
+ return;
258
+ }
259
+ options.limit = n;
260
+ }
261
+ if (offset !== undefined) {
262
+ const n = validateNonNegativeIntFlag(offset, "offset");
263
+ if (n === undefined) return;
264
+ if (n > MAX_PAGINATION_OFFSET) {
265
+ console.error(`ERROR: --offset must not exceed ${MAX_PAGINATION_OFFSET} (got ${n}).`);
266
+ return;
267
+ }
268
+ options.offset = n;
269
+ }
270
+
271
+ const client = await getOpsCompassClient();
272
+ const result = await client.licenseManager.listOracleProductAliases(
273
+ companySlug,
274
+ Object.keys(options).length > 0 ? options : undefined,
275
+ );
276
+ console.log(JSON.stringify(result, null, 2));
277
+ }
278
+
279
+ async function listOracleOrders(args) {
280
+ let companySlug = global.company;
281
+ let accountId = undefined;
282
+ let limit = undefined;
283
+ let offset = undefined;
284
+ for (let i = 0; i < args.length - 1; i++) {
285
+ switch (args[i].toLowerCase()) {
286
+ case "--company":
287
+ if (!requireArgValue(args, i, "company")) return;
288
+ companySlug = args[++i];
289
+ break;
290
+ case "--account-id":
291
+ case "--accountid":
292
+ if (!requireArgValue(args, i, "account-id")) return;
293
+ accountId = args[++i];
294
+ break;
295
+ case "--limit":
296
+ if (!requireArgValue(args, i, "limit")) return;
297
+ limit = args[++i];
298
+ break;
299
+ case "--offset":
300
+ if (!requireArgValue(args, i, "offset")) return;
301
+ offset = args[++i];
302
+ break;
303
+ }
304
+ }
305
+
306
+ if (accountId === undefined || accountId === null) {
307
+ console.error("ERROR: --account-id is required.");
308
+ return;
309
+ }
310
+
311
+ const parsedAccountId = validatePositiveIntFlag(accountId, "account-id");
312
+ if (parsedAccountId === undefined) return;
313
+
314
+ const options = {};
315
+ if (limit !== undefined) {
316
+ const n = validatePositiveIntFlag(limit, "limit");
317
+ if (n === undefined) return;
318
+ if (n > MAX_PAGINATION_LIMIT) {
319
+ console.error(`ERROR: --limit must not exceed ${MAX_PAGINATION_LIMIT} (got ${n}).`);
320
+ return;
321
+ }
322
+ options.limit = n;
323
+ }
324
+ if (offset !== undefined) {
325
+ const n = validateNonNegativeIntFlag(offset, "offset");
326
+ if (n === undefined) return;
327
+ if (n > MAX_PAGINATION_OFFSET) {
328
+ console.error(`ERROR: --offset must not exceed ${MAX_PAGINATION_OFFSET} (got ${n}).`);
329
+ return;
330
+ }
331
+ options.offset = n;
332
+ }
333
+
334
+ const client = await getOpsCompassClient();
335
+ const result = await client.licenseManager.listOracleOrders(
336
+ companySlug,
337
+ parsedAccountId,
338
+ Object.keys(options).length > 0 ? options : undefined,
339
+ );
340
+ console.log(JSON.stringify(result, null, 2));
341
+ }
342
+
343
+ async function getOracleOrderItems(args) {
344
+ let companySlug = global.company;
345
+ let accountId = undefined;
346
+ const orderItemIds = [];
347
+ for (let i = 0; i < args.length - 1; i++) {
348
+ switch (args[i].toLowerCase()) {
349
+ case "--company":
350
+ if (!requireArgValue(args, i, "company")) return;
351
+ companySlug = args[++i];
352
+ break;
353
+ case "--account-id":
354
+ case "--accountid":
355
+ if (!requireArgValue(args, i, "account-id")) return;
356
+ accountId = args[++i];
357
+ break;
358
+ case "--id":
359
+ if (!requireArgValue(args, i, "id")) return;
360
+ orderItemIds.push(args[++i]);
361
+ break;
362
+ }
363
+ }
364
+
365
+ if (accountId === undefined || accountId === null) {
366
+ console.error("ERROR: --account-id is required.");
367
+ return;
368
+ }
369
+
370
+ if (orderItemIds.length === 0) {
371
+ console.error("ERROR: At least one --id is required.");
372
+ return;
373
+ }
374
+
375
+ // Validate each --id value is a positive integer before dispatch
376
+ for (const rawId of orderItemIds) {
377
+ if (validatePositiveIntFlag(rawId, "id") === undefined) return;
378
+ }
379
+
380
+ const client = await getOpsCompassClient();
381
+ try {
382
+ const result = await client.licenseManager.getOracleOrderItems(
383
+ companySlug,
384
+ Number(accountId),
385
+ orderItemIds.map(Number),
386
+ );
387
+ console.log(JSON.stringify(result, null, 2));
388
+ } catch (err) {
389
+ console.error("ERROR:", err.message);
390
+ }
391
+ }
392
+
393
+ async function printOracleHelp() {
394
+ console.log();
395
+ console.log(
396
+ "get-oracle-current-entitlements",
397
+ "Gets current Oracle entitlements for the specified account.",
398
+ );
399
+ console.log("Parameters:");
400
+ console.log("--company [company_slug] (optional, defaults to current company)");
401
+ console.log("--account-id [number] The account ID to retrieve entitlements for.");
402
+ console.log(`--limit [number] (optional) Maximum number of results to return (max ${MAX_PAGINATION_LIMIT}), e.g. --limit 50.`);
403
+ console.log(`--offset [number] (optional) Number of results to skip for pagination (max ${MAX_PAGINATION_OFFSET}), e.g. --offset 100.`);
404
+ console.log();
405
+ console.log(
406
+ "list-oracle-metrics",
407
+ "Lists Oracle metric reference data.",
408
+ );
409
+ console.log("Parameters:");
410
+ console.log("--company [company_slug] (optional, defaults to current company)");
411
+ console.log(`--limit [number] (optional) Maximum number of results to return (max ${MAX_PAGINATION_LIMIT}), e.g. --limit 50.`);
412
+ console.log(`--offset [number] (optional) Number of results to skip for pagination (max ${MAX_PAGINATION_OFFSET}), e.g. --offset 100.`);
413
+ console.log();
414
+ console.log(
415
+ "list-oracle-limitations",
416
+ "Lists Oracle limitation reference data.",
417
+ );
418
+ console.log("Parameters:");
419
+ console.log("--company [company_slug] (optional, defaults to current company)");
420
+ console.log(`--limit [number] (optional) Maximum number of results to return (max ${MAX_PAGINATION_LIMIT}), e.g. --limit 50.`);
421
+ console.log(`--offset [number] (optional) Number of results to skip for pagination (max ${MAX_PAGINATION_OFFSET}), e.g. --offset 100.`);
422
+ console.log();
423
+ console.log(
424
+ "list-oracle-product-aliases",
425
+ "Lists Oracle product-alias lookup data.",
426
+ );
427
+ console.log("Parameters:");
428
+ console.log("--company [company_slug] (optional, defaults to current company)");
429
+ console.log(`--limit [number] (optional) Maximum number of results to return (max ${MAX_PAGINATION_LIMIT}), e.g. --limit 50.`);
430
+ console.log(`--offset [number] (optional) Number of results to skip for pagination (max ${MAX_PAGINATION_OFFSET}), e.g. --offset 100.`);
431
+ console.log();
432
+ console.log(
433
+ "list-oracle-orders",
434
+ "Lists Oracle orders for the specified account.",
435
+ );
436
+ console.log("Parameters:");
437
+ console.log("--company [company_slug] (optional, defaults to current company)");
438
+ console.log("--account-id [number] The account ID to retrieve orders for.");
439
+ console.log(`--limit [number] (optional) Maximum number of results to return (max ${MAX_PAGINATION_LIMIT}), e.g. --limit 50.`);
440
+ console.log(`--offset [number] (optional) Number of results to skip for pagination (max ${MAX_PAGINATION_OFFSET}), e.g. --offset 100.`);
441
+ console.log();
442
+ console.log(
443
+ "get-oracle-order-items",
444
+ "Gets Oracle order-item details for the specified IDs.",
445
+ );
446
+ console.log("Parameters:");
447
+ console.log("--company [company_slug] (optional, defaults to current company)");
448
+ console.log("--account-id [number] The account ID to scope the request.");
449
+ console.log('--id [number] Use parameter multiple times to retrieve multiple items, e.g. --id 10 --id 11');
450
+ console.log("Note: A maximum of 100 order-item IDs can be requested at once.");
451
+ console.log();
452
+ }
453
+
454
+ export {
455
+ getOracleCurrentEntitlements,
456
+ listOracleMetrics,
457
+ listOracleLimitations,
458
+ listOracleProductAliases,
459
+ listOracleOrders,
460
+ getOracleOrderItems,
461
+ printOracleHelp,
462
+ };
@@ -37,6 +37,17 @@ import {
37
37
  deleteMssqlConfiguration,
38
38
  } from "./license-manager/microsoft.js";
39
39
 
40
+ // Oracle entitlement read-only functions
41
+ import {
42
+ printOracleHelp,
43
+ getOracleCurrentEntitlements,
44
+ listOracleMetrics,
45
+ listOracleLimitations,
46
+ listOracleProductAliases,
47
+ listOracleOrders,
48
+ getOracleOrderItems,
49
+ } from "./license-manager/oracle.js";
50
+
40
51
  // Vcenter configuration functions
41
52
  import {
42
53
  printVcenterHelp,
@@ -1114,6 +1125,9 @@ async function printHelp() {
1114
1125
  );
1115
1126
  console.log();
1116
1127
 
1128
+ // Add Oracle help
1129
+ printOracleHelp();
1130
+
1117
1131
  // Add Mssql help
1118
1132
  printMssqlHelp();
1119
1133
 
@@ -1252,6 +1266,18 @@ const licenseManagerModule = (action, ...args) => {
1252
1266
  return updateNutanixConfigurations(args);
1253
1267
  case "delete-nutanix-configuration":
1254
1268
  return deleteNutanixConfiguration(args);
1269
+ case "get-oracle-current-entitlements":
1270
+ return getOracleCurrentEntitlements(args);
1271
+ case "list-oracle-metrics":
1272
+ return listOracleMetrics(args);
1273
+ case "list-oracle-limitations":
1274
+ return listOracleLimitations(args);
1275
+ case "list-oracle-product-aliases":
1276
+ return listOracleProductAliases(args);
1277
+ case "list-oracle-orders":
1278
+ return listOracleOrders(args);
1279
+ case "get-oracle-order-items":
1280
+ return getOracleOrderItems(args);
1255
1281
  case "help":
1256
1282
  case "":
1257
1283
  return printHelp();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opscompass/opscompass-cli",
3
- "version": "1.3.5",
3
+ "version": "1.3.6",
4
4
  "description": "Calls OpsCompass's APIs",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -24,11 +24,11 @@
24
24
  "author": "opscompass",
25
25
  "license": "SEE LICENSE IN license.txt",
26
26
  "engines": {
27
- "node": ">=22 <23 || >=24 <25"
27
+ "node": "22 || 24 || 26"
28
28
  },
29
29
  "dependencies": {
30
- "@opscompass/opscompass-api": "^1.3.4",
31
- "adm-zip": "^0.5.16",
30
+ "@opscompass/opscompass-api": "^1.3.6",
31
+ "adm-zip": "^0.6.0",
32
32
  "axios": "^1.18.1",
33
33
  "better-sqlite3": "12.11.1",
34
34
  "fs-extra": "^10.1.0",
@@ -36,7 +36,7 @@
36
36
  "open": "^8.2.1",
37
37
  "openpgp": "6.2.2",
38
38
  "semver": "^7.3.7",
39
- "tar": "^7.5.16"
39
+ "tar": "^7.5.22"
40
40
  },
41
41
  "devDependencies": {
42
42
  "jest": "^30.4.2"