bdy 1.25.41-dev → 1.25.42-stage
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 +1 -1
- package/distTs/src/api/client.js +59 -1
- package/distTs/src/command/agent/debug.js +22 -1
- package/distTs/src/command/agent/disable.js +21 -2
- package/distTs/src/command/agent/enable.js +21 -2
- package/distTs/src/command/agent/proxy/disable.js +16 -2
- package/distTs/src/command/agent/proxy/enable.js +16 -2
- package/distTs/src/command/agent/proxy/status.js +32 -13
- package/distTs/src/command/agent/remote.js +219 -0
- package/distTs/src/command/agent/status.js +78 -48
- package/distTs/src/command/agent/tags/get.js +37 -13
- package/distTs/src/command/agent/tags/set.js +30 -9
- package/distTs/src/command/agent/target/disable.js +16 -2
- package/distTs/src/command/agent/target/enable.js +16 -2
- package/distTs/src/command/agent/target/status.js +32 -13
- package/distTs/src/command/agent/tunnel/disable.js +16 -2
- package/distTs/src/command/agent/tunnel/enable.js +16 -2
- package/distTs/src/command/agent/tunnel/http.js +21 -0
- package/distTs/src/command/agent/tunnel/list.js +28 -6
- package/distTs/src/command/agent/tunnel/remove.js +29 -1
- package/distTs/src/command/agent/tunnel/start.js +23 -0
- package/distTs/src/command/agent/tunnel/status.js +50 -13
- package/distTs/src/command/agent/tunnel/tcp.js +21 -0
- package/distTs/src/command/agent/tunnel/tls.js +21 -0
- package/distTs/src/command/agent/update.js +17 -1
- package/distTs/src/command/agent/version.js +28 -5
- package/distTs/src/command/pre.js +2 -1
- package/distTs/src/format.js +6 -0
- package/distTs/src/output.js +16 -0
- package/distTs/src/texts.js +231 -31
- package/distTs/src/tunnel/output/interactive/tunnel.js +67 -8
- package/distTs/src/tunnel/output/noninteractive/tunnel.js +8 -0
- package/distTs/src/types/serverAgent.js +2 -0
- package/package.json +1 -1
|
@@ -8,36 +8,10 @@ const node_fs_1 = require("node:fs");
|
|
|
8
8
|
const texts_1 = require("../../texts");
|
|
9
9
|
const utils_1 = require("../../utils");
|
|
10
10
|
const tunnel_1 = require("../../types/tunnel");
|
|
11
|
+
const remote_1 = require("./remote");
|
|
11
12
|
const commandAgentStatus = (0, utils_1.newCommand)('status', texts_1.DESC_COMMAND_AGENT_STATUS, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_STATUS, helpText: texts_1.HELP_AGENT_STATUS_JSON });
|
|
12
|
-
const outputStatus = (
|
|
13
|
-
const
|
|
14
|
-
if (!installed) {
|
|
15
|
-
// Nothing loaded, yet there is a file where the install would be - it is unreadable or not
|
|
16
|
-
// the shape this cli writes. Worth naming rather than reporting no install at all: the
|
|
17
|
-
// system config takes precedence whatever state it is in, so while it sits there an `--app`
|
|
18
|
-
// install in this account's home is shadowed by it and every command says the same nothing.
|
|
19
|
-
const active = AgentManager.system.getActiveConfigPath();
|
|
20
|
-
if ((0, node_fs_1.existsSync)(active)) {
|
|
21
|
-
output_1.default.exitError((0, texts_1.ERR_AGENT_CONFIG_UNREADABLE)(active));
|
|
22
|
-
}
|
|
23
|
-
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
24
|
-
}
|
|
25
|
-
const orphan = AgentManager.system.getStandaloneConfigPath();
|
|
26
|
-
const orphanedConfig = !AgentManager.system.isUserOwnedInstall() && (0, node_fs_1.existsSync)(orphan)
|
|
27
|
-
? orphan
|
|
28
|
-
: null;
|
|
29
|
-
if (json) {
|
|
30
|
-
output_1.default.json({
|
|
31
|
-
...commandAgentStatus.agentStatus,
|
|
32
|
-
installed,
|
|
33
|
-
standalone,
|
|
34
|
-
id: id ?? null,
|
|
35
|
-
version: version || null,
|
|
36
|
-
running,
|
|
37
|
-
orphaned_config: orphanedConfig,
|
|
38
|
-
});
|
|
39
|
-
output_1.default.exitNormal();
|
|
40
|
-
}
|
|
13
|
+
const outputStatus = (data) => {
|
|
14
|
+
const { standalone, version, id, running, enabled, target, tunneling, proxy, status } = data;
|
|
41
15
|
let txt = 'Installation: ';
|
|
42
16
|
if (standalone)
|
|
43
17
|
txt += 'App @ ';
|
|
@@ -82,29 +56,85 @@ const outputStatus = (installed, standalone, version, id, running, enabled, targ
|
|
|
82
56
|
// above: an install made before those files moved keeps its config in the system directory
|
|
83
57
|
// and reports itself as an app, and a leftover in the home is just as inert next to it.
|
|
84
58
|
// Inert, but only findable if it is said out loud.
|
|
85
|
-
if (orphanedConfig) {
|
|
86
|
-
output_1.default.error((0, texts_1.TXT_AGENT_APP_INSTALL_ORPHANED)(
|
|
59
|
+
if (data.orphanedConfig) {
|
|
60
|
+
output_1.default.error((0, texts_1.TXT_AGENT_APP_INSTALL_ORPHANED)(data.orphanedConfig));
|
|
87
61
|
}
|
|
88
62
|
output_1.default.exitNormal();
|
|
89
63
|
};
|
|
64
|
+
const localStatus = (json) => {
|
|
65
|
+
const AgentManager = require('../../agent/manager').default;
|
|
66
|
+
const agentStatus = commandAgentStatus.agentStatus;
|
|
67
|
+
if (!commandAgentStatus.agentInstalled) {
|
|
68
|
+
// Nothing loaded, yet there is a file where the install would be - it is unreadable or not
|
|
69
|
+
// the shape this cli writes. Worth naming rather than reporting no install at all: the
|
|
70
|
+
// system config takes precedence whatever state it is in, so while it sits there an `--app`
|
|
71
|
+
// install in this account's home is shadowed by it and every command says the same nothing.
|
|
72
|
+
const active = AgentManager.system.getActiveConfigPath();
|
|
73
|
+
if ((0, node_fs_1.existsSync)(active)) {
|
|
74
|
+
output_1.default.exitError((0, texts_1.ERR_AGENT_CONFIG_UNREADABLE)(active));
|
|
75
|
+
}
|
|
76
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
77
|
+
}
|
|
78
|
+
const orphan = AgentManager.system.getStandaloneConfigPath();
|
|
79
|
+
const orphanedConfig = !AgentManager.system.isUserOwnedInstall() && (0, node_fs_1.existsSync)(orphan)
|
|
80
|
+
? orphan
|
|
81
|
+
: null;
|
|
82
|
+
const data = {
|
|
83
|
+
installed: true,
|
|
84
|
+
standalone: !!commandAgentStatus.agentStandalone,
|
|
85
|
+
version: agentStatus?.version || '',
|
|
86
|
+
id: commandAgentStatus.agentId,
|
|
87
|
+
running: !!agentStatus,
|
|
88
|
+
enabled: agentStatus ? agentStatus.enabled : true,
|
|
89
|
+
target: agentStatus ? agentStatus.target : false,
|
|
90
|
+
tunneling: agentStatus ? agentStatus.tunneling : true,
|
|
91
|
+
proxy: agentStatus ? agentStatus.proxy : false,
|
|
92
|
+
status: agentStatus ? agentStatus.status : tunnel_1.TUNNEL_AGENT_STATUS.DISABLED,
|
|
93
|
+
orphanedConfig,
|
|
94
|
+
};
|
|
95
|
+
if (json) {
|
|
96
|
+
output_1.default.json({
|
|
97
|
+
...agentStatus,
|
|
98
|
+
installed: data.installed,
|
|
99
|
+
standalone: data.standalone,
|
|
100
|
+
id: data.id ?? null,
|
|
101
|
+
version: data.version || null,
|
|
102
|
+
running: data.running,
|
|
103
|
+
orphaned_config: orphanedConfig,
|
|
104
|
+
});
|
|
105
|
+
output_1.default.exitNormal();
|
|
106
|
+
}
|
|
107
|
+
outputStatus(data);
|
|
108
|
+
};
|
|
109
|
+
const remoteStatus = (agent, json) => {
|
|
110
|
+
const status = (0, remote_1.remoteAgentStatus)(agent);
|
|
111
|
+
if (json) {
|
|
112
|
+
output_1.default.json(status);
|
|
113
|
+
output_1.default.exitNormal();
|
|
114
|
+
}
|
|
115
|
+
outputStatus({
|
|
116
|
+
...status,
|
|
117
|
+
version: status.version || '',
|
|
118
|
+
orphanedConfig: null,
|
|
119
|
+
});
|
|
120
|
+
};
|
|
90
121
|
commandAgentStatus.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
status = commandAgentStatus.agentStatus.status;
|
|
104
|
-
target = commandAgentStatus.agentStatus.target;
|
|
105
|
-
tunneling = commandAgentStatus.agentStatus.tunneling;
|
|
106
|
-
proxy = commandAgentStatus.agentStatus.proxy;
|
|
122
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentStatus);
|
|
123
|
+
commandAgentStatus.action(async (options) => {
|
|
124
|
+
const json = options.format === 'json';
|
|
125
|
+
let agent = null;
|
|
126
|
+
try {
|
|
127
|
+
const remote = await (0, remote_1.resolveRemoteAgent)(options);
|
|
128
|
+
if (remote) {
|
|
129
|
+
agent = await remote.client.getServerAgent(remote.workspace, remote.agentId);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
output_1.default.exitError(err);
|
|
107
134
|
}
|
|
108
|
-
|
|
135
|
+
if (agent)
|
|
136
|
+
remoteStatus(agent, json);
|
|
137
|
+
else
|
|
138
|
+
localStatus(json);
|
|
109
139
|
});
|
|
110
140
|
exports.default = commandAgentStatus;
|
|
@@ -6,9 +6,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const remote_1 = require("../remote");
|
|
9
10
|
const commandAgentTagsGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_AGENT_TAGS_GET, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TAGS_GET });
|
|
10
11
|
commandAgentTagsGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
12
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTagsGet);
|
|
13
|
+
// no tags is a non-zero exit, in text and JSON alike
|
|
14
|
+
const output = (data, json) => {
|
|
15
|
+
if (json) {
|
|
16
|
+
output_1.default.json(data);
|
|
17
|
+
if (!data.tags?.length)
|
|
18
|
+
output_1.default.exitError(texts_1.TXT_AGENT_NO_TAGS);
|
|
19
|
+
output_1.default.exitNormal();
|
|
20
|
+
}
|
|
21
|
+
if (data.tags && data.tags.length > 0) {
|
|
22
|
+
output_1.default.exitNormal(data.tags.join(' '));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
output_1.default.exitError(texts_1.TXT_AGENT_NO_TAGS);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
11
28
|
commandAgentTagsGet.action(async (options) => {
|
|
29
|
+
const json = options.format === 'json';
|
|
30
|
+
// --agent: the tags of the REST view, in the local agent's shape
|
|
31
|
+
let remote = null;
|
|
32
|
+
try {
|
|
33
|
+
const agent = await (0, remote_1.resolveRemoteAgent)(options);
|
|
34
|
+
if (agent) {
|
|
35
|
+
const r = await agent.client.getServerAgent(agent.workspace, agent.agentId);
|
|
36
|
+
remote = { tags: r.tags || [] };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
output_1.default.exitError(err);
|
|
41
|
+
}
|
|
42
|
+
if (remote) {
|
|
43
|
+
output(remote, json);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
12
46
|
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
13
47
|
if (!commandAgentTagsGet.agentInstalled) {
|
|
14
48
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
@@ -16,24 +50,14 @@ commandAgentTagsGet.action(async (options) => {
|
|
|
16
50
|
if (!commandAgentTagsGet.agentStatus) {
|
|
17
51
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
18
52
|
}
|
|
53
|
+
let data;
|
|
19
54
|
try {
|
|
20
55
|
const api = new ApiAgent(commandAgentTagsGet.agentPort || 0);
|
|
21
|
-
|
|
22
|
-
if (options.format === 'json') {
|
|
23
|
-
output_1.default.json(data);
|
|
24
|
-
if (!data.tags?.length)
|
|
25
|
-
output_1.default.exitError(texts_1.TXT_AGENT_NO_TAGS);
|
|
26
|
-
output_1.default.exitNormal();
|
|
27
|
-
}
|
|
28
|
-
if (data.tags && data.tags.length > 0) {
|
|
29
|
-
output_1.default.exitNormal(data.tags.join(' '));
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
output_1.default.exitError(texts_1.TXT_AGENT_NO_TAGS);
|
|
33
|
-
}
|
|
56
|
+
data = await api.fetchAgentTags();
|
|
34
57
|
}
|
|
35
58
|
catch (err) {
|
|
36
59
|
output_1.default.exitError(err);
|
|
37
60
|
}
|
|
61
|
+
output(data, json);
|
|
38
62
|
});
|
|
39
63
|
exports.default = commandAgentTagsGet;
|
|
@@ -6,17 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
-
const
|
|
9
|
+
const remote_1 = require("../remote");
|
|
10
|
+
const commandAgentTagsSet = (0, utils_1.newCommand)('set', texts_1.DESC_COMMAND_AGENT_TAGS_SET, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TAGS_SET });
|
|
10
11
|
commandAgentTagsSet.argument('[tags...]', texts_1.OPT_COMMAND_AGENT_TAGS_SET);
|
|
11
12
|
commandAgentTagsSet.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
13
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTagsSet);
|
|
12
14
|
commandAgentTagsSet.action(async (tags, options) => {
|
|
13
|
-
const
|
|
14
|
-
if (!commandAgentTagsSet.agentInstalled) {
|
|
15
|
-
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
16
|
-
}
|
|
17
|
-
if (!commandAgentTagsSet.agentStatus) {
|
|
18
|
-
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
19
|
-
}
|
|
15
|
+
const json = options.format === 'json';
|
|
20
16
|
const validTags = [];
|
|
21
17
|
if (tags) {
|
|
22
18
|
tags.forEach((t) => {
|
|
@@ -27,10 +23,35 @@ commandAgentTagsSet.action(async (tags, options) => {
|
|
|
27
23
|
validTags.push(validTag);
|
|
28
24
|
});
|
|
29
25
|
}
|
|
26
|
+
// --agent: replaced through the REST API, which pushes them to the agent
|
|
27
|
+
let remote = null;
|
|
28
|
+
try {
|
|
29
|
+
const agent = await (0, remote_1.resolveRemoteAgent)(options);
|
|
30
|
+
if (agent) {
|
|
31
|
+
const r = await agent.client.updateServerAgent(agent.workspace, agent.agentId, {
|
|
32
|
+
tags: validTags,
|
|
33
|
+
});
|
|
34
|
+
remote = r.tags || [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
output_1.default.exitError(err);
|
|
39
|
+
}
|
|
40
|
+
if (remote) {
|
|
41
|
+
output_1.default.exitResult(json, { tags: remote }, texts_1.TXT_AGENT_TAGS_SET);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
45
|
+
if (!commandAgentTagsSet.agentInstalled) {
|
|
46
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
47
|
+
}
|
|
48
|
+
if (!commandAgentTagsSet.agentStatus) {
|
|
49
|
+
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
50
|
+
}
|
|
30
51
|
try {
|
|
31
52
|
const api = new ApiAgent(commandAgentTagsSet.agentPort || 0);
|
|
32
53
|
await api.setAgentTags(validTags);
|
|
33
|
-
output_1.default.exitResult(
|
|
54
|
+
output_1.default.exitResult(json, { tags: validTags }, texts_1.TXT_AGENT_TAGS_SET);
|
|
34
55
|
}
|
|
35
56
|
catch (err) {
|
|
36
57
|
output_1.default.exitError(err);
|
|
@@ -6,9 +6,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
-
const
|
|
9
|
+
const remote_1 = require("../remote");
|
|
10
|
+
const commandAgentTargetDisable = (0, utils_1.newCommand)('disable', texts_1.DESC_COMMAND_AGENT_TARGET_DISABLE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TARGET_DISABLE });
|
|
10
11
|
commandAgentTargetDisable.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
12
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTargetDisable);
|
|
11
13
|
commandAgentTargetDisable.action(async (options) => {
|
|
14
|
+
const json = options.format === 'json';
|
|
15
|
+
let remote = null;
|
|
16
|
+
try {
|
|
17
|
+
remote = await (0, remote_1.remoteAgentFlag)(options, 'target', false);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
output_1.default.exitError(err);
|
|
21
|
+
}
|
|
22
|
+
if (remote !== null) {
|
|
23
|
+
output_1.default.exitResult(json, { target: remote }, texts_1.TXT_AGENT_TARGET_DISABLED);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
12
26
|
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
13
27
|
if (!commandAgentTargetDisable.agentInstalled) {
|
|
14
28
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
@@ -19,7 +33,7 @@ commandAgentTargetDisable.action(async (options) => {
|
|
|
19
33
|
try {
|
|
20
34
|
const api = new ApiAgent(commandAgentTargetDisable.agentPort || 0);
|
|
21
35
|
await api.disableAgentTarget();
|
|
22
|
-
output_1.default.exitResult(
|
|
36
|
+
output_1.default.exitResult(json, { target: false }, texts_1.TXT_AGENT_TARGET_DISABLED);
|
|
23
37
|
}
|
|
24
38
|
catch (err) {
|
|
25
39
|
output_1.default.exitError(err);
|
|
@@ -6,9 +6,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
-
const
|
|
9
|
+
const remote_1 = require("../remote");
|
|
10
|
+
const commandAgentTargetEnable = (0, utils_1.newCommand)('enable', texts_1.DESC_COMMAND_AGENT_TARGET_ENABLE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TARGET_ENABLE });
|
|
10
11
|
commandAgentTargetEnable.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
12
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTargetEnable);
|
|
11
13
|
commandAgentTargetEnable.action(async (options) => {
|
|
14
|
+
const json = options.format === 'json';
|
|
15
|
+
let remote = null;
|
|
16
|
+
try {
|
|
17
|
+
remote = await (0, remote_1.remoteAgentFlag)(options, 'target', true);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
output_1.default.exitError(err);
|
|
21
|
+
}
|
|
22
|
+
if (remote !== null) {
|
|
23
|
+
output_1.default.exitResult(json, { target: remote }, texts_1.TXT_AGENT_TARGET_ENABLED);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
12
26
|
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
13
27
|
if (!commandAgentTargetEnable.agentInstalled) {
|
|
14
28
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
@@ -19,7 +33,7 @@ commandAgentTargetEnable.action(async (options) => {
|
|
|
19
33
|
try {
|
|
20
34
|
const api = new ApiAgent(commandAgentTargetEnable.agentPort || 0);
|
|
21
35
|
await api.enableAgentTarget();
|
|
22
|
-
output_1.default.exitResult(
|
|
36
|
+
output_1.default.exitResult(json, { target: true }, texts_1.TXT_AGENT_TARGET_ENABLED);
|
|
23
37
|
}
|
|
24
38
|
catch (err) {
|
|
25
39
|
output_1.default.exitError(err);
|
|
@@ -6,9 +6,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
+
const remote_1 = require("../remote");
|
|
9
10
|
const commandAgentTargetStatus = (0, utils_1.newCommand)('status', texts_1.DESC_COMMAND_AGENT_TARGET_STATUS, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TARGET_STATUS });
|
|
10
11
|
commandAgentTargetStatus.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
12
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTargetStatus);
|
|
13
|
+
// a disabled target is a non-zero exit, in text and JSON alike
|
|
14
|
+
const output = (data, json) => {
|
|
15
|
+
if (json) {
|
|
16
|
+
output_1.default.json(data);
|
|
17
|
+
if (!data.target)
|
|
18
|
+
output_1.default.exitError(texts_1.TXT_AGENT_TARGET_DISABLED);
|
|
19
|
+
output_1.default.exitNormal();
|
|
20
|
+
}
|
|
21
|
+
if (data.target) {
|
|
22
|
+
output_1.default.exitSuccess(texts_1.TXT_AGENT_TARGET_ENABLED);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
output_1.default.exitError(texts_1.TXT_AGENT_TARGET_DISABLED);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
11
28
|
commandAgentTargetStatus.action(async (options) => {
|
|
29
|
+
const json = options.format === 'json';
|
|
30
|
+
let remote = null;
|
|
31
|
+
try {
|
|
32
|
+
remote = await (0, remote_1.remoteAgentFlag)(options, 'target');
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
output_1.default.exitError(err);
|
|
36
|
+
}
|
|
37
|
+
if (remote !== null) {
|
|
38
|
+
output({ target: remote }, json);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
12
41
|
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
13
42
|
if (!commandAgentTargetStatus.agentInstalled) {
|
|
14
43
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
@@ -16,24 +45,14 @@ commandAgentTargetStatus.action(async (options) => {
|
|
|
16
45
|
if (!commandAgentTargetStatus.agentStatus) {
|
|
17
46
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
18
47
|
}
|
|
48
|
+
let data;
|
|
19
49
|
try {
|
|
20
50
|
const api = new ApiAgent(commandAgentTargetStatus.agentPort || 0);
|
|
21
|
-
|
|
22
|
-
if (options.format === 'json') {
|
|
23
|
-
output_1.default.json(data);
|
|
24
|
-
if (!data.target)
|
|
25
|
-
output_1.default.exitError(texts_1.TXT_AGENT_TARGET_DISABLED);
|
|
26
|
-
output_1.default.exitNormal();
|
|
27
|
-
}
|
|
28
|
-
if (data.target) {
|
|
29
|
-
output_1.default.exitSuccess(texts_1.TXT_AGENT_TARGET_ENABLED);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
output_1.default.exitError(texts_1.TXT_AGENT_TARGET_DISABLED);
|
|
33
|
-
}
|
|
51
|
+
data = await api.fetchAgentTarget();
|
|
34
52
|
}
|
|
35
53
|
catch (err) {
|
|
36
54
|
output_1.default.exitError(err);
|
|
37
55
|
}
|
|
56
|
+
output(data, json);
|
|
38
57
|
});
|
|
39
58
|
exports.default = commandAgentTargetStatus;
|
|
@@ -6,9 +6,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
-
const
|
|
9
|
+
const remote_1 = require("../remote");
|
|
10
|
+
const commandAgentTunnelDisable = (0, utils_1.newCommand)('disable', texts_1.DESC_COMMAND_AGENT_TUNNELING_DISABLE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TUNNELING_DISABLE });
|
|
10
11
|
commandAgentTunnelDisable.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
12
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTunnelDisable, false);
|
|
11
13
|
commandAgentTunnelDisable.action(async (options) => {
|
|
14
|
+
const json = options.format === 'json';
|
|
15
|
+
let remote = null;
|
|
16
|
+
try {
|
|
17
|
+
remote = await (0, remote_1.remoteAgentFlag)(options, 'tunneling', false);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
output_1.default.exitError(err);
|
|
21
|
+
}
|
|
22
|
+
if (remote !== null) {
|
|
23
|
+
output_1.default.exitResult(json, { tunneling: remote }, texts_1.TXT_AGENT_TUNNELING_DISABLED);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
12
26
|
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
13
27
|
if (!commandAgentTunnelDisable.agentInstalled) {
|
|
14
28
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
@@ -19,7 +33,7 @@ commandAgentTunnelDisable.action(async (options) => {
|
|
|
19
33
|
try {
|
|
20
34
|
const api = new ApiAgent(commandAgentTunnelDisable.agentPort || 0);
|
|
21
35
|
await api.disableAgentTunneling();
|
|
22
|
-
output_1.default.exitResult(
|
|
36
|
+
output_1.default.exitResult(json, { tunneling: false }, texts_1.TXT_AGENT_TUNNELING_DISABLED);
|
|
23
37
|
}
|
|
24
38
|
catch (err) {
|
|
25
39
|
output_1.default.exitError(err);
|
|
@@ -6,9 +6,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
-
const
|
|
9
|
+
const remote_1 = require("../remote");
|
|
10
|
+
const commandAgentTunnelEnable = (0, utils_1.newCommand)('enable', texts_1.DESC_COMMAND_AGENT_TUNNELING_ENABLE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TUNNELING_ENABLE });
|
|
10
11
|
commandAgentTunnelEnable.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
12
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTunnelEnable, false);
|
|
11
13
|
commandAgentTunnelEnable.action(async (options) => {
|
|
14
|
+
const json = options.format === 'json';
|
|
15
|
+
let remote = null;
|
|
16
|
+
try {
|
|
17
|
+
remote = await (0, remote_1.remoteAgentFlag)(options, 'tunneling', true);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
output_1.default.exitError(err);
|
|
21
|
+
}
|
|
22
|
+
if (remote !== null) {
|
|
23
|
+
output_1.default.exitResult(json, { tunneling: remote }, texts_1.TXT_AGENT_TUNNELING_ENABLED);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
12
26
|
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
13
27
|
if (!commandAgentTunnelEnable.agentInstalled) {
|
|
14
28
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
@@ -19,7 +33,7 @@ commandAgentTunnelEnable.action(async (options) => {
|
|
|
19
33
|
try {
|
|
20
34
|
const api = new ApiAgent(commandAgentTunnelEnable.agentPort || 0);
|
|
21
35
|
await api.enableAgentTunneling();
|
|
22
|
-
output_1.default.exitResult(
|
|
36
|
+
output_1.default.exitResult(json, { tunneling: true }, texts_1.TXT_AGENT_TUNNELING_ENABLED);
|
|
23
37
|
}
|
|
24
38
|
catch (err) {
|
|
25
39
|
output_1.default.exitError(err);
|
|
@@ -8,6 +8,7 @@ const output_1 = __importDefault(require("../../../output"));
|
|
|
8
8
|
const cliError_1 = __importDefault(require("../../../cliError"));
|
|
9
9
|
const texts_1 = require("../../../texts");
|
|
10
10
|
const tunnel_1 = require("../../../types/tunnel");
|
|
11
|
+
const remote_1 = require("../remote");
|
|
11
12
|
const commandAgentTunnelHttp = (0, utils_1.getBasicCommandHttp)({
|
|
12
13
|
requiredScopes: [],
|
|
13
14
|
examples: (0, texts_1.EXAMPLE_TUNNEL_HTTP)(true),
|
|
@@ -15,6 +16,7 @@ const commandAgentTunnelHttp = (0, utils_1.getBasicCommandHttp)({
|
|
|
15
16
|
commandAgentTunnelHttp.description(texts_1.DESC_COMMAND_AGENT_TUNNEL_HTTP);
|
|
16
17
|
commandAgentTunnelHttp.option('-f, --follow', texts_1.OPTION_FOLLOW);
|
|
17
18
|
commandAgentTunnelHttp.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
19
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTunnelHttp, false);
|
|
18
20
|
commandAgentTunnelHttp.argument('[protocol://host:port]', texts_1.OPTION_TARGET);
|
|
19
21
|
commandAgentTunnelHttp.action(async (target, options) => {
|
|
20
22
|
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
@@ -24,6 +26,25 @@ commandAgentTunnelHttp.action(async (target, options) => {
|
|
|
24
26
|
if (json && options.follow) {
|
|
25
27
|
throw new cliError_1.default('usage_error', texts_1.ERR_FOLLOW_WITH_JSON);
|
|
26
28
|
}
|
|
29
|
+
if (options.agent && options.follow) {
|
|
30
|
+
throw new cliError_1.default('usage_error', texts_1.ERR_FOLLOW_WITH_AGENT);
|
|
31
|
+
}
|
|
32
|
+
// --agent: added through the REST API; the agent starts it when it gets it
|
|
33
|
+
let added = null;
|
|
34
|
+
try {
|
|
35
|
+
const remote = await (0, remote_1.resolveRemoteAgent)(options);
|
|
36
|
+
if (remote) {
|
|
37
|
+
const prepared = await Cfg.prepareTunnel(tunnel_1.TUNNEL_TYPE.HTTP, target, options, false);
|
|
38
|
+
added = await remote.client.createServerAgentTunnel(remote.workspace, remote.agentId, (0, remote_1.remoteTunnelCreate)(prepared));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
output_1.default.exitError(err);
|
|
43
|
+
}
|
|
44
|
+
if (added) {
|
|
45
|
+
output_1.default.exitResult(json, { id: added.id, type: added.type }, (0, texts_1.TXT_TUNNEL_ADDED_REMOTE)(added.type, added.endpoint_url));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
27
48
|
if (!commandAgentTunnelHttp.agentInstalled) {
|
|
28
49
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
29
50
|
}
|
|
@@ -6,10 +6,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const output_1 = __importDefault(require("../../../output"));
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const utils_1 = require("../../../utils");
|
|
9
|
+
const remote_1 = require("../remote");
|
|
9
10
|
const commandAgentTunnelList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_AGENT_TUNNEL_LIST, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TUNNEL_LIST });
|
|
10
11
|
commandAgentTunnelList.alias('ls');
|
|
11
12
|
commandAgentTunnelList.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
13
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTunnelList, false);
|
|
14
|
+
const output = (data, json) => {
|
|
15
|
+
if (json) {
|
|
16
|
+
output_1.default.json(data);
|
|
17
|
+
output_1.default.exitNormal();
|
|
18
|
+
}
|
|
19
|
+
output_1.default.agentTunnels(data.tunnels);
|
|
20
|
+
};
|
|
12
21
|
commandAgentTunnelList.action(async (options) => {
|
|
22
|
+
const json = options.format === 'json';
|
|
23
|
+
let remote = null;
|
|
24
|
+
try {
|
|
25
|
+
const agent = await (0, remote_1.resolveRemoteAgent)(options);
|
|
26
|
+
if (agent) {
|
|
27
|
+
const r = await agent.client.getServerAgentTunnels(agent.workspace, agent.agentId);
|
|
28
|
+
remote = { tunnels: (r.tunnels || []).map(remote_1.remoteTunnelListItem) };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
output_1.default.exitError(err);
|
|
33
|
+
}
|
|
34
|
+
if (remote) {
|
|
35
|
+
output(remote, json);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
13
38
|
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
14
39
|
if (!commandAgentTunnelList.agentInstalled) {
|
|
15
40
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
@@ -17,17 +42,14 @@ commandAgentTunnelList.action(async (options) => {
|
|
|
17
42
|
if (!commandAgentTunnelList.agentStatus) {
|
|
18
43
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
19
44
|
}
|
|
45
|
+
let data;
|
|
20
46
|
try {
|
|
21
47
|
const api = new ApiAgent(commandAgentTunnelList.agentPort || 0);
|
|
22
|
-
|
|
23
|
-
if (options.format === 'json') {
|
|
24
|
-
output_1.default.json(data);
|
|
25
|
-
output_1.default.exitNormal();
|
|
26
|
-
}
|
|
27
|
-
output_1.default.agentTunnels(data.tunnels);
|
|
48
|
+
data = await api.fetchTunnels();
|
|
28
49
|
}
|
|
29
50
|
catch (err) {
|
|
30
51
|
output_1.default.exitError(err);
|
|
31
52
|
}
|
|
53
|
+
output(data, json);
|
|
32
54
|
});
|
|
33
55
|
exports.default = commandAgentTunnelList;
|
|
@@ -6,10 +6,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const output_1 = __importDefault(require("../../../output"));
|
|
7
7
|
const texts_1 = require("../../../texts");
|
|
8
8
|
const utils_1 = require("../../../utils");
|
|
9
|
+
const remote_1 = require("../remote");
|
|
9
10
|
const commandAgentTunnelRemove = (0, utils_1.newCommand)('rm', texts_1.DESC_COMMAND_AGENT_TUNNEL_REMOVE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TUNNEL_REMOVE });
|
|
10
11
|
commandAgentTunnelRemove.argument('<id>', texts_1.OPTION_ID);
|
|
12
|
+
commandAgentTunnelRemove.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
|
|
11
13
|
commandAgentTunnelRemove.option('--format <text|json>', texts_1.OPTION_FORMAT);
|
|
14
|
+
(0, remote_1.addRemoteAgentOptions)(commandAgentTunnelRemove, false);
|
|
12
15
|
commandAgentTunnelRemove.action(async (id, options) => {
|
|
16
|
+
const json = options.format === 'json';
|
|
17
|
+
// --agent: removed through the REST API, which pushes the removal to the agent
|
|
18
|
+
let removed = false;
|
|
19
|
+
try {
|
|
20
|
+
const remote = await (0, remote_1.resolveRemoteAgent)(options);
|
|
21
|
+
if (remote) {
|
|
22
|
+
// the tunnel first: a wrong id fails before the question
|
|
23
|
+
await remote.client.getServerAgentTunnel(remote.workspace, remote.agentId, id);
|
|
24
|
+
if (!(await output_1.default.confirmDestructive(options.force, (0, texts_1.TXT_AGENT_TUNNEL_REMOVE_CONFIRM)(id), json))) {
|
|
25
|
+
output_1.default.exitResult(json, { removed: null });
|
|
26
|
+
}
|
|
27
|
+
await remote.client.deleteServerAgentTunnel(remote.workspace, remote.agentId, id);
|
|
28
|
+
removed = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
output_1.default.exitError(err);
|
|
33
|
+
}
|
|
34
|
+
if (removed) {
|
|
35
|
+
output_1.default.exitResult(json, { removed: id }, texts_1.TXT_TUNNEL_REMOVED_REMOTE);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
13
38
|
const ApiAgent = require('../../../tunnel/api/agent').default;
|
|
14
39
|
if (!commandAgentTunnelRemove.agentInstalled) {
|
|
15
40
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
|
|
@@ -18,9 +43,12 @@ commandAgentTunnelRemove.action(async (id, options) => {
|
|
|
18
43
|
output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
|
|
19
44
|
}
|
|
20
45
|
try {
|
|
46
|
+
if (!(await output_1.default.confirmDestructive(options.force, (0, texts_1.TXT_AGENT_TUNNEL_REMOVE_CONFIRM)(id), json))) {
|
|
47
|
+
output_1.default.exitResult(json, { removed: null });
|
|
48
|
+
}
|
|
21
49
|
const api = new ApiAgent(commandAgentTunnelRemove.agentPort || 0);
|
|
22
50
|
await api.stopTunnel(id);
|
|
23
|
-
output_1.default.exitResult(
|
|
51
|
+
output_1.default.exitResult(json, { removed: id }, texts_1.TXT_TUNNEL_STOPPED);
|
|
24
52
|
}
|
|
25
53
|
catch (err) {
|
|
26
54
|
output_1.default.exitError(err);
|