@dishantlangayan/solace-cloud-cli 0.0.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.
- package/LICENSE.txt +202 -0
- package/README.md +638 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +5 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/commands/missionctrl/broker/create.d.ts +18 -0
- package/dist/commands/missionctrl/broker/create.js +107 -0
- package/dist/commands/missionctrl/broker/delete.d.ts +11 -0
- package/dist/commands/missionctrl/broker/delete.js +54 -0
- package/dist/commands/missionctrl/broker/display.d.ts +12 -0
- package/dist/commands/missionctrl/broker/display.js +69 -0
- package/dist/commands/missionctrl/broker/list.d.ts +13 -0
- package/dist/commands/missionctrl/broker/list.js +65 -0
- package/dist/commands/platform/env/create.d.ts +14 -0
- package/dist/commands/platform/env/create.js +63 -0
- package/dist/commands/platform/env/delete.d.ts +11 -0
- package/dist/commands/platform/env/delete.js +41 -0
- package/dist/commands/platform/env/display.d.ts +12 -0
- package/dist/commands/platform/env/display.js +64 -0
- package/dist/commands/platform/env/list.d.ts +13 -0
- package/dist/commands/platform/env/list.js +56 -0
- package/dist/commands/platform/env/update.d.ts +15 -0
- package/dist/commands/platform/env/update.js +76 -0
- package/dist/config/env-vars.d.ts +44 -0
- package/dist/config/env-vars.js +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/sc-command.d.ts +22 -0
- package/dist/sc-command.js +54 -0
- package/dist/types/broker.d.ts +60 -0
- package/dist/types/broker.js +1 -0
- package/dist/types/environment.d.ts +36 -0
- package/dist/types/environment.js +1 -0
- package/dist/util/internal.d.ts +6 -0
- package/dist/util/internal.js +12 -0
- package/dist/util/json.d.ts +15 -0
- package/dist/util/json.js +19 -0
- package/dist/util/sc-connection.d.ts +12 -0
- package/dist/util/sc-connection.js +47 -0
- package/oclif.manifest.json +521 -0
- package/package.json +77 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { table } from 'table';
|
|
3
|
+
import { camelCaseToTitleCase } from '../../../util/internal.js';
|
|
4
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
5
|
+
export default class MissionctrlBrokerCreate extends Command {
|
|
6
|
+
static args = {};
|
|
7
|
+
static description = `Create an event broker service. You must provide a unique name and select a service class and datacenter. You can optionally define other properties for the event broker service.
|
|
8
|
+
|
|
9
|
+
Your token must have one of the permissions listed in the Token Permissions.
|
|
10
|
+
|
|
11
|
+
Token Permissions: [ \`services:post\` ]`;
|
|
12
|
+
static examples = ['<%= config.bin %> <%= command.id %> --datacenter-id=MyDatacenterId --name=MyBrokerName --service-class-id=DEVELOPER'];
|
|
13
|
+
static flags = {
|
|
14
|
+
'datacenter-id': Flags.string({
|
|
15
|
+
char: 'd',
|
|
16
|
+
description: 'The identifier of the datacenter.',
|
|
17
|
+
required: true,
|
|
18
|
+
}),
|
|
19
|
+
'env-name': Flags.string({
|
|
20
|
+
char: 'e',
|
|
21
|
+
description: 'The name of the environment environment where you want to create the service. If no name is provided, the service will be created in the default environment.',
|
|
22
|
+
}),
|
|
23
|
+
locked: Flags.boolean({
|
|
24
|
+
char: 'l',
|
|
25
|
+
default: false,
|
|
26
|
+
description: 'Indicates if you can delete the event broker service after creating it. The default value is false.',
|
|
27
|
+
}),
|
|
28
|
+
'max-spool-usage': Flags.string({
|
|
29
|
+
char: 's',
|
|
30
|
+
description: 'The message spool size, in gigabytes (GB). A default message spool size is provided if this is not specified.',
|
|
31
|
+
}),
|
|
32
|
+
'msg-vpn-name': Flags.string({
|
|
33
|
+
char: 'm',
|
|
34
|
+
description: 'The message VPN name. A default message VPN name is provided when this is not specified.',
|
|
35
|
+
}),
|
|
36
|
+
name: Flags.string({ char: 'n', description: 'Name of the event broker service to create.', required: true }),
|
|
37
|
+
'service-class-id': Flags.string({
|
|
38
|
+
char: 'c',
|
|
39
|
+
description: 'Supported service classes.',
|
|
40
|
+
required: true,
|
|
41
|
+
}),
|
|
42
|
+
version: Flags.string({
|
|
43
|
+
char: 'v',
|
|
44
|
+
description: 'The event broker version. A default version is provided when this is not specified.',
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
async run() {
|
|
48
|
+
const { flags } = await this.parse(MissionctrlBrokerCreate);
|
|
49
|
+
const datacenterId = flags['datacenter-id'] ?? '';
|
|
50
|
+
let envName = flags['env-name'] ?? '';
|
|
51
|
+
const locked = flags.locked ?? false;
|
|
52
|
+
// const maxSpoolUsage = flags['max-spool-usage'] ?? ''
|
|
53
|
+
// const msgVpnName = flags['msg-vpn-name'] ?? ''
|
|
54
|
+
const name = flags.name ?? '';
|
|
55
|
+
const redundancyGroupSslEnabled = false; // This flag is not defined yet, but it is used in the API body
|
|
56
|
+
const serviceClassId = flags['service-class-id'] ?? 'DEVELOPER';
|
|
57
|
+
// const version = flags.version ?? ''
|
|
58
|
+
const conn = new ScConnection();
|
|
59
|
+
// API url
|
|
60
|
+
const apiUrl = `/missionControl/eventBrokerServices`;
|
|
61
|
+
// If envName is provided, retrieve the environment ID
|
|
62
|
+
if (envName) {
|
|
63
|
+
const envApiUrl = `/platform/environments?name=${envName}`;
|
|
64
|
+
const envResp = await conn.get(envApiUrl);
|
|
65
|
+
if (envResp.data.length > 1) {
|
|
66
|
+
this.error(`Multiple environments found with: ${name}. Exactly one environment must match the provided name.`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
envName = envResp.data[0]?.id;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// API body
|
|
73
|
+
const body = {
|
|
74
|
+
datacenterId,
|
|
75
|
+
envName,
|
|
76
|
+
// eventBrokerVersion: version,
|
|
77
|
+
locked,
|
|
78
|
+
// maxSpoolUsage,
|
|
79
|
+
// msgVpnName,
|
|
80
|
+
name,
|
|
81
|
+
redundancyGroupSslEnabled,
|
|
82
|
+
serviceClassId,
|
|
83
|
+
};
|
|
84
|
+
// API call
|
|
85
|
+
const resp = await conn.post(apiUrl, body);
|
|
86
|
+
// Display results
|
|
87
|
+
this.log('Event broker service created successfully.');
|
|
88
|
+
this.print(resp.data);
|
|
89
|
+
}
|
|
90
|
+
print(broker) {
|
|
91
|
+
this.log();
|
|
92
|
+
const tableRows = [
|
|
93
|
+
['Key', 'Value'],
|
|
94
|
+
...Object.entries(broker).map(([key, value]) => [camelCaseToTitleCase(key), value]),
|
|
95
|
+
];
|
|
96
|
+
// Table config
|
|
97
|
+
const config = {
|
|
98
|
+
columns: {
|
|
99
|
+
1: { width: 50, wrapWord: true },
|
|
100
|
+
},
|
|
101
|
+
drawHorizontalLine(lineIndex, rowCount) {
|
|
102
|
+
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
this.log(table(tableRows, config));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class MissionctrlBrokerDelete extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
'broker-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
3
|
+
export default class MissionctrlBrokerDelete extends Command {
|
|
4
|
+
static args = {};
|
|
5
|
+
static description = `Delete a service using its unique identifier.
|
|
6
|
+
|
|
7
|
+
Your token must have one of the permissions listed in the Token Permissions.
|
|
8
|
+
|
|
9
|
+
Token Permissions: [ \`services:delete\` **or** \`services:delete:self\` **or** \`mission_control:access\` ]`;
|
|
10
|
+
static examples = [
|
|
11
|
+
'<%= config.bin %> <%= command.id %> --broker-id=MyBrokerId',
|
|
12
|
+
'<%= config.bin %> <%= command.id %> --name=MyBrokerName',
|
|
13
|
+
];
|
|
14
|
+
static flags = {
|
|
15
|
+
// flag for getting environment by id (-e, --env-id)
|
|
16
|
+
'broker-id': Flags.string({
|
|
17
|
+
char: 'b',
|
|
18
|
+
description: 'Id of the event broker service.',
|
|
19
|
+
exactlyOne: ['broker-id', 'name'],
|
|
20
|
+
}),
|
|
21
|
+
// flag for getting environment by name (-n, --name=VALUE)
|
|
22
|
+
name: Flags.string({
|
|
23
|
+
char: 'n',
|
|
24
|
+
description: 'Name of the event broker service.',
|
|
25
|
+
exactlyOne: ['broker-id', 'name'],
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
async run() {
|
|
29
|
+
const { flags } = await this.parse(MissionctrlBrokerDelete);
|
|
30
|
+
const name = flags.name ?? '';
|
|
31
|
+
const brokerId = flags['broker-id'] ?? '';
|
|
32
|
+
const conn = new ScConnection();
|
|
33
|
+
// API url
|
|
34
|
+
let apiUrl = `/missionControl/eventBrokerServices`;
|
|
35
|
+
let brokerIdToDelete = brokerId;
|
|
36
|
+
// If broker name was provided, get the broker matching provided name and delete. If more than one broker matches, an error will be thrown.
|
|
37
|
+
// If broker id was provided, delete broker with that id
|
|
38
|
+
if (name) {
|
|
39
|
+
// API call to get broker by name
|
|
40
|
+
const getBrokersApiUrl = `${apiUrl}?customAttributes=name=="${name}"`;
|
|
41
|
+
const resp = await conn.get(getBrokersApiUrl);
|
|
42
|
+
if (resp.data.length > 1) {
|
|
43
|
+
this.error(`Multiple event broker services found with: ${name}. Exactly one broker must match the provided name.`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
brokerIdToDelete = resp.data[0]?.id;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// API call to delete environment by id
|
|
50
|
+
apiUrl += `/${brokerIdToDelete}`;
|
|
51
|
+
await conn.delete(apiUrl);
|
|
52
|
+
this.log(`Event broker service with id '${brokerIdToDelete}' has been deleted successfully.`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class MissionctrlBrokerDisplay extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
'broker-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
private print;
|
|
12
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { table } from 'table';
|
|
3
|
+
import { camelCaseToTitleCase } from '../../../util/internal.js';
|
|
4
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
5
|
+
export default class MissionctrlBrokerDisplay extends Command {
|
|
6
|
+
static args = {};
|
|
7
|
+
static description = `Get the details of an event broker service using its identifier or name.
|
|
8
|
+
|
|
9
|
+
Use either the Event Broker's ID (--broker-id) or name of the Event Broker (--name).
|
|
10
|
+
|
|
11
|
+
Token Permissions: [ \`mission_control:access\` **or** \`services:get\` **or** \`services:get:self\` **or** \`services:view\` **or** \`services:view:self\` ]`;
|
|
12
|
+
static examples = ['<%= config.bin %> <%= command.id %>'];
|
|
13
|
+
static flags = {
|
|
14
|
+
'broker-id': Flags.string({
|
|
15
|
+
char: 'b',
|
|
16
|
+
description: 'Id of the event broker service.',
|
|
17
|
+
exactlyOne: ['broker-id', 'name'],
|
|
18
|
+
}),
|
|
19
|
+
name: Flags.string({
|
|
20
|
+
char: 'n',
|
|
21
|
+
description: 'Name of the event broker service.',
|
|
22
|
+
exactlyOne: ['broker-id', 'name'],
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
async run() {
|
|
26
|
+
const { flags } = await this.parse(MissionctrlBrokerDisplay);
|
|
27
|
+
const name = flags.name ?? '';
|
|
28
|
+
const brokerId = flags['broker-id'] ?? '';
|
|
29
|
+
const conn = new ScConnection();
|
|
30
|
+
// API url
|
|
31
|
+
let apiUrl = `/missionControl/eventBrokerServices`;
|
|
32
|
+
// If broker name provided, get all brokers matching provided name
|
|
33
|
+
// If broker id provided, get broker with that id
|
|
34
|
+
if (brokerId) {
|
|
35
|
+
// API call to get broker by id
|
|
36
|
+
apiUrl += `/${brokerId}`;
|
|
37
|
+
const resp = await conn.get(apiUrl);
|
|
38
|
+
this.print(resp);
|
|
39
|
+
}
|
|
40
|
+
else if (name) {
|
|
41
|
+
// API call to get broker by name
|
|
42
|
+
apiUrl += `?customAttributes=name=="${name}"`;
|
|
43
|
+
const resp = await conn.get(apiUrl);
|
|
44
|
+
for (const broker of resp.data) {
|
|
45
|
+
this.print(broker);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.error('Either --broker-id or --name must be provided.');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
print(broker) {
|
|
53
|
+
this.log();
|
|
54
|
+
const tableRows = [
|
|
55
|
+
['Key', 'Value'],
|
|
56
|
+
...Object.entries(broker).map(([key, value]) => [camelCaseToTitleCase(key), value]),
|
|
57
|
+
];
|
|
58
|
+
// Table config
|
|
59
|
+
const config = {
|
|
60
|
+
columns: {
|
|
61
|
+
1: { width: 50, wrapWord: true },
|
|
62
|
+
},
|
|
63
|
+
drawHorizontalLine(lineIndex, rowCount) {
|
|
64
|
+
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
this.log(table(tableRows, config));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class MissionctrlBrokerList extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
pageNumber: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
pageSize: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
sort: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { table } from 'table';
|
|
3
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
4
|
+
export default class MissionctrlBrokerList extends Command {
|
|
5
|
+
static args = {};
|
|
6
|
+
static description = `Get a listing of event broker services.
|
|
7
|
+
|
|
8
|
+
Your token must have one of the permissions listed in the Token Permissions.
|
|
9
|
+
|
|
10
|
+
Token Permissions: [ \`mission_control:access\` **or** \`services:get\` **or** \`services:get:self\` **or** \`services:view\` **or** \`services:view:self\` ]`;
|
|
11
|
+
static examples = ['<%= config.bin %> <%= command.id %> --name=MyBrokerName --pageNumber=1 --pageSize=10 --sort=name:asc'];
|
|
12
|
+
static flags = {
|
|
13
|
+
// flag with a value (-n, --name=VALUE)
|
|
14
|
+
name: Flags.string({ char: 'n', description: 'Name of the event broker service to match on.' }),
|
|
15
|
+
// pageNumber (--pageNumber=VALUE)
|
|
16
|
+
pageNumber: Flags.integer({ description: 'The page number to get. Defaults to 1' }),
|
|
17
|
+
// pageSize (--pageSize=VALUE)
|
|
18
|
+
pageSize: Flags.integer({
|
|
19
|
+
description: 'The number of event broker services to return per page. Defaults to 100',
|
|
20
|
+
max: 100,
|
|
21
|
+
min: 1,
|
|
22
|
+
}),
|
|
23
|
+
// sort (--sort=VALUE)
|
|
24
|
+
sort: Flags.string({
|
|
25
|
+
description: `Sort the returned event broker services by attribute.
|
|
26
|
+
|
|
27
|
+
You can use the following value formats for the sort order:
|
|
28
|
+
|
|
29
|
+
* attributes-names
|
|
30
|
+
* attributes-names:sort-order`,
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
async run() {
|
|
34
|
+
const { flags } = await this.parse(MissionctrlBrokerList);
|
|
35
|
+
const conn = new ScConnection();
|
|
36
|
+
const pageSize = flags.pageSize ?? 10;
|
|
37
|
+
const pageNumber = flags.pageNumber ?? 1;
|
|
38
|
+
// API url
|
|
39
|
+
let apiUrl = `/missionControl/eventBrokerServices?pageSize=${pageSize}&pageNumber=${pageNumber}`;
|
|
40
|
+
if (flags.sort) {
|
|
41
|
+
apiUrl += `&sort=${flags.sort}`;
|
|
42
|
+
}
|
|
43
|
+
if (flags.name) {
|
|
44
|
+
apiUrl += `&customAttributes=name=="${flags.name}"`;
|
|
45
|
+
}
|
|
46
|
+
// API call
|
|
47
|
+
const resp = await conn.get(apiUrl);
|
|
48
|
+
// Array to output as table
|
|
49
|
+
const brokerArray = [
|
|
50
|
+
['Name', 'Id', 'Type', 'Version', 'Owned By', 'Datacenter Id', 'Service Class Id'],
|
|
51
|
+
...resp.data.map((item) => [
|
|
52
|
+
item.name,
|
|
53
|
+
item.id,
|
|
54
|
+
item.type,
|
|
55
|
+
item.eventBrokerServiceVersion,
|
|
56
|
+
item.ownedBy,
|
|
57
|
+
item.datacenterId,
|
|
58
|
+
item.serviceClassId,
|
|
59
|
+
]),
|
|
60
|
+
];
|
|
61
|
+
// Display results as a table
|
|
62
|
+
this.log();
|
|
63
|
+
this.log(table(brokerArray));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class PlatformEnvCreate extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
desc: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
isDefault: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
isProduction: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
private print;
|
|
14
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { table } from 'table';
|
|
3
|
+
import { camelCaseToTitleCase } from '../../../util/internal.js';
|
|
4
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
5
|
+
export default class PlatformEnvCreate extends Command {
|
|
6
|
+
static args = {};
|
|
7
|
+
static description = `Create a new environment.
|
|
8
|
+
|
|
9
|
+
Token Permissions: [ environments:edit ]`;
|
|
10
|
+
static examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvironment --desc="My environment description" --isDefault --isProduction'];
|
|
11
|
+
static flags = {
|
|
12
|
+
desc: Flags.string({ char: 'd', description: 'Description of the environment to create.' }),
|
|
13
|
+
// flag with no value (--isDefault)
|
|
14
|
+
isDefault: Flags.boolean({ description: 'Indicates this is the organization’s default environment.' }),
|
|
15
|
+
isProduction: Flags.boolean({
|
|
16
|
+
description: `Indicates this is an organization’s production environment.
|
|
17
|
+
This is an immutable field. If an environment needs to be migrated,
|
|
18
|
+
architecture can be migrated to a new environment with the desired
|
|
19
|
+
environment type instead.`,
|
|
20
|
+
}),
|
|
21
|
+
// flag with a value (-n, --name=VALUE)
|
|
22
|
+
name: Flags.string({ char: 'n', description: 'Name of the environment to create.', required: true }),
|
|
23
|
+
};
|
|
24
|
+
async run() {
|
|
25
|
+
const { flags } = await this.parse(PlatformEnvCreate);
|
|
26
|
+
const name = flags.name ?? '';
|
|
27
|
+
const desc = flags.desc ?? '';
|
|
28
|
+
const isDefault = flags.isDefault ?? false;
|
|
29
|
+
const isProduction = flags.isProduction ?? false;
|
|
30
|
+
const conn = new ScConnection();
|
|
31
|
+
// API url
|
|
32
|
+
const apiUrl = `/platform/environments`;
|
|
33
|
+
// API body
|
|
34
|
+
const body = {
|
|
35
|
+
description: desc,
|
|
36
|
+
isDefault,
|
|
37
|
+
isProduction,
|
|
38
|
+
name,
|
|
39
|
+
};
|
|
40
|
+
// API call
|
|
41
|
+
const resp = await conn.post(apiUrl, body);
|
|
42
|
+
// Display results
|
|
43
|
+
this.log('Environment created successfully.');
|
|
44
|
+
this.print(resp.data);
|
|
45
|
+
}
|
|
46
|
+
print(environment) {
|
|
47
|
+
this.log();
|
|
48
|
+
const tableRows = [
|
|
49
|
+
['Key', 'Value'],
|
|
50
|
+
...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
|
|
51
|
+
];
|
|
52
|
+
// Table config
|
|
53
|
+
const config = {
|
|
54
|
+
columns: {
|
|
55
|
+
1: { width: 50, wrapWord: true },
|
|
56
|
+
},
|
|
57
|
+
drawHorizontalLine(lineIndex, rowCount) {
|
|
58
|
+
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
this.log(table(tableRows, config));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class PlatformEnvDelete extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
3
|
+
export default class PlatformEnvDelete extends Command {
|
|
4
|
+
static args = {};
|
|
5
|
+
static description = `Delete an environment using either its name or unique identifier. The default environment cannot be deleted.
|
|
6
|
+
|
|
7
|
+
Token Permissions: [ environments:edit ]`;
|
|
8
|
+
static examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvName', '<%= config.bin %> <%= command.id %> --env-id=MyEnvId'];
|
|
9
|
+
static flags = {
|
|
10
|
+
// flag for getting environment by id (-e, --env-id)
|
|
11
|
+
'env-id': Flags.string({ char: 'e', description: 'Id of the environment.', exactlyOne: ['env-id', 'name'] }),
|
|
12
|
+
// flag for getting environment by name (-n, --name=VALUE)
|
|
13
|
+
name: Flags.string({ char: 'n', description: 'Name of the environment.', exactlyOne: ['env-id', 'name'] }),
|
|
14
|
+
};
|
|
15
|
+
async run() {
|
|
16
|
+
const { flags } = await this.parse(PlatformEnvDelete);
|
|
17
|
+
const name = flags.name ?? '';
|
|
18
|
+
const envId = flags['env-id'] ?? '';
|
|
19
|
+
const conn = new ScConnection();
|
|
20
|
+
// API url
|
|
21
|
+
let apiUrl = `/platform/environments`;
|
|
22
|
+
let envIdToDelete = envId;
|
|
23
|
+
// If env name provided, get the environment matching provided name and delete. If more than one environment matches, an error will be thrown.
|
|
24
|
+
// If env id provided, delete environment with that id
|
|
25
|
+
if (name) {
|
|
26
|
+
// API call to get environment by name
|
|
27
|
+
const getEnvApiUrl = `${apiUrl}?name=${name}`;
|
|
28
|
+
const resp = await conn.get(getEnvApiUrl);
|
|
29
|
+
if (resp.data.length > 1) {
|
|
30
|
+
this.error(`Multiple environments found with: ${name}. Exactly one environment must match the provided name.`);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
envIdToDelete = resp.data[0]?.id;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// API call to delete environment by id
|
|
37
|
+
apiUrl += `/${envIdToDelete}`;
|
|
38
|
+
await conn.delete(apiUrl);
|
|
39
|
+
this.log(`Environment with id '${envIdToDelete}' has been deleted successfully.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class PlatformEnvDisplay extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
private print;
|
|
12
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
|
+
import { table } from 'table';
|
|
3
|
+
import { camelCaseToTitleCase } from '../../../util/internal.js';
|
|
4
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
5
|
+
export default class PlatformEnvDisplay extends Command {
|
|
6
|
+
static args = {};
|
|
7
|
+
static description = `Display information about an Environment.
|
|
8
|
+
|
|
9
|
+
Use either the Environment's ID (--env-id) or name of the Environment (--name).
|
|
10
|
+
|
|
11
|
+
Required token permissions: [ environments:view ]
|
|
12
|
+
`;
|
|
13
|
+
static examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvName', '<%= config.bin %> <%= command.id %> --env-id=MyEnvId'];
|
|
14
|
+
static flags = {
|
|
15
|
+
// flag for getting environment by id (-e, --env-id)
|
|
16
|
+
'env-id': Flags.string({ char: 'e', description: 'Id of the environment.', exactlyOne: ['env-id', 'name'] }),
|
|
17
|
+
// flag for getting environment by name (-n, --name=VALUE)
|
|
18
|
+
name: Flags.string({ char: 'n', description: 'Name of the environment.', exactlyOne: ['env-id', 'name'] }),
|
|
19
|
+
};
|
|
20
|
+
async run() {
|
|
21
|
+
const { flags } = await this.parse(PlatformEnvDisplay);
|
|
22
|
+
const name = flags.name ?? '';
|
|
23
|
+
const envId = flags['env-id'] ?? '';
|
|
24
|
+
const conn = new ScConnection();
|
|
25
|
+
// API url
|
|
26
|
+
// If env name provided, get all environments matching provided name
|
|
27
|
+
// If env id provided, get environment with that id
|
|
28
|
+
let apiUrl = `/platform/environments`;
|
|
29
|
+
if (envId) {
|
|
30
|
+
// API call to get environment by id
|
|
31
|
+
apiUrl += `/${envId}`;
|
|
32
|
+
const resp = await conn.get(apiUrl);
|
|
33
|
+
this.print(resp.data);
|
|
34
|
+
}
|
|
35
|
+
else if (name) {
|
|
36
|
+
// API call to get environment by name
|
|
37
|
+
apiUrl += `?name=${name}`;
|
|
38
|
+
const resp = await conn.get(apiUrl);
|
|
39
|
+
for (const env of resp.data) {
|
|
40
|
+
this.print(env);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.error('Either --env-id or --name must be provided.');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
print(environment) {
|
|
48
|
+
this.log();
|
|
49
|
+
const tableRows = [
|
|
50
|
+
['Key', 'Value'],
|
|
51
|
+
...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
|
|
52
|
+
];
|
|
53
|
+
// Table config
|
|
54
|
+
const config = {
|
|
55
|
+
columns: {
|
|
56
|
+
1: { width: 50, wrapWord: true },
|
|
57
|
+
},
|
|
58
|
+
drawHorizontalLine(lineIndex, rowCount) {
|
|
59
|
+
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
this.log(table(tableRows, config));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
2
|
+
export default class PlatformEnvList extends ScCommand<typeof PlatformEnvList> {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
pageNumber: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
pageSize: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
sort: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
};
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import { table } from 'table';
|
|
3
|
+
import { ScCommand } from '../../../sc-command.js';
|
|
4
|
+
import { ScConnection } from '../../../util/sc-connection.js';
|
|
5
|
+
export default class PlatformEnvList extends ScCommand {
|
|
6
|
+
static args = {};
|
|
7
|
+
static description = `Get a list of all Environments.
|
|
8
|
+
|
|
9
|
+
Required token permissions: [ environments:view ]`;
|
|
10
|
+
static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --name=Default --pageNumber=1 --pageSize=10 --sort=name:ASC'];
|
|
11
|
+
static flags = {
|
|
12
|
+
// flag with a value (-n, --name=VALUE)
|
|
13
|
+
name: Flags.string({ char: 'n', description: 'Name of the environment to match on.' }),
|
|
14
|
+
// pageNumber (--pageNumber=VALUE)
|
|
15
|
+
pageNumber: Flags.integer({ description: 'The page number to get. Defaults to 10' }),
|
|
16
|
+
// pageSize (--pageSize=VALUE)
|
|
17
|
+
pageSize: Flags.integer({
|
|
18
|
+
description: 'The number of environments to get per page. Defaults to 1',
|
|
19
|
+
max: 100,
|
|
20
|
+
min: 1,
|
|
21
|
+
}),
|
|
22
|
+
// sort (--sort=VALUE)
|
|
23
|
+
sort: Flags.string({
|
|
24
|
+
description: 'The query (fieldName:<ASC/DESC>) used to sort the environment list in the response.',
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
async run() {
|
|
28
|
+
const { flags } = await this.parse(PlatformEnvList);
|
|
29
|
+
const conn = new ScConnection();
|
|
30
|
+
const pageSize = flags.pageSize ?? 10;
|
|
31
|
+
const pageNumber = flags.pageNumber ?? 1;
|
|
32
|
+
// API url
|
|
33
|
+
let apiUrl = `/platform/environments?pageSize=${pageSize}&pageNumber=${pageNumber}`;
|
|
34
|
+
if (flags.sort) {
|
|
35
|
+
apiUrl += `&sort=${flags.sort}`;
|
|
36
|
+
}
|
|
37
|
+
// API call
|
|
38
|
+
const resp = await conn.get(apiUrl);
|
|
39
|
+
// Array to output as table
|
|
40
|
+
const envArray = [['Name', 'Id', 'Is Default', 'Is Production', 'Description'], ...resp.data.map((item) => [
|
|
41
|
+
item.name,
|
|
42
|
+
item.id,
|
|
43
|
+
item.isDefault,
|
|
44
|
+
item.isProduction,
|
|
45
|
+
item.description,
|
|
46
|
+
])];
|
|
47
|
+
// Display results as a table
|
|
48
|
+
const config = {
|
|
49
|
+
columns: {
|
|
50
|
+
4: { width: 50, wrapWord: true },
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
this.log();
|
|
54
|
+
this.log(table(envArray, config));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command } from '@oclif/core';
|
|
2
|
+
export default class PlatformEnvUpdate extends Command {
|
|
3
|
+
static args: {};
|
|
4
|
+
static description: string;
|
|
5
|
+
static examples: string[];
|
|
6
|
+
static flags: {
|
|
7
|
+
desc: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
isDefault: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
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<void>;
|
|
14
|
+
private print;
|
|
15
|
+
}
|