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
@@ -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 commandAgentTunnelEnable = (0, utils_1.newCommand)('enable', texts_1.DESC_COMMAND_AGENT_TUNNELING_ENABLE, { requiredScopes: [] });
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(options.format === 'json', { tunneling: true }, texts_1.TXT_AGENT_TUNNELING_ENABLED);
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
- const data = await api.fetchTunnels();
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(options.format === 'json', { removed: id }, texts_1.TXT_TUNNEL_STOPPED);
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);
@@ -7,13 +7,36 @@ const cliError_1 = __importDefault(require("../../../cliError"));
7
7
  const output_1 = __importDefault(require("../../../output"));
8
8
  const texts_1 = require("../../../texts");
9
9
  const utils_1 = require("../../../utils");
10
+ const remote_1 = require("../remote");
10
11
  const commandAgentTunnelStart = (0, utils_1.newCommand)('start', texts_1.DESC_COMMAND_AGENT_TUNNEL_START, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TUNNEL_START });
11
12
  commandAgentTunnelStart.argument('<name>', texts_1.OPTION_NAME);
12
13
  commandAgentTunnelStart.option('--format <text|json>', texts_1.OPTION_FORMAT);
14
+ (0, remote_1.addRemoteAgentOptions)(commandAgentTunnelStart, false);
13
15
  commandAgentTunnelStart.action(async (name, options) => {
14
16
  const json = options.format === 'json';
15
17
  const ApiAgent = require('../../../tunnel/api/agent').default;
16
18
  const Cfg = require('../../../tunnel/cfg').default;
19
+ // --agent: the tunnel of this machine's config added to that agent through
20
+ // the REST API; the agent starts it when it gets it
21
+ if (options.agent) {
22
+ if (!Cfg.hasTunnel(name)) {
23
+ output_1.default.exitError(new cliError_1.default('not_found', (0, texts_1.ERR_TUNNEL_NOT_FOUND)(name), texts_1.HINT_TUNNEL_CONFIG_LIST));
24
+ }
25
+ let added = null;
26
+ try {
27
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
28
+ if (remote) {
29
+ added = await remote.client.createServerAgentTunnel(remote.workspace, remote.agentId, (0, remote_1.remoteTunnelCreate)(Cfg.getTunnel(name)));
30
+ }
31
+ }
32
+ catch (err) {
33
+ output_1.default.exitError(err);
34
+ }
35
+ if (added) {
36
+ output_1.default.exitResult(json, { id: added.id, type: added.type }, (0, texts_1.TXT_TUNNEL_ADDED_REMOTE)(added.type, added.endpoint_url));
37
+ return;
38
+ }
39
+ }
17
40
  if (!commandAgentTunnelStart.agentInstalled) {
18
41
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
19
42
  }
@@ -6,10 +6,58 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const texts_1 = require("../../../texts");
7
7
  const output_1 = __importDefault(require("../../../output"));
8
8
  const utils_1 = require("../../../utils");
9
+ const remote_1 = require("../remote");
9
10
  const commandAgentTunnelStatus = (0, utils_1.newCommand)('status', texts_1.DESC_COMMAND_AGENT_TUNNEL_STATUS, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_TUNNEL_STATUS });
10
11
  commandAgentTunnelStatus.argument('[id]', texts_1.OPTION_ID);
11
12
  commandAgentTunnelStatus.option('--format <text|json>', texts_1.OPTION_FORMAT);
13
+ (0, remote_1.addRemoteAgentOptions)(commandAgentTunnelStatus, false);
14
+ // without an id: whether the agent tunnels at all; disabled is a non-zero exit
15
+ const outputTunneling = (data, json) => {
16
+ if (json) {
17
+ output_1.default.json(data);
18
+ if (!data.tunneling)
19
+ output_1.default.exitError(texts_1.TXT_AGENT_TUNNELING_DISABLED);
20
+ output_1.default.exitNormal();
21
+ }
22
+ if (data.tunneling) {
23
+ output_1.default.exitSuccess(texts_1.TXT_AGENT_TUNNELING_ENABLED);
24
+ }
25
+ else {
26
+ output_1.default.exitError(texts_1.TXT_AGENT_TUNNELING_DISABLED);
27
+ }
28
+ };
12
29
  commandAgentTunnelStatus.action(async (id, options) => {
30
+ const json = options.format === 'json';
31
+ // --agent: the REST API. A tunnel is read once - the agent's last report,
32
+ // nothing to follow - and shown in the same view as a followed one.
33
+ let tunneling = null;
34
+ let tunnel = null;
35
+ try {
36
+ if (id) {
37
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
38
+ if (remote) {
39
+ tunnel = await remote.client.getServerAgentTunnel(remote.workspace, remote.agentId, id);
40
+ }
41
+ }
42
+ else {
43
+ tunneling = await (0, remote_1.remoteAgentFlag)(options, 'tunneling');
44
+ }
45
+ }
46
+ catch (err) {
47
+ output_1.default.exitError(err);
48
+ }
49
+ if (tunneling !== null) {
50
+ outputTunneling({ tunneling }, json);
51
+ return;
52
+ }
53
+ if (tunnel) {
54
+ if (json) {
55
+ output_1.default.json((0, remote_1.remoteTunnelStatus)(tunnel));
56
+ output_1.default.exitNormal();
57
+ }
58
+ output_1.default.tunnelSnapshot((0, remote_1.remoteTunnelView)(tunnel));
59
+ return;
60
+ }
13
61
  const ApiAgent = require('../../../tunnel/api/agent').default;
14
62
  const AgentSocketTunnel = require('../../../agent/socket/tunnel').default;
15
63
  if (!commandAgentTunnelStatus.agentInstalled) {
@@ -22,24 +70,13 @@ commandAgentTunnelStatus.action(async (id, options) => {
22
70
  const api = new ApiAgent(commandAgentTunnelStatus.agentPort || 0);
23
71
  if (!id) {
24
72
  const data = await api.fetchAgentTunneling();
25
- if (options.format === 'json') {
26
- output_1.default.json(data);
27
- if (!data.tunneling)
28
- output_1.default.exitError(texts_1.TXT_AGENT_TUNNELING_DISABLED);
29
- output_1.default.exitNormal();
30
- }
31
- if (data.tunneling) {
32
- output_1.default.exitSuccess(texts_1.TXT_AGENT_TUNNELING_ENABLED);
33
- }
34
- else {
35
- output_1.default.exitError(texts_1.TXT_AGENT_TUNNELING_DISABLED);
36
- }
73
+ outputTunneling(data, json);
37
74
  return;
38
75
  }
39
76
  const ws = await api.socketTunnel(id);
40
77
  const tunnel = new AgentSocketTunnel(ws, id);
41
78
  await tunnel.waitForReady();
42
- if (options.format === 'json') {
79
+ if (json) {
43
80
  output_1.default.json(tunnel.rawStatus);
44
81
  tunnel.close();
45
82
  output_1.default.exitNormal();
@@ -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 commandAgentTunnelTcp = (0, utils_1.getBasicCommandTcp)({
12
13
  requiredScopes: [],
13
14
  examples: (0, texts_1.EXAMPLE_TUNNEL_TCP)(true),
@@ -15,6 +16,7 @@ const commandAgentTunnelTcp = (0, utils_1.getBasicCommandTcp)({
15
16
  commandAgentTunnelTcp.description(texts_1.DESC_COMMAND_AGENT_TUNNEL_TCP);
16
17
  commandAgentTunnelTcp.option('-f, --follow', texts_1.OPTION_FOLLOW);
17
18
  commandAgentTunnelTcp.option('--format <text|json>', texts_1.OPTION_FORMAT);
19
+ (0, remote_1.addRemoteAgentOptions)(commandAgentTunnelTcp, false);
18
20
  commandAgentTunnelTcp.argument('[host:port]', texts_1.OPTION_TARGET);
19
21
  commandAgentTunnelTcp.action(async (target, options) => {
20
22
  const ApiAgent = require('../../../tunnel/api/agent').default;
@@ -24,6 +26,25 @@ commandAgentTunnelTcp.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.TCP, 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 (!commandAgentTunnelTcp.agentInstalled) {
28
49
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
29
50
  }
@@ -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 commandAgentTunnelTls = (0, utils_1.getBasicCommandTls)({
12
13
  requiredScopes: [],
13
14
  examples: (0, texts_1.EXAMPLE_TUNNEL_TLS)(true),
@@ -15,6 +16,7 @@ const commandAgentTunnelTls = (0, utils_1.getBasicCommandTls)({
15
16
  commandAgentTunnelTls.description(texts_1.DESC_COMMAND_AGENT_TUNNEL_TLS);
16
17
  commandAgentTunnelTls.option('-f, --follow', texts_1.OPTION_FOLLOW);
17
18
  commandAgentTunnelTls.option('--format <text|json>', texts_1.OPTION_FORMAT);
19
+ (0, remote_1.addRemoteAgentOptions)(commandAgentTunnelTls, false);
18
20
  commandAgentTunnelTls.argument('[host:port]', texts_1.OPTION_TARGET);
19
21
  commandAgentTunnelTls.action(async (target, options) => {
20
22
  const ApiAgent = require('../../../tunnel/api/agent').default;
@@ -24,6 +26,25 @@ commandAgentTunnelTls.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.TLS, 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 (!commandAgentTunnelTls.agentInstalled) {
28
49
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
29
50
  }
@@ -6,11 +6,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const texts_1 = require("../../texts");
7
7
  const output_1 = __importDefault(require("../../output"));
8
8
  const utils_1 = require("../../utils");
9
- const commandAgentUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_AGENT_UPDATE, { requiredScopes: [] });
9
+ const remote_1 = require("./remote");
10
+ const commandAgentUpdate = (0, utils_1.newCommand)('update', texts_1.DESC_COMMAND_AGENT_UPDATE, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_UPDATE });
10
11
  commandAgentUpdate.hideVersionUpdate = true;
11
12
  commandAgentUpdate.option('--format <text|json>', texts_1.OPTION_FORMAT);
13
+ (0, remote_1.addRemoteAgentOptions)(commandAgentUpdate);
12
14
  commandAgentUpdate.action(async (options) => {
13
15
  const json = options.format === 'json';
16
+ // --agent: requested through the REST API and done by the agent when it gets
17
+ // it (its outcome lands in `action`, see `agent status --agent`); a pending
18
+ // action answers 409
19
+ let requested = null;
20
+ try {
21
+ requested = await (0, remote_1.remoteAgentAction)(options, 'UPDATE');
22
+ }
23
+ catch (err) {
24
+ output_1.default.exitError(err);
25
+ }
26
+ if (requested) {
27
+ output_1.default.exitResult(json, { updated: false, requested: true }, texts_1.TXT_AGENT_UPDATE_REQUESTED);
28
+ return;
29
+ }
14
30
  const AgentManager = require('../../agent/manager').default;
15
31
  const ApiAgent = require('../../tunnel/api/agent').default;
16
32
  const waitUntilAgentEnabled = require('../../agent/wait').default;
@@ -6,19 +6,42 @@ 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 commandAgentVersion = (0, utils_1.newCommand)('version', texts_1.DESC_COMMAND_AGENT_VERSION, { requiredScopes: [], examples: texts_1.EXAMPLE_AGENT_VERSION });
10
11
  commandAgentVersion.option('--format <text|json>', texts_1.OPTION_FORMAT);
12
+ (0, remote_1.addRemoteAgentOptions)(commandAgentVersion);
13
+ const output = (status, json) => {
14
+ if (json) {
15
+ output_1.default.json(status);
16
+ output_1.default.exitNormal();
17
+ }
18
+ output_1.default.exitNormal(status.version || '');
19
+ };
11
20
  commandAgentVersion.action(async (options) => {
21
+ const json = options.format === 'json';
22
+ let agent = null;
23
+ try {
24
+ const remote = await (0, remote_1.resolveRemoteAgent)(options);
25
+ if (remote) {
26
+ agent = await remote.client.getServerAgent(remote.workspace, remote.agentId);
27
+ }
28
+ }
29
+ catch (err) {
30
+ output_1.default.exitError(err);
31
+ }
32
+ if (agent) {
33
+ // the version is the agent's own report: none before it first reports
34
+ if (!agent.version)
35
+ output_1.default.exitError(texts_1.ERR_AGENT_VERSION_UNKNOWN);
36
+ output((0, remote_1.remoteAgentApiStatus)(agent), json);
37
+ return;
38
+ }
12
39
  if (!commandAgentVersion.agentInstalled) {
13
40
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_INSTALLED);
14
41
  }
15
42
  if (!commandAgentVersion.agentStatus) {
16
43
  output_1.default.exitError(texts_1.ERR_AGENT_NOT_RUNNING);
17
44
  }
18
- if (options.format === 'json') {
19
- output_1.default.json(commandAgentVersion.agentStatus);
20
- output_1.default.exitNormal();
21
- }
22
- output_1.default.exitNormal(commandAgentVersion.agentStatus.version);
45
+ output(commandAgentVersion.agentStatus, json);
23
46
  });
24
47
  exports.default = commandAgentVersion;
@@ -8,6 +8,7 @@ const texts_1 = require("../../texts");
8
8
  const input_1 = __importDefault(require("../../input"));
9
9
  const output_1 = __importDefault(require("../../output"));
10
10
  const distro_1 = require("../../types/distro");
11
+ const scope_1 = require("./scope");
11
12
  const commandDistroCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMAND_DISTRO_CREATE, {
12
13
  requiredScopes: [utils_1.REST_API_SCOPE.DISTRIBUTION_WRITE],
13
14
  examples: texts_1.EXAMPLE_DISTRO_CREATE,
@@ -15,7 +16,8 @@ const commandDistroCreate = (0, utils_1.newCommand)('create', texts_1.DESC_COMMA
15
16
  commandDistroCreate.alias('add');
16
17
  commandDistroCreate.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
17
18
  commandDistroCreate.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
- commandDistroCreate.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
19
+ commandDistroCreate.option('--environment <identifier>', texts_1.OPTION_DISTRO_ENVIRONMENT);
20
+ commandDistroCreate.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE_ENVIRONMENT);
19
21
  commandDistroCreate.option('-i, --identifier <identifier>', texts_1.OPT_COMMAND_DISTRO_IDENTIFIER);
20
22
  commandDistroCreate.option('-n, --name <name>', texts_1.OPT_COMMAND_DISTRO_NAME);
21
23
  commandDistroCreate.option('--note <note>', texts_1.OPT_COMMAND_DISTRO_NOTE);
@@ -24,16 +26,15 @@ commandDistroCreate.option('--format <text|json>', texts_1.OPTION_FORMAT);
24
26
  commandDistroCreate.action(async (options) => {
25
27
  const humanId = require('human-id').default;
26
28
  const workspace = input_1.default.restApiWorkspace(options.workspace);
27
- const project = input_1.default.restApiProject(options.project, true);
28
29
  const client = input_1.default.restApiTokenClient();
29
- const scope = input_1.default.scope(project, options.scope);
30
+ const ctx = await (0, scope_1.resolveDistroContext)(client, workspace, options);
30
31
  const timestamp = Date.now().toString(36);
31
32
  const baseName = humanId({ separator: '-', capitalize: false });
32
33
  const defaultIdentifier = `${baseName}-${timestamp}`;
33
34
  const body = {
34
35
  name: options.name || options.identifier || baseName,
35
36
  identifier: options.identifier || defaultIdentifier,
36
- scope,
37
+ scope: ctx.scope,
37
38
  };
38
39
  if (options.note) {
39
40
  body.note = options.note;
@@ -41,8 +42,12 @@ commandDistroCreate.action(async (options) => {
41
42
  if (options.agentNote) {
42
43
  body.agent_note = options.agentNote;
43
44
  }
44
- if (project && scope === distro_1.SCOPE.PROJECT)
45
- body.project_name = project;
45
+ // an environment distribution has no permissions of its own: they follow
46
+ // the environment
47
+ if (ctx.scope === distro_1.SCOPE.ENVIRONMENT)
48
+ body.environment_id = ctx.environmentId;
49
+ else if (ctx.scope === distro_1.SCOPE.PROJECT)
50
+ body.project_name = ctx.project;
46
51
  const result = await client.createDistro(workspace, body);
47
52
  if (options.format === 'json') {
48
53
  output_1.default.json(result);
@@ -3,39 +3,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const cliError_1 = __importDefault(require("../../cliError"));
7
6
  const utils_1 = require("../../utils");
8
7
  const texts_1 = require("../../texts");
9
8
  const input_1 = __importDefault(require("../../input"));
10
9
  const output_1 = __importDefault(require("../../output"));
11
- const distro_1 = require("../../types/distro");
10
+ const scope_1 = require("./scope");
12
11
  const commandDistroDelete = (0, utils_1.newCommand)('delete', texts_1.DESC_COMMAND_DISTRO_DELETE, {
13
12
  requiredScopes: [utils_1.REST_API_SCOPE.DISTRIBUTION_MANAGE],
14
13
  examples: texts_1.EXAMPLE_DISTRO_DELETE,
15
14
  });
16
15
  commandDistroDelete.alias('rm');
17
16
  commandDistroDelete.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
18
- commandDistroDelete.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
17
+ commandDistroDelete.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE_ENVIRONMENT);
19
18
  commandDistroDelete.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
19
+ commandDistroDelete.option('--environment <identifier>', texts_1.OPTION_DISTRO_ENVIRONMENT);
20
20
  commandDistroDelete.option('-f, --force', texts_1.OPTION_CONFIRM_FORCE);
21
21
  commandDistroDelete.option('--format <text|json>', texts_1.OPTION_FORMAT);
22
22
  commandDistroDelete.argument('<identifier>', texts_1.OPT_COMMAND_DISTRO_IDENTIFIER);
23
23
  commandDistroDelete.action(async (identifier, options) => {
24
24
  const workspace = input_1.default.restApiWorkspace(options.workspace);
25
- const project = input_1.default.restApiProject(options.project, true);
26
- const scope = input_1.default.scope(project, options.scope);
27
25
  const client = input_1.default.restApiTokenClient();
28
- const data = await client.getDistributionByIdentifier(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, identifier);
29
- if (!data || !data.domain) {
30
- output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_WORKSPACE_NOT_FOUND, texts_1.HINT_WORKSPACE_LIST));
31
- }
32
- if (!data || !data.distribution_id) {
33
- output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_COMMAND_DISTRO_NOT_FOUND, texts_1.HINT_DISTRO_LIST));
34
- }
26
+ const ctx = await (0, scope_1.resolveDistroContext)(client, workspace, options, identifier);
27
+ const distributionId = ctx.distributionId;
35
28
  const json = options.format === 'json';
36
29
  const confirmed = await output_1.default.confirmDestructive(options.force, (0, texts_1.TXT_COMMAND_DISTRO_DELETE_CONFIRM)(identifier), json);
37
30
  if (confirmed) {
38
- await client.deleteDistribution(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, data.distribution_id);
31
+ await client.deleteDistribution(workspace, ctx.api, distributionId);
39
32
  output_1.default.exitResult(json, { deleted: identifier }, texts_1.TXT_COMMAND_DISTRO_DELETED);
40
33
  }
41
34
  else {
@@ -3,35 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const cliError_1 = __importDefault(require("../../cliError"));
7
6
  const utils_1 = require("../../utils");
8
7
  const texts_1 = require("../../texts");
9
8
  const input_1 = __importDefault(require("../../input"));
10
9
  const output_1 = __importDefault(require("../../output"));
11
- const distro_1 = require("../../types/distro");
10
+ const scope_1 = require("./scope");
12
11
  const commandDistroGet = (0, utils_1.newCommand)('get', texts_1.DESC_COMMAND_DISTRO_GET, {
13
12
  requiredScopes: [utils_1.REST_API_SCOPE.DISTRIBUTION_READ],
14
13
  examples: texts_1.EXAMPLE_DISTRO_GET,
15
14
  });
16
15
  commandDistroGet.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
17
- commandDistroGet.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
16
+ commandDistroGet.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE_ENVIRONMENT);
18
17
  commandDistroGet.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
+ commandDistroGet.option('--environment <identifier>', texts_1.OPTION_DISTRO_ENVIRONMENT);
19
19
  commandDistroGet.option('--format <text|json>', texts_1.OPTION_FORMAT);
20
20
  commandDistroGet.option('--no-parent-notes', texts_1.OPTION_NO_PARENT_NOTES);
21
21
  commandDistroGet.argument('<identifier>', texts_1.OPT_COMMAND_DISTRO_IDENTIFIER);
22
22
  commandDistroGet.action(async (identifier, options) => {
23
23
  const workspace = input_1.default.restApiWorkspace(options.workspace);
24
- const project = input_1.default.restApiProject(options.project, true);
25
- const scope = input_1.default.scope(project, options.scope);
26
24
  const client = input_1.default.restApiTokenClient();
27
- const data = await client.getDistributionByIdentifier(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, identifier);
28
- if (!data || !data.domain) {
29
- output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_WORKSPACE_NOT_FOUND, texts_1.HINT_WORKSPACE_LIST));
30
- }
31
- if (!data || !data.distribution_id) {
32
- output_1.default.exitError(new cliError_1.default('not_found', texts_1.ERR_COMMAND_DISTRO_NOT_FOUND, texts_1.HINT_DISTRO_LIST));
33
- }
34
- const distro = await client.getDistribution(workspace, scope === distro_1.SCOPE.PROJECT ? project : null, data.distribution_id);
25
+ const ctx = await (0, scope_1.resolveDistroContext)(client, workspace, options, identifier);
26
+ const distributionId = ctx.distributionId;
27
+ const distro = await client.getDistribution(workspace, ctx.api, distributionId);
35
28
  if (options.format === 'json') {
36
29
  output_1.default.json(await client.withParentNotes(workspace, distro, options.parentNotes));
37
30
  }
@@ -7,7 +7,7 @@ const utils_1 = require("../../utils");
7
7
  const texts_1 = require("../../texts");
8
8
  const input_1 = __importDefault(require("../../input"));
9
9
  const output_1 = __importDefault(require("../../output"));
10
- const distro_1 = require("../../types/distro");
10
+ const scope_1 = require("./scope");
11
11
  const commandDistroList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_DISTRO_LIST, {
12
12
  requiredScopes: [utils_1.REST_API_SCOPE.DISTRIBUTION_READ],
13
13
  examples: texts_1.EXAMPLE_DISTRO_LIST,
@@ -15,15 +15,15 @@ const commandDistroList = (0, utils_1.newCommand)('list', texts_1.DESC_COMMAND_D
15
15
  commandDistroList.alias('ls');
16
16
  commandDistroList.option('-w, --workspace <domain>', texts_1.OPTION_REST_API_WORKSPACE);
17
17
  commandDistroList.option('-p, --project <name>', texts_1.OPTION_REST_API_PROJECT);
18
+ commandDistroList.option('--environment <identifier>', texts_1.OPTION_DISTRO_ENVIRONMENT);
18
19
  commandDistroList.option('--format <text|json>', texts_1.OPTION_FORMAT);
19
- commandDistroList.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE);
20
+ commandDistroList.option('--scope <scope>', texts_1.OPT_COMMAND_SCOPE_ENVIRONMENT);
20
21
  commandDistroList.action(async (options) => {
21
22
  const workspace = input_1.default.restApiWorkspace(options.workspace);
22
- const project = input_1.default.restApiProject(options.project, true);
23
- const scope = input_1.default.scope(project, options.scope);
24
- input_1.default.projectScopeNote(options, project, scope, 'distributions');
25
23
  const client = input_1.default.restApiTokenClient();
26
- const r = await client.getDistributions(workspace, scope === distro_1.SCOPE.PROJECT ? project : null);
24
+ const ctx = await (0, scope_1.resolveDistroContext)(client, workspace, options);
25
+ input_1.default.projectScopeNote(options, ctx.project, ctx.scope, 'distributions');
26
+ const r = await client.getDistributions(workspace, ctx.api);
27
27
  const distributions = r.distributions || [];
28
28
  if (options.format === 'json') {
29
29
  output_1.default.json(distributions);