@dishantlangayan/solace-cloud-cli 0.0.2 → 0.0.4
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.
- package/README.md +158 -35
- package/dist/commands/missionctrl/broker/create.d.ts +4 -3
- package/dist/commands/missionctrl/broker/create.js +12 -18
- package/dist/commands/missionctrl/broker/delete.d.ts +5 -3
- package/dist/commands/missionctrl/broker/delete.js +16 -4
- package/dist/commands/missionctrl/broker/display.d.ts +4 -3
- package/dist/commands/missionctrl/broker/display.js +12 -16
- package/dist/commands/missionctrl/broker/list.d.ts +4 -3
- package/dist/commands/missionctrl/broker/list.js +7 -4
- package/dist/commands/missionctrl/broker/opstatus.d.ts +15 -0
- package/dist/commands/missionctrl/broker/opstatus.js +159 -0
- package/dist/commands/missionctrl/broker/update.d.ts +15 -0
- package/dist/commands/missionctrl/broker/update.js +77 -0
- package/dist/commands/platform/env/create.d.ts +5 -4
- package/dist/commands/platform/env/create.js +11 -18
- package/dist/commands/platform/env/delete.d.ts +5 -3
- package/dist/commands/platform/env/delete.js +19 -7
- package/dist/commands/platform/env/display.d.ts +4 -3
- package/dist/commands/platform/env/display.js +12 -17
- package/dist/commands/platform/env/list.d.ts +4 -3
- package/dist/commands/platform/env/list.js +21 -17
- package/dist/commands/platform/env/update.d.ts +5 -4
- package/dist/commands/platform/env/update.js +14 -22
- package/dist/types/broker.d.ts +148 -14
- package/dist/util/internal.d.ts +15 -0
- package/dist/util/internal.js +34 -0
- package/dist/util/sc-connection.d.ts +1 -0
- package/dist/util/sc-connection.js +5 -0
- package/oclif.manifest.json +385 -15
- package/package.json +3 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { MultiBar, Presets } from 'cli-progress';
|
|
3
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
4
|
+
import { renderTable, sleep } from '../../../util/internal.js';
|
|
5
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
6
|
+
export default class MissionctrlBrokerOpstatus extends ScCommand {
|
|
7
|
+
static args = {};
|
|
8
|
+
static description = `Get the status of all operations being performed on an event broker service.
|
|
9
|
+
To get the operation status, you must provide the identifier or name of the event broker service.
|
|
10
|
+
|
|
11
|
+
Token Permissions: [ mission_control:access or services:get or services:get:self or services:view or services:view:self ]`;
|
|
12
|
+
static examples = [
|
|
13
|
+
'<%= config.bin %> <%= command.id %> -b <broker-id>',
|
|
14
|
+
'<%= config.bin %> <%= command.id %> -n <broker-name>',
|
|
15
|
+
];
|
|
16
|
+
static flags = {
|
|
17
|
+
'broker-id': Flags.string({
|
|
18
|
+
char: 'b',
|
|
19
|
+
description: 'Id of the event broker service.',
|
|
20
|
+
exactlyOne: ['broker-id', 'name'],
|
|
21
|
+
}),
|
|
22
|
+
name: Flags.string({
|
|
23
|
+
char: 'n',
|
|
24
|
+
description: 'Name of the event broker service.',
|
|
25
|
+
exactlyOne: ['broker-id', 'name'],
|
|
26
|
+
}),
|
|
27
|
+
'show-progress': Flags.boolean({
|
|
28
|
+
char: 'p',
|
|
29
|
+
description: 'Displays a status bar of the in-progress operations. The command will wait for completion of each step of the operation.',
|
|
30
|
+
}),
|
|
31
|
+
'wait-ms': Flags.integer({
|
|
32
|
+
char: 'w',
|
|
33
|
+
description: 'The milliseconds to wait between API calls for checking progress of the operation. Default is 5000 ms.',
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
async run() {
|
|
37
|
+
const { flags } = await this.parse(MissionctrlBrokerOpstatus);
|
|
38
|
+
const name = flags.name ?? '';
|
|
39
|
+
let brokerId = flags['broker-id'] ?? '';
|
|
40
|
+
const showProgress = flags['show-progress'] ?? false;
|
|
41
|
+
const waitMs = flags['wait-ms'] ?? 5000;
|
|
42
|
+
const conn = new ScConnection();
|
|
43
|
+
// Base API url
|
|
44
|
+
let apiUrl = `/missionControl/eventBrokerServices`;
|
|
45
|
+
// If broker name provided, retrieve the broker service id first
|
|
46
|
+
// then retrieve the operation status using the id
|
|
47
|
+
if (name) {
|
|
48
|
+
// API call to get broker by name
|
|
49
|
+
apiUrl += `?customAttributes=name=="${name}"`;
|
|
50
|
+
const resp = await conn.get(apiUrl);
|
|
51
|
+
// FUTURE: show status of multiple brokers operations that match the name
|
|
52
|
+
if (resp.data.length === 0) {
|
|
53
|
+
this.error(`No brokers found with name: ${name}.`);
|
|
54
|
+
}
|
|
55
|
+
else if (resp.data.length > 1) {
|
|
56
|
+
this.error(`Multiple broker services found with: ${name}. Exactly one broker service must match the provided name.`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
brokerId = resp.data[0]?.id;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// API call to retrieve status of the broker operation
|
|
63
|
+
apiUrl = `/missionControl/eventBrokerServices/${brokerId}/operations`;
|
|
64
|
+
const resp = await conn.get(apiUrl);
|
|
65
|
+
const opStatusArray = [
|
|
66
|
+
['Operation Id', 'Operation Type', 'Status', 'Created Time', 'Completed Time'],
|
|
67
|
+
...resp.data.map((item) => [
|
|
68
|
+
item.id,
|
|
69
|
+
item.operationType,
|
|
70
|
+
item.status,
|
|
71
|
+
item.createdTime,
|
|
72
|
+
item.completedTime,
|
|
73
|
+
]),
|
|
74
|
+
];
|
|
75
|
+
// Display results as a table
|
|
76
|
+
this.log(renderTable(opStatusArray));
|
|
77
|
+
// If show-progress flag is set, display progress bars for each operation
|
|
78
|
+
if (showProgress && resp.data.length > 0) {
|
|
79
|
+
// Create progress bar for each operation
|
|
80
|
+
const multiProgressBar = new MultiBar({
|
|
81
|
+
clearOnComplete: false,
|
|
82
|
+
format: ' {bar} | {operationType} | {value}/{total}',
|
|
83
|
+
hideCursor: true,
|
|
84
|
+
}, Presets.shades_classic);
|
|
85
|
+
// Get the initial progress for each operation
|
|
86
|
+
const progressBars = [];
|
|
87
|
+
let completedOperations = 0;
|
|
88
|
+
let allCompleted = false;
|
|
89
|
+
for (const operationData of resp.data) {
|
|
90
|
+
const opStatusApiUrl = `/missionControl/eventBrokerServices/${brokerId}/operations/${operationData.id}?expand=progressLogs`;
|
|
91
|
+
// eslint-disable-next-line no-await-in-loop
|
|
92
|
+
const opStatusResp = await conn.get(opStatusApiUrl);
|
|
93
|
+
this.debug(`Operation ID: ${operationData.id}, Type: ${operationData.operationType}, Status: ${operationData.status}`);
|
|
94
|
+
if (opStatusResp.data.progressLogs) {
|
|
95
|
+
const numSteps = opStatusResp.data.progressLogs.length;
|
|
96
|
+
// start a new progress bar for the operation with a total value of size of the steps
|
|
97
|
+
const progressBar = multiProgressBar.create(numSteps, 0, { operationType: operationData.operationType });
|
|
98
|
+
// Update the progress with the steps completed
|
|
99
|
+
const completedNumSteps = opStatusResp.data.progressLogs.filter((log) => log.status === 'success').length;
|
|
100
|
+
progressBar.update(completedNumSteps);
|
|
101
|
+
if (completedNumSteps === numSteps ||
|
|
102
|
+
opStatusResp.data.status === 'SUCCEEDED' ||
|
|
103
|
+
opStatusResp.data.status === 'FAILED') {
|
|
104
|
+
completedOperations += 1;
|
|
105
|
+
progressBar.stop();
|
|
106
|
+
}
|
|
107
|
+
// Add the operation ID and progress bar to the list
|
|
108
|
+
progressBars.push([operationData.id, progressBar]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Check if all operations are completed
|
|
112
|
+
if (completedOperations === progressBars.length) {
|
|
113
|
+
allCompleted = true;
|
|
114
|
+
}
|
|
115
|
+
// Loop until all operations are completed
|
|
116
|
+
while (!allCompleted) {
|
|
117
|
+
// Wait before making the next API call
|
|
118
|
+
sleep(waitMs);
|
|
119
|
+
// Poll the status of all operations and update the progress bars
|
|
120
|
+
// eslint-disable-next-line no-await-in-loop
|
|
121
|
+
allCompleted = await this.pollAllOperationStatus(conn, brokerId, progressBars);
|
|
122
|
+
}
|
|
123
|
+
multiProgressBar.stop();
|
|
124
|
+
this.log(); // Add a new line for better readability
|
|
125
|
+
}
|
|
126
|
+
return resp.data;
|
|
127
|
+
}
|
|
128
|
+
async pollAllOperationStatus(conn, brokerId, progressBars) {
|
|
129
|
+
let completedOperations = 0;
|
|
130
|
+
let allCompleted = false;
|
|
131
|
+
// For each operation, get the latest status and update the progress bar
|
|
132
|
+
for (const [operationId, progressBar] of progressBars) {
|
|
133
|
+
const opStatusApiUrl = `/missionControl/eventBrokerServices/${brokerId}/operations/${operationId}?expand=progressLogs`;
|
|
134
|
+
// eslint-disable-next-line no-await-in-loop
|
|
135
|
+
const opStatusResp = await conn.get(opStatusApiUrl);
|
|
136
|
+
if (opStatusResp.data.progressLogs) {
|
|
137
|
+
const numSteps = opStatusResp.data.progressLogs.length;
|
|
138
|
+
const completedNumSteps = opStatusResp.data.progressLogs.filter((log) => log.status === 'success').length;
|
|
139
|
+
// Update progress bar
|
|
140
|
+
progressBar.setTotal(numSteps);
|
|
141
|
+
progressBar.update(completedNumSteps);
|
|
142
|
+
if (completedNumSteps === numSteps ||
|
|
143
|
+
opStatusResp.data.status === 'SUCCEEDED' ||
|
|
144
|
+
opStatusResp.data.status === 'FAILED') {
|
|
145
|
+
completedOperations += 1;
|
|
146
|
+
progressBar.stop();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
progressBar.stop();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Check if all operations are completed
|
|
154
|
+
if (completedOperations === progressBars.length) {
|
|
155
|
+
allCompleted = true;
|
|
156
|
+
}
|
|
157
|
+
return allCompleted;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
2
|
+
import { EventBrokerOperationDetail } from '../../../types/broker.js';
|
|
3
|
+
export default class MissionctrlBrokerUpdate extends ScCommand<typeof MissionctrlBrokerUpdate> {
|
|
4
|
+
static args: {};
|
|
5
|
+
static description: string;
|
|
6
|
+
static examples: string[];
|
|
7
|
+
static flags: {
|
|
8
|
+
'broker-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
locked: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'new-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<EventBrokerOperationDetail>;
|
|
14
|
+
private print;
|
|
15
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
3
|
+
import { camelCaseToTitleCase, renderKeyValueTable } from '../../../util/internal.js';
|
|
4
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
5
|
+
export default class MissionctrlBrokerUpdate extends ScCommand {
|
|
6
|
+
static args = {};
|
|
7
|
+
static description = `Update the configuration of an existing event broker service.
|
|
8
|
+
You can provide any combination of supported flags. If a flag is not provided, then it will not be updated.
|
|
9
|
+
|
|
10
|
+
Your token must have one of the permissions listed in the Token Permissions.
|
|
11
|
+
|
|
12
|
+
Token Permissions: [ mission_control:access or services:put ]`;
|
|
13
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
14
|
+
static flags = {
|
|
15
|
+
'broker-id': Flags.string({
|
|
16
|
+
char: 'b',
|
|
17
|
+
description: 'Id of the event broker service.',
|
|
18
|
+
exactlyOne: ['broker-id', 'name'],
|
|
19
|
+
}),
|
|
20
|
+
locked: Flags.string({
|
|
21
|
+
char: 'l',
|
|
22
|
+
description: `Indicates whether the event broker service has deletion protection enabled. The valid values are 'true' (enabled) or 'false' (disabled).`,
|
|
23
|
+
}),
|
|
24
|
+
name: Flags.string({
|
|
25
|
+
char: 'n',
|
|
26
|
+
description: 'Name of the event broker service.',
|
|
27
|
+
exactlyOne: ['broker-id', 'name'],
|
|
28
|
+
}),
|
|
29
|
+
'new-name': Flags.string({
|
|
30
|
+
description: 'New name of the event broker service. The new service name must be unique within an organization.',
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
async run() {
|
|
34
|
+
const { flags } = await this.parse(MissionctrlBrokerUpdate);
|
|
35
|
+
const brokerId = flags['broker-id'] ?? '';
|
|
36
|
+
const locked = flags.locked ?? '';
|
|
37
|
+
const lockedBoolValue = locked === 'true';
|
|
38
|
+
const name = flags.name ?? '';
|
|
39
|
+
const newName = flags['new-name'] ?? '';
|
|
40
|
+
// API body
|
|
41
|
+
const body = {
|
|
42
|
+
...(locked && { locked: lockedBoolValue }),
|
|
43
|
+
...(newName && { name: newName }),
|
|
44
|
+
};
|
|
45
|
+
const conn = new ScConnection();
|
|
46
|
+
// API url
|
|
47
|
+
let apiUrl = `/missionControl/eventBrokerServices`;
|
|
48
|
+
let brokerIdToUpdate = brokerId;
|
|
49
|
+
if (name) {
|
|
50
|
+
// If broker name provided, get the broker matching provided name. If more than one broker matches, an error will be thrown.
|
|
51
|
+
const resp = await conn.get(`${apiUrl}?customAttributes=name=="${name}"`);
|
|
52
|
+
if (resp.data.length === 0) {
|
|
53
|
+
this.error(`No brokers found with name: ${name}.`);
|
|
54
|
+
}
|
|
55
|
+
else if (resp.data.length > 1) {
|
|
56
|
+
this.error(`Multiple brokers found with name: ${name}. Exactly one event broker service must match the provided name.`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
brokerIdToUpdate = resp.data[0]?.id;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// API call to update broker by id
|
|
63
|
+
apiUrl += `/${brokerIdToUpdate}`;
|
|
64
|
+
const resp = await conn.patch(apiUrl, body);
|
|
65
|
+
this.log(`Broker with id '${brokerIdToUpdate}' has been updated successfully.`);
|
|
66
|
+
this.print(resp.data);
|
|
67
|
+
return resp.data;
|
|
68
|
+
}
|
|
69
|
+
print(broker) {
|
|
70
|
+
const tableRows = [
|
|
71
|
+
['Key', 'Value'],
|
|
72
|
+
...Object.entries(broker).map(([key, value]) => [camelCaseToTitleCase(key), value]),
|
|
73
|
+
];
|
|
74
|
+
this.log();
|
|
75
|
+
this.log(renderKeyValueTable(tableRows));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
2
|
+
import { Environment } from '../../../types/environment.js';
|
|
3
|
+
export default class PlatformEnvCreate extends ScCommand<typeof PlatformEnvCreate> {
|
|
3
4
|
static args: {};
|
|
4
5
|
static description: string;
|
|
5
6
|
static examples: string[];
|
|
6
7
|
static flags: {
|
|
7
|
-
|
|
8
|
+
description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
9
|
isDefault: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
10
|
isProduction: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
11
|
name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
12
|
};
|
|
12
|
-
run(): Promise<
|
|
13
|
+
run(): Promise<Environment>;
|
|
13
14
|
private print;
|
|
14
15
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { camelCaseToTitleCase } from '../../../util/internal.js';
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
3
|
+
import { camelCaseToTitleCase, renderKeyValueTable } from '../../../util/internal.js';
|
|
4
4
|
import { ScConnection } from '../../../util/sc-connection.js';
|
|
5
|
-
export default class PlatformEnvCreate extends
|
|
5
|
+
export default class PlatformEnvCreate extends ScCommand {
|
|
6
6
|
static args = {};
|
|
7
7
|
static description = `Create a new environment.
|
|
8
8
|
|
|
9
9
|
Token Permissions: [ environments:edit ]`;
|
|
10
10
|
static examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvironment --desc="My environment description" --isDefault --isProduction'];
|
|
11
11
|
static flags = {
|
|
12
|
-
|
|
12
|
+
description: Flags.string({
|
|
13
13
|
char: 'd',
|
|
14
14
|
description: 'Description of the environment to create.'
|
|
15
15
|
}),
|
|
@@ -31,7 +31,7 @@ export default class PlatformEnvCreate extends Command {
|
|
|
31
31
|
async run() {
|
|
32
32
|
const { flags } = await this.parse(PlatformEnvCreate);
|
|
33
33
|
const name = flags.name ?? '';
|
|
34
|
-
const desc = flags.
|
|
34
|
+
const desc = flags.description ?? '';
|
|
35
35
|
const isDefault = flags.isDefault ?? false;
|
|
36
36
|
const isProduction = flags.isProduction ?? false;
|
|
37
37
|
const conn = new ScConnection();
|
|
@@ -39,7 +39,7 @@ export default class PlatformEnvCreate extends Command {
|
|
|
39
39
|
const apiUrl = `/platform/environments`;
|
|
40
40
|
// API body
|
|
41
41
|
const body = {
|
|
42
|
-
description: desc,
|
|
42
|
+
...(desc && { description: desc }),
|
|
43
43
|
isDefault,
|
|
44
44
|
isProduction,
|
|
45
45
|
name,
|
|
@@ -49,22 +49,15 @@ export default class PlatformEnvCreate extends Command {
|
|
|
49
49
|
// Display results
|
|
50
50
|
this.log('Environment created successfully.');
|
|
51
51
|
this.print(resp.data);
|
|
52
|
+
// Return raw json if --json flag is set
|
|
53
|
+
return resp.data;
|
|
52
54
|
}
|
|
53
55
|
print(environment) {
|
|
54
|
-
this.log();
|
|
55
56
|
const tableRows = [
|
|
56
57
|
['Key', 'Value'],
|
|
57
58
|
...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
|
|
58
59
|
];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
columns: {
|
|
62
|
-
1: { width: 50, wrapWord: true },
|
|
63
|
-
},
|
|
64
|
-
drawHorizontalLine(lineIndex, rowCount) {
|
|
65
|
-
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
this.log(table(tableRows, config));
|
|
60
|
+
this.log();
|
|
61
|
+
this.log(renderKeyValueTable(tableRows));
|
|
69
62
|
}
|
|
70
63
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default class PlatformEnvDelete extends
|
|
1
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
2
|
+
export default class PlatformEnvDelete extends ScCommand<typeof PlatformEnvDelete> {
|
|
3
3
|
static args: {};
|
|
4
4
|
static description: string;
|
|
5
5
|
static examples: string[];
|
|
@@ -7,5 +7,7 @@ export default class PlatformEnvDelete extends Command {
|
|
|
7
7
|
'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
8
|
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
9
|
};
|
|
10
|
-
run(): Promise<
|
|
10
|
+
run(): Promise<{
|
|
11
|
+
message: string;
|
|
12
|
+
}>;
|
|
11
13
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
2
3
|
import { ScConnection } from '../../../util/sc-connection.js';
|
|
3
|
-
export default class PlatformEnvDelete extends
|
|
4
|
+
export default class PlatformEnvDelete extends ScCommand {
|
|
4
5
|
static args = {};
|
|
5
6
|
static description = `Delete an environment using either its name or unique identifier. The default environment cannot be deleted.
|
|
6
7
|
|
|
@@ -28,20 +29,31 @@ export default class PlatformEnvDelete extends Command {
|
|
|
28
29
|
let envIdToDelete = envId;
|
|
29
30
|
// If env name provided, get the environment matching provided name and delete. If more than one environment matches, an error will be thrown.
|
|
30
31
|
// If env id provided, delete environment with that id
|
|
32
|
+
let foundMultiple = false;
|
|
31
33
|
if (name) {
|
|
32
34
|
// API call to get environment by name
|
|
33
35
|
const getEnvApiUrl = `${apiUrl}?name=${name}`;
|
|
34
36
|
const resp = await conn.get(getEnvApiUrl);
|
|
35
37
|
if (resp.data.length > 1) {
|
|
36
|
-
|
|
38
|
+
foundMultiple = true;
|
|
37
39
|
}
|
|
38
40
|
else {
|
|
39
41
|
envIdToDelete = resp.data[0]?.id;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
let message = '';
|
|
45
|
+
if (foundMultiple) {
|
|
46
|
+
message = `Multiple environments found with: ${name}. Exactly one environment must match the provided name.`;
|
|
47
|
+
this.warn(message);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// API call to delete environment by id
|
|
51
|
+
apiUrl += `/${envIdToDelete}`;
|
|
52
|
+
await conn.delete(apiUrl);
|
|
53
|
+
message = `Environment with id '${envIdToDelete}' has been deleted successfully.`;
|
|
54
|
+
this.log(message);
|
|
55
|
+
}
|
|
56
|
+
// Return raw json if --json flag is set
|
|
57
|
+
return { message };
|
|
46
58
|
}
|
|
47
59
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
2
|
+
import { Environment } from '../../../types/environment.js';
|
|
3
|
+
export default class PlatformEnvDisplay extends ScCommand<typeof PlatformEnvDisplay> {
|
|
3
4
|
static args: {};
|
|
4
5
|
static description: string;
|
|
5
6
|
static examples: string[];
|
|
@@ -7,6 +8,6 @@ export default class PlatformEnvDisplay extends Command {
|
|
|
7
8
|
'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
9
|
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
10
|
};
|
|
10
|
-
run(): Promise<
|
|
11
|
+
run(): Promise<Environment[]>;
|
|
11
12
|
private print;
|
|
12
13
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { camelCaseToTitleCase } from '../../../util/internal.js';
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
3
|
+
import { camelCaseToTitleCase, renderKeyValueTable } from '../../../util/internal.js';
|
|
4
4
|
import { ScConnection } from '../../../util/sc-connection.js';
|
|
5
|
-
export default class PlatformEnvDisplay extends
|
|
5
|
+
export default class PlatformEnvDisplay extends ScCommand {
|
|
6
6
|
static args = {};
|
|
7
7
|
static description = `Display information about an Environment.
|
|
8
8
|
|
|
9
9
|
Use either the Environment's ID (--env-id) or name of the Environment (--name).
|
|
10
10
|
|
|
11
|
-
Required token permissions: [ environments:view ]
|
|
12
|
-
`;
|
|
11
|
+
Required token permissions: [ environments:view ]`;
|
|
13
12
|
static examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvName', '<%= config.bin %> <%= command.id %> --env-id=MyEnvId'];
|
|
14
13
|
static flags = {
|
|
15
14
|
'env-id': Flags.string({
|
|
@@ -32,11 +31,13 @@ export default class PlatformEnvDisplay extends Command {
|
|
|
32
31
|
// If env name provided, get all environments matching provided name
|
|
33
32
|
// If env id provided, get environment with that id
|
|
34
33
|
let apiUrl = `/platform/environments`;
|
|
34
|
+
let rawResp;
|
|
35
35
|
if (envId) {
|
|
36
36
|
// API call to get environment by id
|
|
37
37
|
apiUrl += `/${envId}`;
|
|
38
38
|
const resp = await conn.get(apiUrl);
|
|
39
39
|
this.print(resp.data);
|
|
40
|
+
rawResp = [resp.data];
|
|
40
41
|
}
|
|
41
42
|
else if (name) {
|
|
42
43
|
// API call to get environment by name
|
|
@@ -45,26 +46,20 @@ export default class PlatformEnvDisplay extends Command {
|
|
|
45
46
|
for (const env of resp.data) {
|
|
46
47
|
this.print(env);
|
|
47
48
|
}
|
|
49
|
+
rawResp = resp.data;
|
|
48
50
|
}
|
|
49
51
|
else {
|
|
50
52
|
this.error('Either --env-id or --name must be provided.');
|
|
51
53
|
}
|
|
54
|
+
// Return raw json if --json flag is set
|
|
55
|
+
return rawResp;
|
|
52
56
|
}
|
|
53
57
|
print(environment) {
|
|
54
|
-
this.log();
|
|
55
58
|
const tableRows = [
|
|
56
59
|
['Key', 'Value'],
|
|
57
60
|
...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
|
|
58
61
|
];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
columns: {
|
|
62
|
-
1: { width: 50, wrapWord: true },
|
|
63
|
-
},
|
|
64
|
-
drawHorizontalLine(lineIndex, rowCount) {
|
|
65
|
-
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
this.log(table(tableRows, config));
|
|
62
|
+
this.log();
|
|
63
|
+
this.log(renderKeyValueTable(tableRows));
|
|
69
64
|
}
|
|
70
65
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
2
|
+
import { Environment } from '../../../types/environment.js';
|
|
3
|
+
export default class PlatformEnvList extends ScCommand<typeof PlatformEnvList> {
|
|
3
4
|
static args: {};
|
|
4
5
|
static description: string;
|
|
5
6
|
static examples: string[];
|
|
@@ -9,5 +10,5 @@ export default class PlatformEnvList extends Command {
|
|
|
9
10
|
pageSize: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
11
|
sort: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
12
|
};
|
|
12
|
-
run(): Promise<
|
|
13
|
+
run(): Promise<Environment[]>;
|
|
13
14
|
}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
3
|
+
import { renderTable } from '../../../util/internal.js';
|
|
3
4
|
import { ScConnection } from '../../../util/sc-connection.js';
|
|
4
|
-
export default class PlatformEnvList extends
|
|
5
|
+
export default class PlatformEnvList extends ScCommand {
|
|
5
6
|
static args = {};
|
|
6
7
|
static description = `Get a list of all Environments.
|
|
7
8
|
|
|
8
9
|
Required token permissions: [ environments:view ]`;
|
|
9
10
|
static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --name=Default --pageNumber=1 --pageSize=10 --sort=name:ASC'];
|
|
10
11
|
static flags = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
name: Flags.string({
|
|
13
|
+
char: 'n',
|
|
14
|
+
description: 'Name of the environment to match on.'
|
|
15
|
+
}),
|
|
16
|
+
pageNumber: Flags.integer({
|
|
17
|
+
char: 'p',
|
|
18
|
+
description: 'The page number to get. Defaults to 10'
|
|
19
|
+
}),
|
|
16
20
|
pageSize: Flags.integer({
|
|
21
|
+
char: 's',
|
|
17
22
|
description: 'The number of environments to get per page. Defaults to 1',
|
|
18
23
|
max: 100,
|
|
19
24
|
min: 1,
|
|
20
25
|
}),
|
|
21
|
-
// sort (--sort=VALUE)
|
|
22
26
|
sort: Flags.string({
|
|
23
27
|
description: 'The query (fieldName:<ASC/DESC>) used to sort the environment list in the response.',
|
|
24
28
|
}),
|
|
@@ -36,20 +40,20 @@ export default class PlatformEnvList extends Command {
|
|
|
36
40
|
// API call
|
|
37
41
|
const resp = await conn.get(apiUrl);
|
|
38
42
|
// Array to output as table
|
|
39
|
-
const envArray = [
|
|
43
|
+
const envArray = [
|
|
44
|
+
['Name', 'Id', 'Is Default', 'Is Production', 'Description'],
|
|
45
|
+
...resp.data.map((item) => [
|
|
40
46
|
item.name,
|
|
41
47
|
item.id,
|
|
42
48
|
item.isDefault,
|
|
43
49
|
item.isProduction,
|
|
44
50
|
item.description,
|
|
45
|
-
])
|
|
51
|
+
])
|
|
52
|
+
];
|
|
46
53
|
// Display results as a table
|
|
47
|
-
const config = {
|
|
48
|
-
columns: {
|
|
49
|
-
4: { width: 50, wrapWord: true },
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
54
|
this.log();
|
|
53
|
-
this.log(
|
|
55
|
+
this.log(renderTable(envArray, { 4: { width: 50, wrapWord: true } }));
|
|
56
|
+
// Return raw json if --json flag is set
|
|
57
|
+
return resp.data;
|
|
54
58
|
}
|
|
55
59
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
2
|
+
import { Environment } from '../../../types/environment.js';
|
|
3
|
+
export default class PlatformEnvUpdate extends ScCommand<typeof PlatformEnvUpdate> {
|
|
3
4
|
static args: {};
|
|
4
5
|
static description: string;
|
|
5
6
|
static examples: string[];
|
|
6
7
|
static flags: {
|
|
7
|
-
|
|
8
|
+
description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
9
|
'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
10
|
isDefault: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
11
|
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
12
|
'new-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
13
|
};
|
|
13
|
-
run(): Promise<
|
|
14
|
+
run(): Promise<Environment>;
|
|
14
15
|
private print;
|
|
15
16
|
}
|