bdy 1.12.8-beta → 1.12.8-dev-pipeline-run

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 (156) hide show
  1. package/distTs/package.json +1 -1
  2. package/package.json +1 -1
  3. package/distTs/bin/cli.js +0 -5
  4. package/distTs/src/agent/agent.js +0 -328
  5. package/distTs/src/agent/linux.js +0 -124
  6. package/distTs/src/agent/manager.js +0 -519
  7. package/distTs/src/agent/osx.js +0 -146
  8. package/distTs/src/agent/socket/client.js +0 -178
  9. package/distTs/src/agent/socket/tunnel.js +0 -237
  10. package/distTs/src/agent/socket.js +0 -242
  11. package/distTs/src/agent/system.js +0 -179
  12. package/distTs/src/agent/wait.js +0 -23
  13. package/distTs/src/agent/windows.js +0 -159
  14. package/distTs/src/agent.js +0 -302
  15. package/distTs/src/api/agent.js +0 -99
  16. package/distTs/src/api/buddy.js +0 -139
  17. package/distTs/src/api/socket.js +0 -159
  18. package/distTs/src/cfg.js +0 -234
  19. package/distTs/src/command/agent/disable.js +0 -27
  20. package/distTs/src/command/agent/enable.js +0 -27
  21. package/distTs/src/command/agent/install.js +0 -117
  22. package/distTs/src/command/agent/restart.js +0 -27
  23. package/distTs/src/command/agent/run.js +0 -19
  24. package/distTs/src/command/agent/start.js +0 -28
  25. package/distTs/src/command/agent/status.js +0 -34
  26. package/distTs/src/command/agent/stop.js +0 -28
  27. package/distTs/src/command/agent/target/disable.js +0 -27
  28. package/distTs/src/command/agent/target/enable.js +0 -27
  29. package/distTs/src/command/agent/target/status.js +0 -32
  30. package/distTs/src/command/agent/target.js +0 -15
  31. package/distTs/src/command/agent/tunnel/http.js +0 -43
  32. package/distTs/src/command/agent/tunnel/list.js +0 -27
  33. package/distTs/src/command/agent/tunnel/remove.js +0 -28
  34. package/distTs/src/command/agent/tunnel/start.js +0 -34
  35. package/distTs/src/command/agent/tunnel/status.js +0 -31
  36. package/distTs/src/command/agent/tunnel/tcp.js +0 -43
  37. package/distTs/src/command/agent/tunnel/tls.js +0 -43
  38. package/distTs/src/command/agent/tunnel.js +0 -23
  39. package/distTs/src/command/agent/uninstall.js +0 -44
  40. package/distTs/src/command/agent/update.js +0 -38
  41. package/distTs/src/command/agent/version.js +0 -21
  42. package/distTs/src/command/agent.js +0 -35
  43. package/distTs/src/command/config/add/http.js +0 -25
  44. package/distTs/src/command/config/add/tcp.js +0 -25
  45. package/distTs/src/command/config/add/tls.js +0 -25
  46. package/distTs/src/command/config/add.js +0 -15
  47. package/distTs/src/command/config/get/region.js +0 -15
  48. package/distTs/src/command/config/get/timeout.js +0 -15
  49. package/distTs/src/command/config/get/token.js +0 -15
  50. package/distTs/src/command/config/get/tunnel.js +0 -19
  51. package/distTs/src/command/config/get/tunnels.js +0 -15
  52. package/distTs/src/command/config/get/whitelist.js +0 -15
  53. package/distTs/src/command/config/get.js +0 -21
  54. package/distTs/src/command/config/remove/tunnel.js +0 -19
  55. package/distTs/src/command/config/remove.js +0 -11
  56. package/distTs/src/command/config/set/region.js +0 -17
  57. package/distTs/src/command/config/set/timeout.js +0 -17
  58. package/distTs/src/command/config/set/token.js +0 -16
  59. package/distTs/src/command/config/set/whitelist.js +0 -17
  60. package/distTs/src/command/config/set.js +0 -17
  61. package/distTs/src/command/config.js +0 -17
  62. package/distTs/src/command/http.js +0 -30
  63. package/distTs/src/command/pre.js +0 -49
  64. package/distTs/src/command/start.js +0 -28
  65. package/distTs/src/command/tcp.js +0 -30
  66. package/distTs/src/command/tls.js +0 -30
  67. package/distTs/src/command/tunnel/config.js +0 -17
  68. package/distTs/src/command/tunnel/http.js +0 -31
  69. package/distTs/src/command/tunnel/start.js +0 -28
  70. package/distTs/src/command/tunnel/tcp.js +0 -30
  71. package/distTs/src/command/tunnel/tls.js +0 -30
  72. package/distTs/src/command/tunnel.js +0 -19
  73. package/distTs/src/command/ut/upload.js +0 -108
  74. package/distTs/src/command/ut.js +0 -12
  75. package/distTs/src/command/version.js +0 -13
  76. package/distTs/src/command/vt/close.js +0 -27
  77. package/distTs/src/command/vt/compare/validation.js +0 -173
  78. package/distTs/src/command/vt/compare.js +0 -97
  79. package/distTs/src/command/vt/exec.js +0 -81
  80. package/distTs/src/command/vt/installBrowser.js +0 -20
  81. package/distTs/src/command/vt/scrap.js +0 -193
  82. package/distTs/src/command/vt/storybook.js +0 -92
  83. package/distTs/src/command/vt.js +0 -22
  84. package/distTs/src/format.js +0 -174
  85. package/distTs/src/index.js +0 -34
  86. package/distTs/src/input.js +0 -270
  87. package/distTs/src/logger.js +0 -95
  88. package/distTs/src/output/interactive/tunnel.js +0 -860
  89. package/distTs/src/output/noninteractive/agent/tunnels.js +0 -43
  90. package/distTs/src/output/noninteractive/config/tunnel.js +0 -65
  91. package/distTs/src/output/noninteractive/config/tunnels.js +0 -18
  92. package/distTs/src/output/noninteractive/tunnel.js +0 -59
  93. package/distTs/src/output.js +0 -143
  94. package/distTs/src/server/cert.js +0 -52
  95. package/distTs/src/server/http1.js +0 -75
  96. package/distTs/src/server/http2.js +0 -78
  97. package/distTs/src/server/sftp.js +0 -497
  98. package/distTs/src/server/ssh.js +0 -446
  99. package/distTs/src/server/tls.js +0 -41
  100. package/distTs/src/ssh/client.js +0 -197
  101. package/distTs/src/texts.js +0 -421
  102. package/distTs/src/tunnel/agent.js +0 -103
  103. package/distTs/src/tunnel/api/agent.js +0 -100
  104. package/distTs/src/tunnel/api/buddy.js +0 -141
  105. package/distTs/src/tunnel/cfg.js +0 -243
  106. package/distTs/src/tunnel/compression.js +0 -44
  107. package/distTs/src/tunnel/dns.js +0 -53
  108. package/distTs/src/tunnel/html/503.html +0 -338
  109. package/distTs/src/tunnel/html.js +0 -33
  110. package/distTs/src/tunnel/http/log.js +0 -218
  111. package/distTs/src/tunnel/http/serve.js +0 -133
  112. package/distTs/src/tunnel/http/stream.js +0 -34
  113. package/distTs/src/tunnel/http.js +0 -508
  114. package/distTs/src/tunnel/identification.js +0 -103
  115. package/distTs/src/tunnel/latency.js +0 -83
  116. package/distTs/src/tunnel/output/interactive/tunnel.js +0 -867
  117. package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +0 -45
  118. package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +0 -67
  119. package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +0 -20
  120. package/distTs/src/tunnel/output/noninteractive/tunnel.js +0 -61
  121. package/distTs/src/tunnel/server/cert.js +0 -54
  122. package/distTs/src/tunnel/server/http1.js +0 -80
  123. package/distTs/src/tunnel/server/http2.js +0 -84
  124. package/distTs/src/tunnel/server/sftp.js +0 -514
  125. package/distTs/src/tunnel/server/ssh.js +0 -464
  126. package/distTs/src/tunnel/server/tls.js +0 -47
  127. package/distTs/src/tunnel/ssh/client.js +0 -211
  128. package/distTs/src/tunnel/tcp.js +0 -113
  129. package/distTs/src/tunnel/tunnel.js +0 -1010
  130. package/distTs/src/tunnel.js +0 -656
  131. package/distTs/src/types/ciInfo.js +0 -10
  132. package/distTs/src/types/options.js +0 -2
  133. package/distTs/src/types/plugin.js +0 -2
  134. package/distTs/src/types/queue.js +0 -2
  135. package/distTs/src/types/requests.js +0 -2
  136. package/distTs/src/types/resources.js +0 -2
  137. package/distTs/src/types/schemas.js +0 -54
  138. package/distTs/src/types/scrape.js +0 -2
  139. package/distTs/src/types/snapshots.js +0 -2
  140. package/distTs/src/types/storybook.js +0 -2
  141. package/distTs/src/types/tunnel.js +0 -141
  142. package/distTs/src/unitTest/ci.js +0 -108
  143. package/distTs/src/unitTest/requests.js +0 -72
  144. package/distTs/src/utils.js +0 -378
  145. package/distTs/src/visualTest/browser.js +0 -39
  146. package/distTs/src/visualTest/ci.js +0 -241
  147. package/distTs/src/visualTest/context.js +0 -52
  148. package/distTs/src/visualTest/exec.js +0 -51
  149. package/distTs/src/visualTest/linkUtils.js +0 -21
  150. package/distTs/src/visualTest/queue.js +0 -43
  151. package/distTs/src/visualTest/requests.js +0 -365
  152. package/distTs/src/visualTest/resources.js +0 -259
  153. package/distTs/src/visualTest/server.js +0 -109
  154. package/distTs/src/visualTest/snapshots.js +0 -129
  155. package/distTs/src/visualTest/utils/parseDom.js +0 -238
  156. package/distTs/src/visualTest/validation.js +0 -18
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.12.8-beta",
4
+ "version": "1.12.8-dev-pipeline-run",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.12.8-beta",
4
+ "version": "1.12.8-dev-pipeline-run",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "scripts": {
package/distTs/bin/cli.js DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- console.log = () => { }; // fix for termkit
5
- require("../src/index");
@@ -1,328 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const events_1 = __importDefault(require("events"));
7
- const logger_1 = __importDefault(require("../logger"));
8
- const texts_1 = require("../texts");
9
- const utils_1 = require("../utils");
10
- const tunnel_1 = __importDefault(require("../tunnel/tunnel"));
11
- const output_1 = __importDefault(require("../output"));
12
- const client_1 = __importDefault(require("./socket/client"));
13
- const tunnel_2 = require("../types/tunnel");
14
- class Agent extends events_1.default {
15
- id;
16
- host;
17
- token;
18
- service;
19
- target;
20
- disabled;
21
- tunnels;
22
- tunnelsUpdating;
23
- started;
24
- api;
25
- socket;
26
- manager;
27
- onRefresh;
28
- constructor(id, host, token, service, target, api, disabled) {
29
- super();
30
- this.id = id;
31
- this.host = host;
32
- this.token = token;
33
- this.service = service;
34
- this.target = target;
35
- this.disabled = disabled;
36
- this.tunnels = [];
37
- this.tunnelsUpdating = false;
38
- this.started = false;
39
- this.api = api;
40
- this.manager = null;
41
- this.onRefresh = null;
42
- this.socket = new client_1.default(host, id, token);
43
- this.socket.on(tunnel_2.TUNNEL_SOCKET_EVENT.FETCH_SUCCESS, (data) => this._onSocketFetch(data));
44
- this.socket.on(tunnel_2.TUNNEL_SOCKET_EVENT.FETCH_FAILED, (err) => this._onSocketFetchFailed(err));
45
- this.socket.on(tunnel_2.TUNNEL_SOCKET_EVENT.CONNECTED, () => this._onSocketConnected());
46
- this.socket.on(tunnel_2.TUNNEL_SOCKET_EVENT.DISCONNECTED, () => this._onSocketDisconnected());
47
- this.socket.on(tunnel_2.TUNNEL_SOCKET_EVENT.TUNNEL, (tunnel, action) => this._onSocketTunnel(tunnel, action));
48
- this.socket.on(tunnel_2.TUNNEL_SOCKET_EVENT.AGENT, (agent, action) => this._onSocketAgent(agent, action));
49
- }
50
- destroy() {
51
- if (this.socket) {
52
- this.socket.removeAllListeners();
53
- this.socket.destroy();
54
- this.socket = null;
55
- }
56
- this.manager = null;
57
- this.onRefresh = null;
58
- this.api = null;
59
- // muszą byc manualnie wcześniej zniszczone to tylko czyści obiekt
60
- this.tunnels = [];
61
- }
62
- _onSocketTunnel(data, action) {
63
- if (action === 'DEL') {
64
- this.destroyTunnel(data.id);
65
- if (!this.service && this.tunnels.length <= 0)
66
- output_1.default.exitError(texts_1.ERR_TUNNEL_REMOVED);
67
- }
68
- else {
69
- logger_1.default.debug('Socket fetch tunnel after sync push');
70
- if (this.socket)
71
- this.socket.fetch(this.started, null, null, false, []);
72
- }
73
- }
74
- async _onSocketAgent(data, action) {
75
- if (action === 'DEL') {
76
- if (this.manager) {
77
- return this.manager.disableAgentAndExit(texts_1.ERR_AGENT_REMOVED);
78
- }
79
- output_1.default.exitError(texts_1.ERR_AGENT_REMOVED);
80
- }
81
- else {
82
- this.target = !!data.target;
83
- this.disabled = !!data.disabled;
84
- if (data.disabled === this.started) {
85
- await this.makeAction(data.disabled ? tunnel_2.TUNNEL_AGENT_ACTION.STOP : tunnel_2.TUNNEL_AGENT_ACTION.START);
86
- }
87
- else if (data.action) {
88
- try {
89
- await this.makeAction(data.action);
90
- }
91
- catch (err) {
92
- logger_1.default.error('Agent sync error');
93
- logger_1.default.error(err);
94
- }
95
- }
96
- }
97
- }
98
- _onSocketConnected() {
99
- if (this.onRefresh)
100
- this.onRefresh(true);
101
- }
102
- _onSocketDisconnected() {
103
- if (this.onRefresh)
104
- this.onRefresh(false);
105
- }
106
- async _onSocketFetch(data) {
107
- try {
108
- if (data.agent.action)
109
- await this.makeAction(data.agent.action);
110
- this.refreshTunnels(data.tunnels || []);
111
- }
112
- catch (err) {
113
- logger_1.default.error('Fetch error');
114
- logger_1.default.error(err);
115
- }
116
- }
117
- _onSocketFetchFailed(err) {
118
- if (err instanceof utils_1.ApiErrorAgentNotFound) {
119
- if (this.manager) {
120
- return this.manager.disableAgentAndExit(texts_1.ERR_AGENT_REMOVED);
121
- }
122
- output_1.default.exitError(texts_1.ERR_AGENT_REMOVED);
123
- }
124
- else {
125
- logger_1.default.error(texts_1.LOG_ERROR_WHILE_REFRESHING_AGENT);
126
- logger_1.default.error(err);
127
- }
128
- }
129
- startRefreshingConfiguration(onRefresh) {
130
- this.onRefresh = onRefresh;
131
- if (this.onRefresh && this.socket)
132
- this.onRefresh(this.socket.connected);
133
- this.refreshIn15();
134
- }
135
- async start() {
136
- this.started = true;
137
- this.tunnels.forEach((t) => {
138
- t.start();
139
- });
140
- if (this.socket)
141
- this.socket.fetch(this.started, '', null, true, this.getTunnelsUpdate());
142
- }
143
- async enable() {
144
- this.disabled = false;
145
- this.started = true;
146
- this.tunnels.forEach((t) => {
147
- t.start();
148
- });
149
- if (this.socket)
150
- this.socket.fetch(this.started, '', false, true, this.getTunnelsUpdate());
151
- }
152
- async stop(clearAction = true) {
153
- this.started = false;
154
- this.tunnels.forEach((t) => {
155
- t.stop();
156
- });
157
- if (!this.socket)
158
- return;
159
- this.socket.fetch(this.started, clearAction ? '' : null, null, false, this.getTunnelsUpdate());
160
- }
161
- async disable() {
162
- this.disabled = true;
163
- this.started = false;
164
- this.tunnels.forEach((t) => {
165
- t.stop();
166
- });
167
- if (this.socket)
168
- this.socket.fetch(this.started, '', true, false, this.getTunnelsUpdate());
169
- }
170
- async restart() {
171
- await this.stop(false);
172
- await (0, utils_1.sleep)(100);
173
- await this.start();
174
- }
175
- async delete() {
176
- try {
177
- if (this.api) {
178
- await this.api.unregister(this.id, this.host, this.token);
179
- }
180
- }
181
- catch {
182
- // do nothing
183
- }
184
- process.exit(0);
185
- }
186
- refreshIn15(fetch = true, counter = 1) {
187
- setTimeout(async () => {
188
- try {
189
- if (fetch || counter >= 3) {
190
- counter = 0;
191
- if (this.socket) {
192
- this.socket.fetch(this.started, null, null, false, this.getTunnelsUpdate());
193
- }
194
- }
195
- else {
196
- this.update();
197
- }
198
- }
199
- catch {
200
- // do nothing
201
- }
202
- this.refreshIn15(false, counter + 1);
203
- }, 15000);
204
- }
205
- httpRequest(tunnelId, logRequest) {
206
- if (this.socket)
207
- this.socket.request(tunnelId, logRequest);
208
- }
209
- update(force = false) {
210
- if (this.socket)
211
- this.socket.update(this.started, this.getTunnelsUpdate(), force);
212
- }
213
- async makeAction(action) {
214
- if (action === tunnel_2.TUNNEL_AGENT_ACTION.STOP) {
215
- if (this.manager) {
216
- return this.manager.agentStop();
217
- }
218
- return this.stop();
219
- }
220
- if (action === tunnel_2.TUNNEL_AGENT_ACTION.START) {
221
- if (this.manager) {
222
- return this.manager.agentStart();
223
- }
224
- return this.start();
225
- }
226
- if (action === tunnel_2.TUNNEL_AGENT_ACTION.RESTART) {
227
- if (this.manager) {
228
- return this.manager.agentRestart();
229
- }
230
- return this.restart();
231
- }
232
- if (action === tunnel_2.TUNNEL_AGENT_ACTION.DELETE) {
233
- if (this.manager) {
234
- return this.manager.disableAgentAndExit(texts_1.ERR_AGENT_REMOVED);
235
- }
236
- return this.delete();
237
- }
238
- }
239
- refreshTunnels(tunnels) {
240
- if (this.tunnelsUpdating)
241
- return;
242
- this.tunnelsUpdating = true;
243
- let hasTunnels = false;
244
- let haveTunnels = false;
245
- try {
246
- const tt = [...this.tunnels];
247
- hasTunnels = tt.length > 0;
248
- haveTunnels = tunnels.length > 0;
249
- if (hasTunnels) {
250
- tt.forEach((tunnel) => {
251
- if (!tunnels.find((t) => t.id === tunnel.id)) {
252
- this.destroyTunnel(tunnel.id);
253
- }
254
- });
255
- }
256
- if (haveTunnels) {
257
- tunnels.forEach((data) => {
258
- let sshHostKey;
259
- if (this.manager)
260
- sshHostKey = this.manager.sshHostKey;
261
- const tunnel = tt.find((tunnel) => data.id === tunnel.id);
262
- if (!tunnel) {
263
- this.addTunnel(new tunnel_1.default({
264
- ...data,
265
- sshHostKey,
266
- agent: {
267
- id: this.id,
268
- host: this.host,
269
- token: this.token,
270
- },
271
- }));
272
- }
273
- else if (tunnel.hasChanged(data)) {
274
- tunnel.recreate(data);
275
- }
276
- });
277
- }
278
- }
279
- catch {
280
- // do nothing
281
- }
282
- this.tunnelsUpdating = false;
283
- if (!this.service && hasTunnels && !haveTunnels) {
284
- output_1.default.exitError(texts_1.ERR_TUNNEL_REMOVED);
285
- }
286
- }
287
- getTunnelsUpdate() {
288
- const update = [];
289
- this.tunnels.forEach((t) => {
290
- update.push({
291
- id: t.id,
292
- active: t.status === tunnel_2.TUNNEL_STATUS.OPEN,
293
- regionLatency: t.regionLatency ? t.regionLatency.latency : -1,
294
- targetLatency: t.targetLatency ? t.targetLatency.latency : -1,
295
- totalConnections: t.totalConnections,
296
- currentConnections: Object.keys(t.connections || {}).length,
297
- httpIdentified: t.identify ? t.identify.type : '',
298
- });
299
- });
300
- return update;
301
- }
302
- addTunnel(tunnel) {
303
- this.tunnels.push(tunnel);
304
- if (this.started)
305
- tunnel.start();
306
- tunnel.on(tunnel_2.TUNNEL_EVENT.OPEN, () => this.update(true));
307
- tunnel.on(tunnel_2.TUNNEL_EVENT.CLOSED, () => this.update());
308
- tunnel.on(tunnel_2.TUNNEL_EVENT.TCP_OPEN, () => this.update());
309
- tunnel.on(tunnel_2.TUNNEL_EVENT.TCP_CLOSED, () => this.update());
310
- tunnel.on(tunnel_2.TUNNEL_EVENT.TLS_OPEN, () => this.update());
311
- tunnel.on(tunnel_2.TUNNEL_EVENT.TLS_CLOSED, () => this.update());
312
- tunnel.on(tunnel_2.TUNNEL_EVENT.HTTP_IDENTIFIED, () => this.update());
313
- tunnel.on(tunnel_2.TUNNEL_EVENT.HTTP_OPEN, () => this.update());
314
- tunnel.on(tunnel_2.TUNNEL_EVENT.HTTP_CLOSED, () => this.update());
315
- tunnel.on(tunnel_2.TUNNEL_EVENT.STOPPED, () => this.update());
316
- tunnel.on(tunnel_2.TUNNEL_EVENT.HTTP_REQUEST, (t, logRequest) => this.httpRequest(t.id, logRequest));
317
- }
318
- destroyTunnel(id) {
319
- const tunnel = this.tunnels.find((t) => t.id === id);
320
- if (!tunnel)
321
- return null;
322
- this.tunnels = this.tunnels.filter((t) => t.id !== tunnel.id);
323
- tunnel.stop();
324
- tunnel.removeAllListeners();
325
- return tunnel;
326
- }
327
- }
328
- exports.default = Agent;
@@ -1,124 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const system_1 = __importDefault(require("./system"));
7
- const path_1 = __importDefault(require("path"));
8
- const child_process_1 = require("child_process");
9
- const logger_1 = __importDefault(require("../logger"));
10
- const texts_1 = require("../texts");
11
- class AgentLinux extends system_1.default {
12
- hasAdminRights() {
13
- return new Promise((resolve) => {
14
- if (process.getuid) {
15
- resolve(process.getuid() === 0);
16
- }
17
- else {
18
- resolve(false);
19
- }
20
- });
21
- }
22
- isSupported() {
23
- return new Promise((resolve) => {
24
- this.systemctl('--version')
25
- .then(() => {
26
- resolve(['arm64', 'x64'].includes(process.arch));
27
- })
28
- .catch(() => {
29
- resolve(false);
30
- });
31
- });
32
- }
33
- isEnabled() {
34
- return new Promise((resolve) => {
35
- this.systemctl('is-enabled bdy')
36
- .then(() => {
37
- resolve(true);
38
- })
39
- .catch(() => {
40
- resolve(false);
41
- });
42
- });
43
- }
44
- getBinaryArchive() {
45
- return `linux-${process.arch}.tar.gz`;
46
- }
47
- getSystemConfigDir() {
48
- return '/etc/bdy';
49
- }
50
- getSystemConfigPath() {
51
- return path_1.default.join(this.getSystemConfigDir(), 'agent.json');
52
- }
53
- getServicePath() {
54
- return '/etc/systemd/system/bdy.service';
55
- }
56
- getServiceConfig(id, host, token, port, start, user, debug) {
57
- const cli = this.getSystemBinaryPath();
58
- return `[Unit]
59
- Description=Buddy Tunnel Agent
60
- After=network.target
61
-
62
- [Service]
63
- Environment="DEBUG=${debug ? 1 : 0}"
64
- User=${user || 'root'}
65
- WorkingDirectory=/
66
- ExecStart=${cli} agent run --id="${id}" --host="${host}" --token="${token}" --port=${port} --start=${!!start}
67
- Restart=always
68
- RestartSec=3
69
-
70
- [Install]
71
- WantedBy=multi-user.target`;
72
- }
73
- async enable(id, host, token, port, start, user, pass, debug) {
74
- try {
75
- logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
76
- await this.ensureSystemConfigDir();
77
- logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
78
- await this.downloadBinaryArchive();
79
- logger_1.default.info(texts_1.LOG_AGENT_EXTRACTING_ARCHIVE);
80
- await this.extractBinaryArchive();
81
- logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_SERVICE_CONFIG);
82
- await this.saveFile(this.getServicePath(), this.getServiceConfig(id, host, token, port, start, user, debug));
83
- logger_1.default.info(texts_1.LOG_AGENT_ENABLING_SYSTEM);
84
- await this.systemctl('enable --now bdy');
85
- logger_1.default.info(texts_1.LOG_AGENT_ENABLED);
86
- }
87
- catch (err) {
88
- logger_1.default.error(err);
89
- throw err;
90
- }
91
- }
92
- async update() {
93
- try {
94
- logger_1.default.info(texts_1.LOG_AGENT_STOPPING_SYSTEM);
95
- await this.systemctl('stop bdy');
96
- logger_1.default.info(texts_1.LOG_AGENT_SYSTEM_DIR);
97
- await this.ensureSystemConfigDir();
98
- logger_1.default.info(texts_1.LOG_AGENT_DOWNLOADING_ARCHIVE);
99
- await this.downloadBinaryArchive();
100
- logger_1.default.info(texts_1.LOG_AGENT_EXTRACTING_ARCHIVE);
101
- await this.extractBinaryArchive();
102
- logger_1.default.info(texts_1.LOG_AGENT_STARTING_SYSTEM);
103
- await this.systemctl('start bdy');
104
- }
105
- catch (err) {
106
- logger_1.default.error(err);
107
- throw err;
108
- }
109
- }
110
- async disable() {
111
- return this.systemctl('disable --now bdy');
112
- }
113
- systemctl(cmd) {
114
- return new Promise((resolve, reject) => {
115
- (0, child_process_1.exec)(`systemctl ${cmd}`, (err) => {
116
- if (!err)
117
- resolve();
118
- else
119
- reject(err);
120
- });
121
- });
122
- }
123
- }
124
- exports.default = AgentLinux;