bdy 1.25.40-dev → 1.25.42-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.
Files changed (51) hide show
  1. package/distTs/package.json +1 -1
  2. package/distTs/src/api/client.js +129 -60
  3. package/distTs/src/command/agent/debug.js +22 -1
  4. package/distTs/src/command/agent/disable.js +21 -2
  5. package/distTs/src/command/agent/enable.js +21 -2
  6. package/distTs/src/command/agent/proxy/disable.js +16 -2
  7. package/distTs/src/command/agent/proxy/enable.js +16 -2
  8. package/distTs/src/command/agent/proxy/status.js +32 -13
  9. package/distTs/src/command/agent/remote.js +219 -0
  10. package/distTs/src/command/agent/status.js +78 -48
  11. package/distTs/src/command/agent/tags/get.js +37 -13
  12. package/distTs/src/command/agent/tags/set.js +30 -9
  13. package/distTs/src/command/agent/target/disable.js +16 -2
  14. package/distTs/src/command/agent/target/enable.js +16 -2
  15. package/distTs/src/command/agent/target/status.js +32 -13
  16. package/distTs/src/command/agent/tunnel/disable.js +16 -2
  17. package/distTs/src/command/agent/tunnel/enable.js +16 -2
  18. package/distTs/src/command/agent/tunnel/http.js +21 -0
  19. package/distTs/src/command/agent/tunnel/list.js +28 -6
  20. package/distTs/src/command/agent/tunnel/remove.js +29 -1
  21. package/distTs/src/command/agent/tunnel/start.js +23 -0
  22. package/distTs/src/command/agent/tunnel/status.js +50 -13
  23. package/distTs/src/command/agent/tunnel/tcp.js +21 -0
  24. package/distTs/src/command/agent/tunnel/tls.js +21 -0
  25. package/distTs/src/command/agent/update.js +17 -1
  26. package/distTs/src/command/agent/version.js +28 -5
  27. package/distTs/src/command/distro/create.js +11 -6
  28. package/distTs/src/command/distro/delete.js +6 -13
  29. package/distTs/src/command/distro/get.js +6 -13
  30. package/distTs/src/command/distro/list.js +6 -6
  31. package/distTs/src/command/distro/open.js +5 -10
  32. package/distTs/src/command/distro/route/create.js +6 -14
  33. package/distTs/src/command/distro/route/delete.js +6 -13
  34. package/distTs/src/command/distro/route/get.js +9 -14
  35. package/distTs/src/command/distro/route/list.js +6 -13
  36. package/distTs/src/command/distro/route/open.js +5 -10
  37. package/distTs/src/command/distro/route/purge.js +42 -0
  38. package/distTs/src/command/distro/route/update.js +8 -15
  39. package/distTs/src/command/distro/route.js +3 -0
  40. package/distTs/src/command/distro/scope.js +77 -0
  41. package/distTs/src/command/distro/update.js +5 -13
  42. package/distTs/src/command/distro.js +1 -0
  43. package/distTs/src/command/pre.js +2 -1
  44. package/distTs/src/format.js +6 -0
  45. package/distTs/src/input.js +33 -10
  46. package/distTs/src/output.js +16 -0
  47. package/distTs/src/texts.js +273 -31
  48. package/distTs/src/tunnel/output/interactive/tunnel.js +67 -8
  49. package/distTs/src/tunnel/output/noninteractive/tunnel.js +8 -0
  50. package/distTs/src/types/serverAgent.js +2 -0
  51. package/package.json +1 -1
@@ -0,0 +1,219 @@
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
+ exports.remoteAgentAction = exports.remoteTunnelCreate = exports.remoteTunnelView = exports.remoteTunnelStatus = exports.remoteTunnelListItem = exports.remoteAgentFlag = exports.remoteAgentStatus = exports.remoteAgentApiStatus = exports.resolveRemoteAgent = exports.addRemoteAgentOptions = void 0;
7
+ const texts_1 = require("../../texts");
8
+ const input_1 = __importDefault(require("../../input"));
9
+ const cliError_1 = __importDefault(require("../../cliError"));
10
+ const tunnel_1 = require("../../types/tunnel");
11
+ // The options of the remote mode. The tunnel commands already use -w for
12
+ // --whitelist, so there the workspace has no short flag.
13
+ const addRemoteAgentOptions = (command, workspaceShort = true) => {
14
+ command.option('--agent <identifier>', texts_1.OPTION_AGENT_REMOTE);
15
+ command.option(workspaceShort ? '-w, --workspace <domain>' : '--workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
16
+ command.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
17
+ };
18
+ exports.addRemoteAgentOptions = addRemoteAgentOptions;
19
+ const notFound = () => new cliError_1.default('not_found', texts_1.ERR_AGENT_NOT_FOUND, texts_1.HINT_AGENT_REMOTE);
20
+ // null without --agent: the command goes to the local agent as before.
21
+ //
22
+ // --agent takes the agent's identifier or its hash id. With a project
23
+ // (--project, BUDDY_PROJECT, linked project) /identifiers looks among the
24
+ // agents of the project and of the workspace both (the backend's scope for
25
+ // agents, unlike the exact scope of the list), so a workspace agent is found
26
+ // from a linked directory too. /identifiers resolves an identifier or a
27
+ // numeric id only, so a value it does not know is tried as a hash id.
28
+ const resolveRemoteAgent = async (options) => {
29
+ if (!options.agent)
30
+ return null;
31
+ const workspace = input_1.default.restApiWorkspace(options.workspace);
32
+ const project = input_1.default.restApiProject(options.project, true);
33
+ const client = input_1.default.restApiTokenClient();
34
+ const resolved = await client.getResourceByIdentifier(workspace, {
35
+ project: project || undefined,
36
+ server_agent: options.agent,
37
+ });
38
+ if (resolved.server_agent_id) {
39
+ return { client, workspace, agentId: resolved.server_agent_id };
40
+ }
41
+ try {
42
+ const agent = await client.getServerAgent(workspace, options.agent);
43
+ return { client, workspace, agentId: agent.id };
44
+ }
45
+ catch (err) {
46
+ // a value that is not a hash id at all answers 400
47
+ if (err instanceof cliError_1.default && ['not_found', 'usage_error'].includes(err.code)) {
48
+ throw notFound();
49
+ }
50
+ throw err;
51
+ }
52
+ };
53
+ exports.resolveRemoteAgent = resolveRemoteAgent;
54
+ // The local agent's `/status` answer rebuilt from the REST view, so the JSON
55
+ // of `agent version` and `agent status` keeps one shape. The connection detail
56
+ // of the local status (fetch failed, initializing) is not reported over REST.
57
+ const remoteAgentApiStatus = (agent) => ({
58
+ id: agent.id,
59
+ status: agent.disabled ? tunnel_1.TUNNEL_AGENT_STATUS.DISABLED : tunnel_1.TUNNEL_AGENT_STATUS.ENABLED,
60
+ version: agent.version || null,
61
+ updating: agent.action === tunnel_1.TUNNEL_AGENT_ACTION.UPDATE ||
62
+ agent.action === tunnel_1.TUNNEL_AGENT_UPDATE_STATUS.STARTED,
63
+ enabled: !agent.disabled,
64
+ target: !!agent.target,
65
+ tunneling: !!agent.tunneling,
66
+ proxy: !!agent.proxy,
67
+ });
68
+ exports.remoteAgentApiStatus = remoteAgentApiStatus;
69
+ // `agent status`: the API status plus what the local command adds about the
70
+ // installation - here only what the REST view knows.
71
+ const remoteAgentStatus = (agent) => ({
72
+ ...(0, exports.remoteAgentApiStatus)(agent),
73
+ installed: true,
74
+ standalone: !agent.service,
75
+ running: !!agent.active,
76
+ orphaned_config: null,
77
+ });
78
+ exports.remoteAgentStatus = remoteAgentStatus;
79
+ // `agent target|proxy|tunnel ...` with --agent: reads the flag (no value) or
80
+ // sets it with a PATCH, which the backend pushes to the agent, and returns the
81
+ // stored state. null without --agent.
82
+ const remoteAgentFlag = async (options, flag, value) => {
83
+ const remote = await (0, exports.resolveRemoteAgent)(options);
84
+ if (!remote)
85
+ return null;
86
+ const agent = value === undefined
87
+ ? await remote.client.getServerAgent(remote.workspace, remote.agentId)
88
+ : await remote.client.updateServerAgent(remote.workspace, remote.agentId, {
89
+ [flag]: value,
90
+ });
91
+ return !!agent[flag];
92
+ };
93
+ exports.remoteAgentFlag = remoteAgentFlag;
94
+ // A latency the agent has not reported is unreachable, as the local agent says
95
+ const latency = (value) => value === undefined || value === null ? -1 : value;
96
+ // `agent tunnel list --agent`: one item of the local agent's `/tunnels`
97
+ // answer rebuilt from the REST view (the SSH tunnel is left out by both).
98
+ const remoteTunnelListItem = (tunnel) => ({
99
+ id: tunnel.id,
100
+ type: tunnel.type,
101
+ target: tunnel.endpoint,
102
+ domain: tunnel.domain,
103
+ subdomain: tunnel.subdomain,
104
+ serve: tunnel.http?.serve_path,
105
+ status: tunnel.active ? tunnel_1.TUNNEL_STATUS.OPEN : tunnel_1.TUNNEL_STATUS.CLOSED,
106
+ region: tunnel.region,
107
+ sshId: tunnel.ssh?.ssh_id,
108
+ sshForwardPort: tunnel.ssh?.forward_port,
109
+ regionLatency: latency(tunnel.region_latency),
110
+ targetLatency: latency(tunnel.target_latency),
111
+ });
112
+ exports.remoteTunnelListItem = remoteTunnelListItem;
113
+ // `agent tunnel status <id> --agent`: the status message the local agent
114
+ // streams for a tunnel, rebuilt from the REST view. Left out: `connections`
115
+ // (the agent's open connections - the REST view has only their count) and
116
+ // `dns` (the local check of the entry host).
117
+ const remoteTunnelStatus = (tunnel) => ({
118
+ regionLatency: { latency: latency(tunnel.region_latency) },
119
+ targetLatency: { latency: latency(tunnel.target_latency) },
120
+ identify: tunnel.http_identified ? { type: tunnel.http_identified } : null,
121
+ totalConnections: tunnel.total_connections ?? 0,
122
+ serve: tunnel.http?.serve_path,
123
+ log: !!tunnel.http?.log_requests,
124
+ status: tunnel.active ? tunnel_1.TUNNEL_STATUS.OPEN : tunnel_1.TUNNEL_STATUS.CLOSED,
125
+ region: tunnel.region,
126
+ type: tunnel.type,
127
+ target: tunnel.endpoint,
128
+ terminate: tunnel.tls?.terminate_at,
129
+ id: tunnel.id,
130
+ subdomain: tunnel.subdomain,
131
+ domain: tunnel.domain,
132
+ sshId: tunnel.ssh?.ssh_id,
133
+ sshForwardPort: tunnel.ssh?.forward_port,
134
+ });
135
+ exports.remoteTunnelStatus = remoteTunnelStatus;
136
+ // What the tunnel views read on top of the status message: the note and the
137
+ // open connections, of which the REST view knows the count only.
138
+ const remoteTunnelView = (tunnel) => {
139
+ const connections = {};
140
+ for (let i = 0; i < (tunnel.current_connections || 0); i += 1) {
141
+ connections[String(i)] = true;
142
+ }
143
+ return { ...(0, exports.remoteTunnelStatus)(tunnel), note: tunnel.note, connections };
144
+ };
145
+ exports.remoteTunnelView = remoteTunnelView;
146
+ // The CLI keeps a fraction, the API a whole percentage (an integer 0-100): a
147
+ // threshold with a fraction of a percent is refused rather than rounded into
148
+ // another value than the one the local agent would use.
149
+ const remoteCircuitBreaker = (fraction) => {
150
+ if (fraction === undefined || fraction === null)
151
+ return undefined;
152
+ const percent = fraction * 100;
153
+ const whole = Math.round(percent);
154
+ // the float product of a whole percentage is off by an epsilon (0.07 * 100)
155
+ if (Math.abs(percent - whole) > 1e-9) {
156
+ throw new cliError_1.default('usage_error', (0, texts_1.ERR_CB_THRESHOLD_NOT_INTEGER_REMOTE)(parseFloat(percent.toFixed(6))));
157
+ }
158
+ return whole;
159
+ };
160
+ const defined = (body) => {
161
+ Object.keys(body).forEach((key) => body[key] === undefined && delete body[key]);
162
+ return body;
163
+ };
164
+ // A tunnel definition (`Cfg.prepareTunnel`: the options of `agent tunnel
165
+ // tcp|tls|http`, or a tunnel of the config for `agent tunnel start`) as the
166
+ // body of POST /server-agents/{id}/tunnels. What the definition leaves out the
167
+ // backend fills with the agent's defaults (its region, timeout 30, no
168
+ // whitelist): the config defaults of this machine are no business of another.
169
+ const remoteTunnelCreate = (tunnel) => {
170
+ const body = defined({
171
+ type: tunnel.type,
172
+ endpoint: tunnel.target,
173
+ name: tunnel.name,
174
+ region: tunnel.region,
175
+ whitelist: tunnel.whitelist,
176
+ timeout: tunnel.timeout,
177
+ note: tunnel.note,
178
+ agent_note: tunnel.agentNote,
179
+ });
180
+ if (tunnel.type === tunnel_1.TUNNEL_TYPE.HTTP) {
181
+ body.http = defined({
182
+ auth_type: tunnel.authType,
183
+ login: tunnel.login,
184
+ password: tunnel.password,
185
+ tls_ca: tunnel.ca,
186
+ verify_certificate: tunnel.verify,
187
+ compression: tunnel.compression,
188
+ http2: tunnel.http2,
189
+ log_requests: tunnel.log,
190
+ request_headers: tunnel.headers,
191
+ response_headers: tunnel.responseHeaders,
192
+ whitelist_user_agents: tunnel.useragents,
193
+ rewrite_host_header: tunnel.host,
194
+ serve_path: tunnel.serve,
195
+ circuit_breaker: remoteCircuitBreaker(tunnel.circuitBreaker),
196
+ });
197
+ }
198
+ else if (tunnel.type === tunnel_1.TUNNEL_TYPE.TLS) {
199
+ body.tls = defined({
200
+ terminate_at: tunnel.terminate,
201
+ private_key: tunnel.key,
202
+ certificate: tunnel.cert,
203
+ ca_certificate: tunnel.ca,
204
+ });
205
+ }
206
+ return body;
207
+ };
208
+ exports.remoteTunnelCreate = remoteTunnelCreate;
209
+ // `agent update` / `agent debug` with --agent: the action is queued on the
210
+ // agent and done when the agent gets it - nothing is awaited. true once
211
+ // requested, null without --agent.
212
+ const remoteAgentAction = async (options, type) => {
213
+ const remote = await (0, exports.resolveRemoteAgent)(options);
214
+ if (!remote)
215
+ return null;
216
+ await remote.client.createServerAgentAction(remote.workspace, remote.agentId, type);
217
+ return true;
218
+ };
219
+ exports.remoteAgentAction = remoteAgentAction;
@@ -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 = (installed, standalone, version, id, running, enabled, target, tunneling, proxy, status, json) => {
13
- const AgentManager = require('../../agent/manager').default;
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)(orphan));
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
- commandAgentStatus.action((options) => {
92
- let version = '';
93
- const id = commandAgentStatus.agentId;
94
- const running = !!commandAgentStatus.agentStatus;
95
- let enabled = true;
96
- let target = false;
97
- let tunneling = true;
98
- let proxy = false;
99
- let status = tunnel_1.TUNNEL_AGENT_STATUS.DISABLED;
100
- if (commandAgentStatus.agentStatus) {
101
- version = commandAgentStatus.agentStatus.version;
102
- enabled = commandAgentStatus.agentStatus.enabled;
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
- outputStatus(!!commandAgentStatus.agentInstalled, !!commandAgentStatus.agentStandalone, version, id, running, enabled, target, tunneling, proxy, status, options.format === 'json');
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
- const data = await api.fetchAgentTags();
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 commandAgentTagsSet = (0, utils_1.newCommand)('set', texts_1.DESC_COMMAND_AGENT_TAGS_SET, { requiredScopes: [] });
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 ApiAgent = require('../../../tunnel/api/agent').default;
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(options.format === 'json', { tags: validTags }, texts_1.TXT_AGENT_TAGS_SET);
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 commandAgentTargetDisable = (0, utils_1.newCommand)('disable', texts_1.DESC_COMMAND_AGENT_TARGET_DISABLE, { requiredScopes: [] });
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(options.format === 'json', { target: false }, texts_1.TXT_AGENT_TARGET_DISABLED);
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 commandAgentTargetEnable = (0, utils_1.newCommand)('enable', texts_1.DESC_COMMAND_AGENT_TARGET_ENABLE, { requiredScopes: [] });
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(options.format === 'json', { target: true }, texts_1.TXT_AGENT_TARGET_ENABLED);
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
- const data = await api.fetchAgentTarget();
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 commandAgentTunnelDisable = (0, utils_1.newCommand)('disable', texts_1.DESC_COMMAND_AGENT_TUNNELING_DISABLE, { requiredScopes: [] });
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(options.format === 'json', { tunneling: false }, texts_1.TXT_AGENT_TUNNELING_DISABLED);
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);