@opscompass/opscompass-cli 1.0.14 → 1.0.16

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.
@@ -4,11 +4,13 @@ const actionMap = {
4
4
  "get": "get",
5
5
  "get-compliance": "getCompliance",
6
6
  "get-drift": "getDrift",
7
+ "get-tags": "getTags",
8
+ "add-tags": "addTags",
9
+ "remove-tags": "removeTags",
7
10
  "list": "list",
8
11
  };
9
12
 
10
13
  async function get(action, args) {
11
- const callParams = {};
12
14
  for (let i = 0; i < args.length - 1; i++) {
13
15
  switch (args[i].toLowerCase()) {
14
16
  case "--company":
@@ -60,7 +62,6 @@ async function get(action, args) {
60
62
  }
61
63
 
62
64
  async function list(args) {
63
- const callParams = {};
64
65
  for (let i = 0; i < args.length - 1; i++) {
65
66
  switch (args[i].toLowerCase()) {
66
67
  case "--company":
@@ -108,6 +109,16 @@ async function list(args) {
108
109
  callParams.resourceTypes = args[++i];
109
110
  }
110
111
  break;
112
+ case "--tags":
113
+ if (typeof callParams.tags === "string") {
114
+ callParams.tags = [callParams.tags];
115
+ }
116
+ if (Array.isArray(callParams.tags)) {
117
+ callParams.tags.push(args[++i]);
118
+ } else {
119
+ callParams.tags = args[++i];
120
+ }
121
+ break;
111
122
  case "--resource-creation-date-beginning":
112
123
  case "--resourcecreationdatebeginning":
113
124
  callParams.resourceCreationDateBeginning = args[++i];
@@ -135,6 +146,35 @@ async function list(args) {
135
146
  console.log(JSON.stringify(resource, null, 2));
136
147
  }
137
148
 
149
+ async function tags(action, args) {
150
+ const callData = {};
151
+ for (let i = 0; i < args.length - 1; i++) {
152
+ switch (args[i].toLowerCase()) {
153
+ case "--company":
154
+ callData.company = args[++i];
155
+ break;
156
+ case "--id":
157
+ callData.id = args[++i];
158
+ break;
159
+ case "--resourceid":
160
+ case "--resource-id":
161
+ callData.resourceId = args[++i];
162
+ break;
163
+ case "--tag":
164
+ if (Array.isArray(callData.tags)) {
165
+ callData.tags.push(args[++i]);
166
+ } else {
167
+ callData.tags = [args[++i]];
168
+ }
169
+ break;
170
+ }
171
+ }
172
+
173
+ const client = await getOpsCompassClient();
174
+ const resource = await client.resources[actionMap[action]](callData);
175
+ console.log(JSON.stringify(resource, null, 2));
176
+ }
177
+
138
178
  async function getUsageAnalytics(args) {
139
179
  let resourceId = undefined;
140
180
  let metricType = undefined;
@@ -219,6 +259,12 @@ async function printHelp() {
219
259
  console.log("--concern \"concern name\"");
220
260
  console.log("--type [configuration_alert | security_alert]");
221
261
  console.log();
262
+ console.log("get-tags", "Gets tags attached to a resource.");
263
+ console.log("Parameters:");
264
+ console.log("--company [company_id]");
265
+ console.log("--id [12345]");
266
+ console.log("--resource-id [cloud-resource-id]");
267
+ console.log();
222
268
  console.log("list", "Lists a set of resources that match any given criteria.");
223
269
  console.log("Parameters:");
224
270
  console.log("--company [company_id]");
@@ -226,12 +272,27 @@ async function printHelp() {
226
272
  console.log("--cloud-providers [aws | azure | gcp | microsoft365]");
227
273
  console.log("--resource-types [resource-type-name]");
228
274
  console.log("--region-ids [region-id]");
275
+ console.log("--tags [tag-value]")
229
276
  console.log("--resource-creation-date-beginning [\"2020-11-11 00:00:00.000\"]");
230
277
  console.log("--resource-creation-date-end [\"2021-11-11 00:00:00.000\"]");
231
278
  console.log("--open-compliance-issues [true | false]");
232
279
  console.log("--unacknowledged-changes [true | false]");
233
280
  console.log("--skip [12345]");
234
281
  console.log();
282
+ console.log("add-tags", "Attaches one or more tags to a resource.");
283
+ console.log("Parameters:");
284
+ console.log("--company [company_id]");
285
+ console.log("--id [12345]");
286
+ console.log("--resource-id [cloud-resource-id]");
287
+ console.log("--tag [tag-value]");
288
+ console.log();
289
+ console.log("remove-tags", "Removes one or more tags to a resource.");
290
+ console.log("Parameters:");
291
+ console.log("--company [company_id]");
292
+ console.log("--id [12345]");
293
+ console.log("--resource-id [cloud-resource-id]");
294
+ console.log("--tag [tag-value]");
295
+ console.log();
235
296
  console.log("get-usage-analytics", "Calculates the resource usage analytics for given criteria.");
236
297
  console.log("Parameters:");
237
298
  console.log("--id [resource_id]");
@@ -253,7 +314,11 @@ const resourcesModule = (action, ...args) => {
253
314
  case "get":
254
315
  case "get-compliance":
255
316
  case "get-drift":
317
+ case "get-tags":
256
318
  return get(action, args);
319
+ case "add-tags":
320
+ case "remove-tags":
321
+ return tags(action, args);
257
322
  case "list":
258
323
  return list(args)
259
324
  case "get-usage-analytics":
package/modules.js CHANGED
@@ -3,6 +3,7 @@ const accounts = require("./modules/accounts.js");
3
3
  const licenseManager = require("./modules/license-manager.js");
4
4
  const compliance = require("./modules/compliance.js");
5
5
  const dataGatheringScripts = require("./modules/data-gathering-scripts.js");
6
+ const defaults = require("./modules/defaults.js");
6
7
 
7
8
 
8
9
  /* login acts like a module, even though it's special */
@@ -12,7 +13,8 @@ module.exports = {
12
13
  login,
13
14
  resources,
14
15
  accounts,
15
- compliance,
16
+ compliance,
17
+ defaults,
16
18
  "license-manager": licenseManager,
17
19
  "data-gathering-scripts": dataGatheringScripts
18
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opscompass/opscompass-cli",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "Calls OpsCompass's APIs",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,7 @@
15
15
  "author": "opscompass",
16
16
  "license": "SEE LICENSE IN license.txt",
17
17
  "dependencies": {
18
- "@opscompass/opscompass-api": "^1.0.14",
18
+ "@opscompass/opscompass-api": "^1.0.16",
19
19
  "adm-zip": "^0.5.9",
20
20
  "axios": "^0.21.1",
21
21
  "fs-extra": "^10.1.0",