bdy 1.16.12 → 1.16.15-dev
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/distTs/package.json +4 -3
- package/distTs/src/api/client.js +176 -5
- package/distTs/src/command/login.js +130 -0
- package/distTs/src/command/logout.js +15 -0
- package/distTs/src/command/project/get.js +18 -0
- package/distTs/src/command/project/list.js +33 -0
- package/distTs/src/command/project/set.js +45 -0
- package/distTs/src/command/project.js +16 -0
- package/distTs/src/command/sandbox/cp.js +71 -0
- package/distTs/src/command/sandbox/create.js +147 -0
- package/distTs/src/command/sandbox/destroy.js +34 -0
- package/distTs/src/command/sandbox/endpoint/add.js +40 -0
- package/distTs/src/command/sandbox/endpoint/delete.js +41 -0
- package/distTs/src/command/sandbox/endpoint/get.js +101 -0
- package/distTs/src/command/sandbox/endpoint/list.js +48 -0
- package/distTs/src/command/sandbox/endpoint.js +18 -0
- package/distTs/src/command/sandbox/exec/command.js +72 -0
- package/distTs/src/command/sandbox/exec/kill.js +34 -0
- package/distTs/src/command/sandbox/exec/list.js +53 -0
- package/distTs/src/command/sandbox/exec/logs.js +59 -0
- package/distTs/src/command/sandbox/exec/status.js +43 -0
- package/distTs/src/command/sandbox/exec.js +19 -0
- package/distTs/src/command/sandbox/get.js +50 -0
- package/distTs/src/command/sandbox/list.js +41 -0
- package/distTs/src/command/sandbox/restart.js +48 -0
- package/distTs/src/command/sandbox/snapshot/create.js +56 -0
- package/distTs/src/command/sandbox/snapshot/delete.js +40 -0
- package/distTs/src/command/sandbox/snapshot/get.js +50 -0
- package/distTs/src/command/sandbox/snapshot/list.js +46 -0
- package/distTs/src/command/sandbox/snapshot.js +18 -0
- package/distTs/src/command/sandbox/start.js +48 -0
- package/distTs/src/command/sandbox/status.js +38 -0
- package/distTs/src/command/sandbox/stop.js +48 -0
- package/distTs/src/command/sandbox.js +34 -0
- package/distTs/src/command/whoami.js +31 -0
- package/distTs/src/command/workspace/get.js +18 -0
- package/distTs/src/command/workspace/list.js +32 -0
- package/distTs/src/command/workspace/set.js +40 -0
- package/distTs/src/command/workspace.js +16 -0
- package/distTs/src/index.js +12 -0
- package/distTs/src/input.js +142 -14
- package/distTs/src/output.js +44 -0
- package/distTs/src/texts.js +186 -8
- package/distTs/src/tunnel/cfg.js +47 -0
- package/distTs/src/utils.js +91 -3
- package/package.json +4 -3
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../api/client"));
|
|
11
|
+
const human_id_1 = __importDefault(require("human-id"));
|
|
12
|
+
const VALID_RESOURCES = [
|
|
13
|
+
'1x2',
|
|
14
|
+
'2x4',
|
|
15
|
+
'3x6',
|
|
16
|
+
'4x8',
|
|
17
|
+
'5x10',
|
|
18
|
+
'6x12',
|
|
19
|
+
'7x14',
|
|
20
|
+
'8x16',
|
|
21
|
+
'9x18',
|
|
22
|
+
'10x20',
|
|
23
|
+
'11x22',
|
|
24
|
+
'12x24',
|
|
25
|
+
];
|
|
26
|
+
const commandSandboxCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMAND_SANDBOX_CREATE);
|
|
27
|
+
commandSandboxCreate.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
28
|
+
commandSandboxCreate.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
29
|
+
commandSandboxCreate.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
30
|
+
commandSandboxCreate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
31
|
+
commandSandboxCreate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
32
|
+
commandSandboxCreate.option('-n, --name <name>', texts_1.OPTION_SANDBOX_NAME);
|
|
33
|
+
commandSandboxCreate.option('-i, --identifier <identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
34
|
+
commandSandboxCreate.option('--os <image>', texts_1.OPTION_SANDBOX_OS);
|
|
35
|
+
commandSandboxCreate.option('--snapshot <snapshot-name>', texts_1.OPTION_SANDBOX_FROM_SNAPSHOT);
|
|
36
|
+
commandSandboxCreate.option('--resources <spec>', texts_1.OPTION_SANDBOX_RESOURCES);
|
|
37
|
+
commandSandboxCreate.option('--install-command <commands...>', texts_1.OPTION_SANDBOX_INSTALL_COMMANDS);
|
|
38
|
+
commandSandboxCreate.option('--run-command <command>', texts_1.OPTION_SANDBOX_RUN_COMMAND);
|
|
39
|
+
commandSandboxCreate.option('--app-dir <directory>', texts_1.OPTION_SANDBOX_APP_DIR);
|
|
40
|
+
commandSandboxCreate.option('--app-type <type>', texts_1.OPTION_SANDBOX_APP_TYPE);
|
|
41
|
+
commandSandboxCreate.option('--tag <tags...>', texts_1.OPTION_SANDBOX_TAGS);
|
|
42
|
+
commandSandboxCreate.option('--wait-for-running', texts_1.OPTION_SANDBOX_WAIT_RUNNING);
|
|
43
|
+
commandSandboxCreate.option('--wait-for-running-timeout <seconds>', texts_1.OPTION_SANDBOX_WAIT_TIMEOUT, '300');
|
|
44
|
+
commandSandboxCreate.option('--wait-for-configured', texts_1.OPTION_SANDBOX_WAIT_CONFIGURED);
|
|
45
|
+
commandSandboxCreate.option('--wait-for-configured-timeout <seconds>', texts_1.OPTION_SANDBOX_WAIT_TIMEOUT, '300');
|
|
46
|
+
commandSandboxCreate.option('--wait-for-app', texts_1.OPTION_SANDBOX_WAIT_APP);
|
|
47
|
+
commandSandboxCreate.option('--wait-for-app-timeout <seconds>', texts_1.OPTION_SANDBOX_WAIT_TIMEOUT, '300');
|
|
48
|
+
commandSandboxCreate.action(async (options) => {
|
|
49
|
+
const token = input_1.default.restApiToken(options.token);
|
|
50
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
51
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
52
|
+
const project = input_1.default.restApiProject(options.project);
|
|
53
|
+
const client = new client_1.default(baseUrl, token);
|
|
54
|
+
if (options.resources && !VALID_RESOURCES.includes(options.resources)) {
|
|
55
|
+
output_1.default.exitError((0, texts_1.ERR_SANDBOX_INVALID_RESOURCES)(options.resources));
|
|
56
|
+
}
|
|
57
|
+
const timestamp = Date.now().toString(36);
|
|
58
|
+
const baseName = (0, human_id_1.default)({ separator: '-', capitalize: false });
|
|
59
|
+
const defaultIdentifier = `${baseName}-${timestamp}`;
|
|
60
|
+
const body = {
|
|
61
|
+
name: options.name || baseName,
|
|
62
|
+
identifier: options.identifier || defaultIdentifier,
|
|
63
|
+
};
|
|
64
|
+
if (options.snapshot) {
|
|
65
|
+
const sandboxesResult = await client.listSandboxes(workspace, project);
|
|
66
|
+
const sandboxes = sandboxesResult.sandboxes || [];
|
|
67
|
+
let foundSnapshotId = null;
|
|
68
|
+
for (const sandbox of sandboxes) {
|
|
69
|
+
const snapshotsResult = await client.listSandboxSnapshots(workspace, sandbox.id);
|
|
70
|
+
const snapshots = snapshotsResult.snapshots || [];
|
|
71
|
+
const foundSnapshot = snapshots.find((s) => s.name === options.snapshot);
|
|
72
|
+
if (foundSnapshot) {
|
|
73
|
+
foundSnapshotId = foundSnapshot.id;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!foundSnapshotId) {
|
|
78
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_SNAPSHOT_NOT_FOUND);
|
|
79
|
+
}
|
|
80
|
+
body.snapshot_id = foundSnapshotId;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
body.os = options.os || 'ubuntu:24.04';
|
|
84
|
+
}
|
|
85
|
+
if (options.resources) {
|
|
86
|
+
body.resources = options.resources;
|
|
87
|
+
}
|
|
88
|
+
if (options.installCommand) {
|
|
89
|
+
body.install_commands = options.installCommand.join('\n');
|
|
90
|
+
}
|
|
91
|
+
if (options.tags) {
|
|
92
|
+
body.tags = options.tags;
|
|
93
|
+
}
|
|
94
|
+
if (options.runCommand) {
|
|
95
|
+
body.run_command = options.runCommand;
|
|
96
|
+
}
|
|
97
|
+
if (options.appDir) {
|
|
98
|
+
body.app_dir = options.appDir;
|
|
99
|
+
}
|
|
100
|
+
if (options.appType) {
|
|
101
|
+
body.app_type = options.app_type;
|
|
102
|
+
}
|
|
103
|
+
output_1.default.normal((0, texts_1.TXT_SANDBOX_CREATING)(body.name, body.identifier));
|
|
104
|
+
const result = await client.createSandbox(workspace, project, body);
|
|
105
|
+
const sandboxId = result.id;
|
|
106
|
+
if (options.waitForRunning) {
|
|
107
|
+
output_1.default.normal(texts_1.TXT_SANDBOX_WAITING_RUNNING);
|
|
108
|
+
const timeout = parseInt(options.waitForRunningTimeout, 10) || 300;
|
|
109
|
+
try {
|
|
110
|
+
const status = await client.sandboxWaitForRunning(workspace, sandboxId, timeout);
|
|
111
|
+
if (status !== utils_1.SANDBOX_STATUS.RUNNING) {
|
|
112
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_RUNNING_FAILED);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_RUNNING_TIMEOUT);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (options.waitForConfigured) {
|
|
120
|
+
output_1.default.normal(texts_1.TXT_SANDBOX_WAITING_SETUP);
|
|
121
|
+
const timeout = parseInt(options.waitForConfiguredTimeout, 10) || 300;
|
|
122
|
+
try {
|
|
123
|
+
const status = await client.sandboxWaitForConfigured(workspace, sandboxId, timeout);
|
|
124
|
+
if (status !== utils_1.SANDBOX_SETUP_STATUS.SUCCESS) {
|
|
125
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_SETUP_FAILED);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_SETUP_TIMEOUT);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (options.waitForApp) {
|
|
133
|
+
output_1.default.normal(texts_1.TXT_SANDBOX_WAITING_APP);
|
|
134
|
+
const timeout = parseInt(options.waitForAppTimeout, 10) || 300;
|
|
135
|
+
try {
|
|
136
|
+
const status = await client.sandboxWaitForApp(workspace, sandboxId, timeout);
|
|
137
|
+
if (status !== utils_1.SANDBOX_APP_STATUS.RUNNING) {
|
|
138
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_APP_FAILED);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_APP_TIMEOUT);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_CREATED)(result.identifier, result.html_url));
|
|
146
|
+
});
|
|
147
|
+
exports.default = commandSandboxCreate;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../api/client"));
|
|
11
|
+
const commandSandboxDestroy = (0, utils_1.newCommand)('destroy', texts_1.DESC_COMMAND_SANDBOX_DESTROY);
|
|
12
|
+
commandSandboxDestroy.alias('rm');
|
|
13
|
+
commandSandboxDestroy.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
14
|
+
commandSandboxDestroy.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
15
|
+
commandSandboxDestroy.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
16
|
+
commandSandboxDestroy.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
17
|
+
commandSandboxDestroy.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
18
|
+
commandSandboxDestroy.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
19
|
+
commandSandboxDestroy.action(async (identifier, options) => {
|
|
20
|
+
const token = input_1.default.restApiToken(options.token);
|
|
21
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const project = input_1.default.restApiProject(options.project);
|
|
24
|
+
const client = new client_1.default(baseUrl, token);
|
|
25
|
+
const result = await client.listSandboxes(workspace, project);
|
|
26
|
+
const sandboxes = result.sandboxes || [];
|
|
27
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
28
|
+
if (!found) {
|
|
29
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
30
|
+
}
|
|
31
|
+
await client.deleteSandbox(workspace, found.id);
|
|
32
|
+
output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_DESTROYED)(identifier));
|
|
33
|
+
});
|
|
34
|
+
exports.default = commandSandboxDestroy;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const logger_1 = __importDefault(require("../../../logger"));
|
|
12
|
+
const commandSandboxEndpointAdd = (0, utils_1.getBasicCommandSandboxEndpoint)('add', texts_1.DESC_COMMAND_SANDBOX_ENDPOINT_ADD);
|
|
13
|
+
commandSandboxEndpointAdd.action(async (identifier, options) => {
|
|
14
|
+
const token = input_1.default.restApiToken(options.token);
|
|
15
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
16
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
17
|
+
const project = input_1.default.restApiProject(options.project);
|
|
18
|
+
const client = new client_1.default(baseUrl, token);
|
|
19
|
+
const result = await client.listSandboxes(workspace, project);
|
|
20
|
+
const sandboxes = result.sandboxes || [];
|
|
21
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
22
|
+
if (!found) {
|
|
23
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
24
|
+
}
|
|
25
|
+
const sandbox = await client.getSandbox(workspace, found.id);
|
|
26
|
+
const endpoints = sandbox.endpoints || [];
|
|
27
|
+
const existing = endpoints.find((ep) => ep.name === options.name);
|
|
28
|
+
if (existing) {
|
|
29
|
+
output_1.default.exitError((0, texts_1.ERR_SANDBOX_ENDPOINT_EXISTS)(options.name));
|
|
30
|
+
}
|
|
31
|
+
const endpoint = input_1.default.prepareSandboxEndpoint(options);
|
|
32
|
+
logger_1.default.info(endpoint);
|
|
33
|
+
const updatedEndpoints = [...endpoints, endpoint];
|
|
34
|
+
const updatedSandbox = await client.updateSandbox(workspace, found.id, {
|
|
35
|
+
endpoints: updatedEndpoints,
|
|
36
|
+
});
|
|
37
|
+
const addedEndpoint = (updatedSandbox.endpoints || []).find((ep) => ep.name === options.name);
|
|
38
|
+
output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_ENDPOINT_ADDED)(options.name, addedEndpoint.endpoint_url));
|
|
39
|
+
});
|
|
40
|
+
exports.default = commandSandboxEndpointAdd;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const commandSandboxEndpointDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_SANDBOX_ENDPOINT_DELETE);
|
|
12
|
+
commandSandboxEndpointDelete.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
13
|
+
commandSandboxEndpointDelete.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
14
|
+
commandSandboxEndpointDelete.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
15
|
+
commandSandboxEndpointDelete.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
16
|
+
commandSandboxEndpointDelete.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
17
|
+
commandSandboxEndpointDelete.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
18
|
+
commandSandboxEndpointDelete.argument('<endpoint-name>', texts_1.OPTION_SANDBOX_ENDPOINT_NAME_ARG);
|
|
19
|
+
commandSandboxEndpointDelete.action(async (identifier, endpointName, options) => {
|
|
20
|
+
const token = input_1.default.restApiToken(options.token);
|
|
21
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const project = input_1.default.restApiProject(options.project);
|
|
24
|
+
const client = new client_1.default(baseUrl, token);
|
|
25
|
+
const result = await client.listSandboxes(workspace, project);
|
|
26
|
+
const sandboxes = result.sandboxes || [];
|
|
27
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
28
|
+
if (!found) {
|
|
29
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
30
|
+
}
|
|
31
|
+
const sandbox = await client.getSandbox(workspace, found.id);
|
|
32
|
+
const endpoints = sandbox.endpoints || [];
|
|
33
|
+
const endpointIndex = endpoints.findIndex((ep) => ep.name === endpointName);
|
|
34
|
+
if (endpointIndex === -1) {
|
|
35
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_ENDPOINT_NOT_FOUND);
|
|
36
|
+
}
|
|
37
|
+
const updatedEndpoints = endpoints.filter((ep) => ep.name !== endpointName);
|
|
38
|
+
await client.updateSandbox(workspace, found.id, { endpoints: updatedEndpoints });
|
|
39
|
+
output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_ENDPOINT_DELETED)(endpointName));
|
|
40
|
+
});
|
|
41
|
+
exports.default = commandSandboxEndpointDelete;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const commandSandboxEndpointGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_SANDBOX_ENDPOINT_GET);
|
|
12
|
+
commandSandboxEndpointGet.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
13
|
+
commandSandboxEndpointGet.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
14
|
+
commandSandboxEndpointGet.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
15
|
+
commandSandboxEndpointGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
16
|
+
commandSandboxEndpointGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
17
|
+
commandSandboxEndpointGet.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
18
|
+
commandSandboxEndpointGet.argument('<endpoint-name>', texts_1.OPTION_SANDBOX_ENDPOINT_NAME_ARG);
|
|
19
|
+
commandSandboxEndpointGet.action(async (identifier, endpointName, options) => {
|
|
20
|
+
const token = input_1.default.restApiToken(options.token);
|
|
21
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const project = input_1.default.restApiProject(options.project);
|
|
24
|
+
const client = new client_1.default(baseUrl, token);
|
|
25
|
+
const result = await client.listSandboxes(workspace, project);
|
|
26
|
+
const sandboxes = result.sandboxes || [];
|
|
27
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
28
|
+
if (!found) {
|
|
29
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
30
|
+
}
|
|
31
|
+
const sandbox = await client.getSandbox(workspace, found.id);
|
|
32
|
+
const endpoints = sandbox.endpoints || [];
|
|
33
|
+
const endpoint = endpoints.find((ep) => ep.name === endpointName);
|
|
34
|
+
if (!endpoint) {
|
|
35
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_ENDPOINT_NOT_FOUND);
|
|
36
|
+
}
|
|
37
|
+
const data = [
|
|
38
|
+
['Property', 'Value'],
|
|
39
|
+
['Name', endpoint.name || '-'],
|
|
40
|
+
['Endpoint', endpoint.endpoint || '-'],
|
|
41
|
+
['Type', endpoint.type || '-'],
|
|
42
|
+
['Region', endpoint.region || '-'],
|
|
43
|
+
['URL', endpoint.endpoint_url || '-'],
|
|
44
|
+
['Timeout', endpoint.timeout?.toString() || '-'],
|
|
45
|
+
];
|
|
46
|
+
if (endpoint.whitelist?.length) {
|
|
47
|
+
data.push(['Whitelist', endpoint.whitelist?.join(', ')]);
|
|
48
|
+
}
|
|
49
|
+
if (endpoint.http) {
|
|
50
|
+
data.push(['HTTP2', endpoint.http.http2 ? 'TRUE' : 'FALSE']);
|
|
51
|
+
data.push([
|
|
52
|
+
'Verify certificate',
|
|
53
|
+
endpoint.http.verify_certificate ? 'TRUE' : 'FALSE',
|
|
54
|
+
]);
|
|
55
|
+
data.push(['Compression', endpoint.http.compression ? 'TRUE' : 'FALSE']);
|
|
56
|
+
data.push([
|
|
57
|
+
'Log requests',
|
|
58
|
+
endpoint.http.log_requests ? 'TRUE' : 'FALSE',
|
|
59
|
+
]);
|
|
60
|
+
data.push(['Auth type', endpoint.http.auth_type]);
|
|
61
|
+
if (endpoint.http.serve_path) {
|
|
62
|
+
data.push(['Serve path', endpoint.http.serve_path]);
|
|
63
|
+
}
|
|
64
|
+
if (endpoint.http.circuit_breaker) {
|
|
65
|
+
data.push(['Circuit breaker', String(endpoint.http.circuit_breaker)]);
|
|
66
|
+
}
|
|
67
|
+
if (endpoint.http.whitelist_user_agents?.length) {
|
|
68
|
+
data.push([
|
|
69
|
+
'Whitelist user agents',
|
|
70
|
+
endpoint.http.whitelist_user_agents.join('\n'),
|
|
71
|
+
]);
|
|
72
|
+
}
|
|
73
|
+
if (endpoint.http.rewrite_host_header) {
|
|
74
|
+
data.push(['Rewrite host header', endpoint.http.rewrite_host_header]);
|
|
75
|
+
}
|
|
76
|
+
let headers = Object.keys(endpoint.http.request_headers || {});
|
|
77
|
+
if (headers.length) {
|
|
78
|
+
data.push([
|
|
79
|
+
'Request headers',
|
|
80
|
+
headers
|
|
81
|
+
.map((key) => `${key}: ${endpoint.http.request_headers[key]}`)
|
|
82
|
+
.join('\n '),
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
headers = Object.keys(endpoint.http.response_headers || {});
|
|
86
|
+
if (headers.length) {
|
|
87
|
+
data.push([
|
|
88
|
+
'Request headers',
|
|
89
|
+
headers
|
|
90
|
+
.map((key) => `${key}: ${endpoint.http.response_headers[key]}`)
|
|
91
|
+
.join('\n '),
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (endpoint.tls) {
|
|
96
|
+
data.push(['Terminate at', endpoint.tls.terminate_at]);
|
|
97
|
+
}
|
|
98
|
+
output_1.default.table(data);
|
|
99
|
+
output_1.default.exitNormal();
|
|
100
|
+
});
|
|
101
|
+
exports.default = commandSandboxEndpointGet;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const commandSandboxEndpointList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_SANDBOX_ENDPOINT_LIST);
|
|
12
|
+
commandSandboxEndpointList.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
13
|
+
commandSandboxEndpointList.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
14
|
+
commandSandboxEndpointList.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
15
|
+
commandSandboxEndpointList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
16
|
+
commandSandboxEndpointList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
17
|
+
commandSandboxEndpointList.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
18
|
+
commandSandboxEndpointList.action(async (identifier, options) => {
|
|
19
|
+
const token = input_1.default.restApiToken(options.token);
|
|
20
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
21
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
22
|
+
const project = input_1.default.restApiProject(options.project);
|
|
23
|
+
const client = new client_1.default(baseUrl, token);
|
|
24
|
+
const result = await client.listSandboxes(workspace, project);
|
|
25
|
+
const sandboxes = result.sandboxes || [];
|
|
26
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
27
|
+
if (!found) {
|
|
28
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
29
|
+
}
|
|
30
|
+
const sandbox = await client.getSandbox(workspace, found.id);
|
|
31
|
+
const endpoints = sandbox.endpoints || [];
|
|
32
|
+
if (endpoints.length === 0) {
|
|
33
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_ENDPOINTS_NOT_FOUND);
|
|
34
|
+
}
|
|
35
|
+
const data = [['Name', 'Endpoint', 'Type', 'Region', 'URL']];
|
|
36
|
+
for (const ep of endpoints) {
|
|
37
|
+
data.push([
|
|
38
|
+
ep.name || '-',
|
|
39
|
+
ep.endpoint || '-',
|
|
40
|
+
ep.type || '-',
|
|
41
|
+
ep.region || '-',
|
|
42
|
+
ep.endpoint_url || '-',
|
|
43
|
+
]);
|
|
44
|
+
}
|
|
45
|
+
output_1.default.table(data);
|
|
46
|
+
output_1.default.exitNormal();
|
|
47
|
+
});
|
|
48
|
+
exports.default = commandSandboxEndpointList;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const texts_1 = require("../../texts");
|
|
8
|
+
const list_1 = __importDefault(require("./endpoint/list"));
|
|
9
|
+
const get_1 = __importDefault(require("./endpoint/get"));
|
|
10
|
+
const add_1 = __importDefault(require("./endpoint/add"));
|
|
11
|
+
const delete_1 = __importDefault(require("./endpoint/delete"));
|
|
12
|
+
const commandSandboxEndpoint = (0, utils_1.newCommand)('endpoint', texts_1.DESC_COMMAND_SANDBOX_ENDPOINT);
|
|
13
|
+
commandSandboxEndpoint.alias('ep');
|
|
14
|
+
commandSandboxEndpoint.addCommand(list_1.default);
|
|
15
|
+
commandSandboxEndpoint.addCommand(get_1.default);
|
|
16
|
+
commandSandboxEndpoint.addCommand(add_1.default);
|
|
17
|
+
commandSandboxEndpoint.addCommand(delete_1.default);
|
|
18
|
+
exports.default = commandSandboxEndpoint;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const texts_1 = require("../../../texts");
|
|
7
|
+
const utils_1 = require("../../../utils");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const commandSandboxExecCommand = (0, utils_1.newCommand)('command', texts_1.DESC_COMMAND_SANDBOX_EXEC);
|
|
12
|
+
commandSandboxExecCommand.alias('cmd');
|
|
13
|
+
commandSandboxExecCommand.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
14
|
+
commandSandboxExecCommand.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
15
|
+
commandSandboxExecCommand.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
16
|
+
commandSandboxExecCommand.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
17
|
+
commandSandboxExecCommand.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
18
|
+
commandSandboxExecCommand.option('--runtime <runtime>', texts_1.OPTION_SANDBOX_RUNTIME);
|
|
19
|
+
commandSandboxExecCommand.option('--wait', texts_1.OPTION_SANDBOX_WAIT);
|
|
20
|
+
commandSandboxExecCommand.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
21
|
+
commandSandboxExecCommand.argument('<command>');
|
|
22
|
+
commandSandboxExecCommand.action(async (identifier, command, options) => {
|
|
23
|
+
output_1.default.handleSignals();
|
|
24
|
+
const token = input_1.default.restApiToken(options.token);
|
|
25
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
26
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
27
|
+
const project = input_1.default.restApiProject(options.project);
|
|
28
|
+
const client = new client_1.default(baseUrl, token);
|
|
29
|
+
const runtime = input_1.default.restApiSandboxExecRuntime(options.runtime);
|
|
30
|
+
const result = await client.listSandboxes(workspace, project);
|
|
31
|
+
const sandboxes = result.sandboxes || [];
|
|
32
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
33
|
+
if (!found) {
|
|
34
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
35
|
+
}
|
|
36
|
+
const cmdResult = await client.executeSandboxCommand(workspace, found.id, {
|
|
37
|
+
command,
|
|
38
|
+
runtime,
|
|
39
|
+
});
|
|
40
|
+
output_1.default.gray((0, texts_1.TXT_SANDBOX_EXEC_ID)(cmdResult.id));
|
|
41
|
+
if (!options.wait) {
|
|
42
|
+
output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_EXEC_BACKGROUND)(cmdResult.id));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const body = await client.streamSandboxCommandLogs(workspace, found.id, cmdResult.id);
|
|
46
|
+
body.on('data', (data) => {
|
|
47
|
+
if (data) {
|
|
48
|
+
try {
|
|
49
|
+
const json = JSON.parse(data);
|
|
50
|
+
if (json.data)
|
|
51
|
+
output_1.default.normal(json.data);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// do nothing
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
body.on('close', async () => {
|
|
59
|
+
const cmdExit = await client.getSandboxCommand(workspace, found.id, cmdResult.id);
|
|
60
|
+
if (cmdExit.status === utils_1.SANDBOX_EXEC_STATUS.SUCCESSFUL) {
|
|
61
|
+
output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_EXEC_SUCCESS)(cmdResult.id));
|
|
62
|
+
}
|
|
63
|
+
else if (cmdExit.status === utils_1.SANDBOX_EXEC_STATUS.INPROGRESS) {
|
|
64
|
+
output_1.default.exitNormal((0, texts_1.TXT_SANDBOX_EXEC_INPROGRESS)(cmdResult.id));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
output_1.default.exitError((0, texts_1.TXT_SANDBOX_EXEC_FAILED)(cmdResult.id));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
exports.default = commandSandboxExecCommand;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
9
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
10
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
11
|
+
const commandSandboxExecKill = (0, utils_1.newCommand)('kill', texts_1.DESC_COMMAND_SANDBOX_EXEC_KILL);
|
|
12
|
+
commandSandboxExecKill.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
13
|
+
commandSandboxExecKill.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
14
|
+
commandSandboxExecKill.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
15
|
+
commandSandboxExecKill.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
16
|
+
commandSandboxExecKill.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
17
|
+
commandSandboxExecKill.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
18
|
+
commandSandboxExecKill.argument('<command-id>', texts_1.OPTION_SANDBOX_COMMAND_ID);
|
|
19
|
+
commandSandboxExecKill.action(async (identifier, commandId, options) => {
|
|
20
|
+
const token = input_1.default.restApiToken(options.token);
|
|
21
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const project = input_1.default.restApiProject(options.project);
|
|
24
|
+
const client = new client_1.default(baseUrl, token);
|
|
25
|
+
const result = await client.listSandboxes(workspace, project);
|
|
26
|
+
const sandboxes = result.sandboxes || [];
|
|
27
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
28
|
+
if (!found) {
|
|
29
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
30
|
+
}
|
|
31
|
+
await client.terminateSandboxCommand(workspace, found.id, commandId);
|
|
32
|
+
output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_COMMAND_KILLED)(commandId));
|
|
33
|
+
});
|
|
34
|
+
exports.default = commandSandboxExecKill;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
9
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
10
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
11
|
+
const commandSandboxExecList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_SANDBOX_EXEC_LIST);
|
|
12
|
+
commandSandboxExecList.alias('ls');
|
|
13
|
+
commandSandboxExecList.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
14
|
+
commandSandboxExecList.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
15
|
+
commandSandboxExecList.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
16
|
+
commandSandboxExecList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
17
|
+
commandSandboxExecList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
18
|
+
commandSandboxExecList.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
19
|
+
commandSandboxExecList.action(async (identifier, options) => {
|
|
20
|
+
const token = input_1.default.restApiToken(options.token);
|
|
21
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
22
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
23
|
+
const project = input_1.default.restApiProject(options.project);
|
|
24
|
+
const client = new client_1.default(baseUrl, token);
|
|
25
|
+
const result = await client.listSandboxes(workspace, project);
|
|
26
|
+
const sandboxes = result.sandboxes || [];
|
|
27
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
28
|
+
if (!found) {
|
|
29
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
30
|
+
}
|
|
31
|
+
const commandsResult = await client.listSandboxCommands(workspace, found.id);
|
|
32
|
+
const commands = commandsResult.commands || [];
|
|
33
|
+
if (commands.length === 0) {
|
|
34
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NO_COMMANDS);
|
|
35
|
+
}
|
|
36
|
+
commands.sort((a, b) => (b.id || '').localeCompare(a.id || ''));
|
|
37
|
+
const data = [
|
|
38
|
+
['ID', 'COMMAND', 'STATUS', 'EXIT CODE', 'RUNTIME'],
|
|
39
|
+
];
|
|
40
|
+
for (const cmd of commands) {
|
|
41
|
+
data.push([
|
|
42
|
+
cmd.id || '-',
|
|
43
|
+
(cmd.command || '-').substring(0, 40) +
|
|
44
|
+
(cmd.command?.length > 40 ? '...' : ''),
|
|
45
|
+
cmd.status || '-',
|
|
46
|
+
cmd.exit_code !== undefined ? String(cmd.exit_code) : '-',
|
|
47
|
+
cmd.runtime || 'BASH',
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
output_1.default.table(data);
|
|
51
|
+
output_1.default.exitNormal();
|
|
52
|
+
});
|
|
53
|
+
exports.default = commandSandboxExecList;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const texts_1 = require("../../../texts");
|
|
8
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const input_1 = __importDefault(require("../../../input"));
|
|
10
|
+
const client_1 = __importDefault(require("../../../api/client"));
|
|
11
|
+
const commandSandboxExecLogs = (0, utils_1.newCommand)('logs', texts_1.DESC_COMMAND_SANDBOX_EXEC_LOGS);
|
|
12
|
+
commandSandboxExecLogs.option('--token <token>', texts_1.OPTION_REST_API_TOKEN);
|
|
13
|
+
commandSandboxExecLogs.option('--api <url>', texts_1.OPTION_REST_API_ENDPOINT);
|
|
14
|
+
commandSandboxExecLogs.option('--region <region>', texts_1.OPTION_REST_API_REGION);
|
|
15
|
+
commandSandboxExecLogs.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
|
|
16
|
+
commandSandboxExecLogs.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
|
|
17
|
+
commandSandboxExecLogs.option('--wait', texts_1.OPTION_SANDBOX_WAIT);
|
|
18
|
+
commandSandboxExecLogs.argument('<identifier>', texts_1.OPTION_SANDBOX_IDENTIFIER);
|
|
19
|
+
commandSandboxExecLogs.argument('<command-id>', texts_1.OPTION_SANDBOX_COMMAND_ID);
|
|
20
|
+
commandSandboxExecLogs.action(async (identifier, commandId, options) => {
|
|
21
|
+
output_1.default.handleSignals();
|
|
22
|
+
const token = input_1.default.restApiToken(options.token);
|
|
23
|
+
const baseUrl = input_1.default.restApiBaseUrl(options.api, options.region);
|
|
24
|
+
const workspace = input_1.default.restApiWorkspace(options.workspace);
|
|
25
|
+
const project = input_1.default.restApiProject(options.project);
|
|
26
|
+
const client = new client_1.default(baseUrl, token);
|
|
27
|
+
const result = await client.listSandboxes(workspace, project);
|
|
28
|
+
const sandboxes = result.sandboxes || [];
|
|
29
|
+
const found = sandboxes.find((s) => s.identifier === identifier);
|
|
30
|
+
if (!found) {
|
|
31
|
+
output_1.default.exitError(texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
32
|
+
}
|
|
33
|
+
const body = await client.streamSandboxCommandLogs(workspace, found.id, commandId, !!options.wait);
|
|
34
|
+
body.on('data', (data) => {
|
|
35
|
+
if (data) {
|
|
36
|
+
try {
|
|
37
|
+
const json = JSON.parse(data);
|
|
38
|
+
if (json.data)
|
|
39
|
+
output_1.default.normal(json.data);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// do nothing
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
body.on('close', async () => {
|
|
47
|
+
const cmdExit = await client.getSandboxCommand(workspace, found.id, commandId);
|
|
48
|
+
if (cmdExit.status === utils_1.SANDBOX_EXEC_STATUS.SUCCESSFUL) {
|
|
49
|
+
output_1.default.exitSuccess((0, texts_1.TXT_SANDBOX_EXEC_SUCCESS)(commandId));
|
|
50
|
+
}
|
|
51
|
+
else if (cmdExit.status === utils_1.SANDBOX_EXEC_STATUS.INPROGRESS) {
|
|
52
|
+
output_1.default.exitNormal((0, texts_1.TXT_SANDBOX_EXEC_INPROGRESS)(commandId));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
output_1.default.exitError((0, texts_1.TXT_SANDBOX_EXEC_FAILED)(commandId));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
exports.default = commandSandboxExecLogs;
|