@milaboratories/pl-deployments 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,45 +1,45 @@
1
- var G = Object.defineProperty;
2
- var Z = (s, r, t) => r in s ? G(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t;
3
- var w = (s, r, t) => Z(s, typeof r != "symbol" ? r + "" : r, t);
1
+ var q = Object.defineProperty;
2
+ var Z = (s, t, r) => t in s ? q(s, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[t] = r;
3
+ var w = (s, t, r) => Z(s, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { spawn as V } from "node:child_process";
5
- import { sleep as C, fileExists as m, assertNever as T, notEmpty as f, RetryablePromise as Y } from "@milaboratories/ts-helpers";
6
- import E from "node:fs";
7
- import p, { readFile as Q } from "node:fs/promises";
8
- import u from "upath";
5
+ import { sleep as F, fileExists as m, assertNever as _, notEmpty as p, RetryablePromise as Y } from "@milaboratories/ts-helpers";
6
+ import A from "node:fs";
7
+ import f, { readFile as Q } from "node:fs/promises";
8
+ import d from "upath";
9
9
  import { request as X } from "undici";
10
- import { Readable as tt, Writable as rt } from "node:stream";
11
- import { text as et } from "node:stream/consumers";
12
- import * as it from "tar";
13
- import ot from "decompress";
14
- import k from "node:os";
15
- import st, { Client as S } from "ssh2";
16
- import B from "node:net";
17
- import nt from "node:dns";
18
- import { randomBytes as F } from "node:crypto";
19
- import { generateSshPlConfigs as at, getFreePort as y } from "@milaboratories/pl-config";
20
- function ct(s, r) {
10
+ import { Readable as rr, Writable as tr } from "node:stream";
11
+ import { text as er } from "node:stream/consumers";
12
+ import * as ir from "tar";
13
+ import or from "decompress";
14
+ import C from "node:os";
15
+ import sr, { Client as E } from "ssh2";
16
+ import I from "node:net";
17
+ import nr from "node:dns";
18
+ import { randomBytes as D } from "node:crypto";
19
+ import { generateSshPlConfigs as ar, getFreePort as y } from "@milaboratories/pl-config";
20
+ function cr(s, t) {
21
21
  return s.info(`Running:
22
- cmd: ${JSON.stringify([r.cmd, ...r.args])}
23
- wd: ${r.opts.cwd}`), s.info(" spawning child process"), V(r.cmd, r.args, r.opts);
22
+ cmd: ${JSON.stringify([t.cmd, ...t.args])}
23
+ wd: ${t.opts.cwd}`), s.info(" spawning child process"), V(t.cmd, t.args, t.opts);
24
24
  }
25
- async function D(s) {
25
+ async function b(s) {
26
26
  try {
27
27
  return process.kill(s, 0), !0;
28
28
  } catch {
29
29
  return !1;
30
30
  }
31
31
  }
32
- function _(s) {
32
+ function j(s) {
33
33
  return process.kill(s, "SIGINT");
34
34
  }
35
- async function j(s, r) {
35
+ async function H(s, t) {
36
36
  let e = 0;
37
- for (; await D(s); )
38
- if (await C(100), e += 100, e > r)
39
- throw new Error(`The process did not stopped after ${r} ms.`);
37
+ for (; await b(s); )
38
+ if (await F(100), e += 100, e > t)
39
+ throw new Error(`The process did not stopped after ${t} ms.`);
40
40
  }
41
- const lt = ["linux", "macos", "windows"];
42
- function I(s) {
41
+ const lr = ["linux", "macos", "windows"];
42
+ function x(s) {
43
43
  switch (s.toLowerCase()) {
44
44
  case "darwin":
45
45
  return "macos";
@@ -49,11 +49,11 @@ function I(s) {
49
49
  return "windows";
50
50
  default:
51
51
  throw new Error(
52
- `operating system '${s}' is not currently supported by Platforma ecosystem. The list of OSes supported: ` + JSON.stringify(lt)
52
+ `operating system '${s}' is not currently supported by Platforma ecosystem. The list of OSes supported: ` + JSON.stringify(lr)
53
53
  );
54
54
  }
55
55
  }
56
- const ht = ["amd64", "arm64"];
56
+ const hr = ["amd64", "arm64"];
57
57
  function P(s) {
58
58
  switch (s) {
59
59
  case "aarch64":
@@ -65,177 +65,180 @@ function P(s) {
65
65
  return "amd64";
66
66
  default:
67
67
  throw new Error(
68
- `processor architecture '${s}' is not currently supported by Platforma ecosystem. The list of architectures supported: ` + JSON.stringify(ht)
68
+ `processor architecture '${s}' is not currently supported by Platforma ecosystem. The list of architectures supported: ` + JSON.stringify(hr)
69
69
  );
70
70
  }
71
71
  }
72
- async function ut(s, r, t, e, i, o) {
73
- const n = wt(t, e, r, P(i), I(o)), { archiveUrl: c, archivePath: a } = n;
74
- return await H(s, c, a), n;
72
+ const dr = "https://cdn.platforma.bio/software", ur = "https://cdn-ga.pl-open.science/software";
73
+ async function wr(s, t, r, e, i, o) {
74
+ const n = M(r, e, t, P(i), x(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l } = n;
75
+ try {
76
+ await v(s, c, l), n.wasDownloadedFrom = c;
77
+ } catch {
78
+ await v(s, a, l), n.wasDownloadedFrom = a;
79
+ }
80
+ return n;
75
81
  }
76
- async function dt(s, r, t, e, i) {
77
- const o = pt(t, r, P(e), I(i)), { archiveUrl: n, archivePath: c, archiveType: a, targetFolder: l, binaryPath: h } = o;
78
- return await H(s, n, c), await mt(s, c, a, l), o;
82
+ async function fr(s, t, r, e, i, o) {
83
+ const n = M(r, e, t, P(i), x(o)), { archiveUrl: c, alternativeArchiveGAUrl: a, archivePath: l, archiveType: h, targetFolder: u, baseName: g } = n;
84
+ try {
85
+ await v(s, c, l), n.wasDownloadedFrom = c;
86
+ } catch {
87
+ await v(s, a, l), n.wasDownloadedFrom = a;
88
+ }
89
+ return await mr(s, l, h, u), n;
79
90
  }
80
- function wt(s, r, t, e, i) {
81
- const o = `${r}-${e}`, n = M[i], c = `${o}.${n}`, a = `https://cdn.platforma.bio/software/${s}/${i}/${c}`, l = u.join(t, c), h = u.join(t, o);
91
+ function M(s, t, r, e, i) {
92
+ const o = `${t}-${e}`, n = gr[i], c = `${o}.${n}`, a = `${dr}/${s}/${i}/${c}`, l = `${ur}/${s}/${i}/${c}`, h = d.join(r, c), u = d.join(r, o);
82
93
  return {
83
94
  archiveUrl: a,
84
- archivePath: l,
95
+ alternativeArchiveGAUrl: l,
96
+ archivePath: h,
85
97
  archiveType: n,
86
- targetFolder: h,
98
+ targetFolder: u,
87
99
  baseName: o
88
100
  };
89
101
  }
90
- function pt(s, r, t, e) {
91
- const i = `pl-${s}-${t}`, o = M[e], n = `${i}.${o}`, c = `https://cdn.platforma.bio/software/pl/${e}/${n}`, a = u.join(r, n), l = u.join(r, i), h = u.join(i, "binaries", gt[e]);
92
- return {
93
- archiveUrl: c,
94
- archivePath: a,
95
- archiveType: o,
96
- targetFolder: l,
97
- binaryPath: h,
98
- baseName: i
99
- };
100
- }
101
- async function H(s, r, t) {
102
+ async function v(s, t, r) {
102
103
  const e = {};
103
- e.dstArchive = t;
104
+ e.dstArchive = r;
104
105
  try {
105
- if (e.fileExisted = await m(t), e.fileExisted)
106
- return s.info(`Platforma Backend archive download skipped: '${t}' already exists`), e;
107
- await p.mkdir(u.dirname(t), { recursive: !0 }), e.dirnameCreated = !0, s.info(`Downloading archive:
108
- URL: ${r}
109
- Save to: ${t}`);
110
- const { body: i, statusCode: o } = await X(r);
106
+ if (e.fileExisted = await m(r), e.fileExisted)
107
+ return s.info(`Platforma Backend archive download skipped: '${r}' already exists`), e;
108
+ await f.mkdir(d.dirname(r), { recursive: !0 }), e.dirnameCreated = !0, s.info(`Downloading archive:
109
+ URL: ${t}
110
+ Save to: ${r}`);
111
+ const { body: i, statusCode: o } = await X(t);
111
112
  if (e.statusCode = o, o != 200) {
112
- const n = await et(i);
113
+ const n = await er(i);
113
114
  throw e.errorMsg = `failed to download archive: ${o}, response: ${n.slice(0, 1e3)}`, s.error(e.errorMsg), new Error(e.errorMsg);
114
115
  }
115
- return e.tmpPath = t + ".tmp", await tt.toWeb(i).pipeTo(rt.toWeb(E.createWriteStream(e.tmpPath))), e.wroteTmp = !0, e.tmpExisted = await m(e.tmpPath), await p.rename(e.tmpPath, t), e.renamed = !0, e.newExisted = await m(t), e;
116
+ return e.tmpPath = r + ".tmp", await rr.toWeb(i).pipeTo(tr.toWeb(A.createWriteStream(e.tmpPath))), e.wroteTmp = !0, e.tmpExisted = await m(e.tmpPath), await f.rename(e.tmpPath, r), e.renamed = !0, e.newExisted = await m(r), e;
116
117
  } catch (i) {
117
118
  const o = `downloadArchive: error ${JSON.stringify(i)} occurred, state: ${JSON.stringify(e)}`;
118
119
  throw s.error(o), new Error(o);
119
120
  }
120
121
  }
121
- const ft = ".ok";
122
- async function mt(s, r, t, e) {
123
- if (s.info("extracting archive..."), s.info(` archive path: '${r}'`), s.info(` target dir: '${e}'`), !await m(r)) {
124
- const o = `Platforma Backend binary archive not found at '${r}'`;
122
+ const pr = ".ok";
123
+ async function mr(s, t, r, e) {
124
+ if (s.info("extracting archive..."), s.info(` archive path: '${t}'`), s.info(` target dir: '${e}'`), !await m(t)) {
125
+ const o = `Platforma Backend binary archive not found at '${t}'`;
125
126
  throw s.error(o), new Error(o);
126
127
  }
127
- const i = u.join(e, ft);
128
+ const i = d.join(e, pr);
128
129
  if (await m(i)) {
129
130
  s.info(`Platforma Backend binaries unpack skipped: '${e}' exists`);
130
131
  return;
131
132
  }
132
- switch (await m(e) && (s.info(`Removing previous incompletely unpacked folder: '${e}'`), await p.rm(e, { recursive: !0 })), s.info(` creating target dir '${e}'`), await p.mkdir(e, { recursive: !0 }), s.info(
133
+ switch (await m(e) && (s.info(`Removing previous incompletely unpacked folder: '${e}'`), await f.rm(e, { recursive: !0 })), s.info(` creating target dir '${e}'`), await f.mkdir(e, { recursive: !0 }), s.info(
133
134
  `Unpacking Platforma Backend archive:
134
- Archive: ${r}
135
+ Archive: ${t}
135
136
  Target dir: ${e}`
136
- ), t) {
137
+ ), r) {
137
138
  case "tgz":
138
- await it.x({
139
- file: r,
139
+ await ir.x({
140
+ file: t,
140
141
  cwd: e,
141
142
  gzip: !0
142
143
  });
143
144
  break;
144
145
  case "zip":
145
- await ot(r, e);
146
+ await or(t, e);
146
147
  break;
147
148
  default:
148
- T(t);
149
+ _(r);
149
150
  }
150
- await p.writeFile(i, "ok"), s.info(" ... unpack done.");
151
+ await f.writeFile(i, "ok"), s.info(" ... unpack done.");
151
152
  }
152
- const M = {
153
+ const gr = {
153
154
  linux: "tgz",
154
155
  macos: "tgz",
155
156
  windows: "zip"
156
- }, gt = {
157
- linux: "platforma",
158
- macos: "platforma",
159
- windows: "platforma.exe"
160
157
  };
161
- function b() {
158
+ function O() {
162
159
  return "1.18.3";
163
160
  }
164
- function yt() {
165
- return { type: "Download", version: b() };
161
+ function yr() {
162
+ return { type: "Download", version: O() };
166
163
  }
167
- async function $t(s, r, t) {
168
- switch (t.type) {
164
+ async function $r(s, t, r) {
165
+ switch (r.type) {
169
166
  case "Download":
170
- return (await dt(s, r, t.version, k.arch(), k.platform())).binaryPath;
167
+ const e = await fr(s, t, "pl", `pl-${r.version}`, C.arch(), C.platform());
168
+ return d.join(e.baseName, "binaries", Pr[x(C.platform())]);
171
169
  case "Local":
172
- return t.path;
170
+ return r.path;
173
171
  default:
174
- T(t);
172
+ _(r);
175
173
  }
176
174
  }
175
+ const Pr = {
176
+ linux: "platforma",
177
+ macos: "platforma",
178
+ windows: "platforma.exe"
179
+ };
177
180
  function J(s) {
178
- return u.join(s, "pl_pid");
181
+ return d.join(s, "pl_pid");
179
182
  }
180
- async function Pt(s) {
183
+ async function vr(s) {
181
184
  if (!await m(s))
182
185
  return;
183
- const r = await p.readFile(s);
184
- return Number(r.toString());
186
+ const t = await f.readFile(s);
187
+ return Number(t.toString());
185
188
  }
186
- async function vt(s, r) {
187
- await p.writeFile(s, JSON.stringify(r));
189
+ async function Sr(s, t) {
190
+ await f.writeFile(s, JSON.stringify(t));
188
191
  }
189
- function St() {
192
+ function Cr() {
190
193
  return {};
191
194
  }
192
- function Ct(s, r, t) {
193
- return s[r] = t, t;
195
+ function Er(s, t, r) {
196
+ return s[t] = r, r;
194
197
  }
195
- async function A(s, r) {
196
- const t = St();
198
+ async function k(s, t) {
199
+ const r = Cr();
197
200
  try {
198
- return await r((i, o) => Ct(t, i, o), t);
201
+ return await t((i, o) => Er(r, i, o), r);
199
202
  } catch (e) {
200
- throw s.error(`error ${e} while doing traced operation, state: ${JSON.stringify(t)}`), e;
203
+ throw s.error(`error ${e} while doing traced operation, state: ${JSON.stringify(r)}`), e;
201
204
  }
202
205
  }
203
- const Et = "config-local.yaml";
204
- class Ft {
205
- constructor(r, t, e, i, o, n, c, a) {
206
+ const Fr = "config-local.yaml";
207
+ class Ar {
208
+ constructor(t, r, e, i, o, n, c, a) {
206
209
  w(this, "instance");
207
210
  w(this, "pid");
208
211
  w(this, "nRuns", 0);
209
212
  w(this, "lastRunHistory", {});
210
213
  w(this, "wasStopped", !1);
211
- this.logger = r, this.workingDir = t, this.startOptions = e, this.initialStartHistory = i, this.onClose = o, this.onError = n, this.onCloseAndError = c, this.onCloseAndErrorNoStop = a;
214
+ this.logger = t, this.workingDir = r, this.startOptions = e, this.initialStartHistory = i, this.onClose = o, this.onError = n, this.onCloseAndError = c, this.onCloseAndErrorNoStop = a;
212
215
  }
213
216
  async start() {
214
- await A(this.logger, async (r, t) => {
217
+ await k(this.logger, async (t, r) => {
215
218
  this.wasStopped = !1;
216
- const e = ct(this.logger, this.startOptions);
219
+ const e = cr(this.logger, this.startOptions);
217
220
  e.on("error", (o) => {
218
221
  this.logger.error(
219
222
  `error '${o}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`
220
223
  ), this.onError !== void 0 && this.onError(this), this.onCloseAndError !== void 0 && this.onCloseAndError(this), this.onCloseAndErrorNoStop !== void 0 && !this.wasStopped && this.onCloseAndErrorNoStop(this);
221
224
  }), e.on("close", () => {
222
225
  this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`), this.onClose !== void 0 && this.onClose(this), this.onCloseAndError !== void 0 && this.onCloseAndError(this), this.onCloseAndErrorNoStop !== void 0 && !this.wasStopped && this.onCloseAndErrorNoStop(this);
223
- }), r("started", !0);
224
- const i = r("pidFile", J(this.workingDir));
225
- r("pid", f(e.pid)), r("pidWritten", await vt(i, f(e.pid))), this.nRuns++, this.instance = e, this.pid = e.pid, this.lastRunHistory = t;
226
+ }), t("started", !0);
227
+ const i = t("pidFile", J(this.workingDir));
228
+ t("pid", p(e.pid)), t("pidWritten", await Sr(i, p(e.pid))), this.nRuns++, this.instance = e, this.pid = e.pid, this.lastRunHistory = r;
226
229
  });
227
230
  }
228
231
  stop() {
229
- this.wasStopped = !0, _(f(this.pid));
232
+ this.wasStopped = !0, j(p(this.pid));
230
233
  }
231
234
  async waitStopped() {
232
- await j(f(this.pid), 15e3);
235
+ await H(p(this.pid), 15e3);
233
236
  }
234
237
  stopped() {
235
238
  return this.wasStopped;
236
239
  }
237
240
  async isAlive() {
238
- return await D(f(this.pid));
241
+ return await b(p(this.pid));
239
242
  }
240
243
  debugInfo() {
241
244
  return {
@@ -248,21 +251,21 @@ class Ft {
248
251
  };
249
252
  }
250
253
  }
251
- async function ir(s, r) {
252
- const t = {
253
- plBinary: yt(),
254
+ async function st(s, t) {
255
+ const r = {
256
+ plBinary: yr(),
254
257
  spawnOptions: {},
255
258
  closeOld: !0,
256
- ...r
259
+ ...t
257
260
  };
258
- return await A(s, async (e, i) => {
259
- e("startOptions", { ...t, config: "too wordy" });
260
- const o = u.resolve(t.workingDir);
261
- t.closeOld && e("closeOld", await Dt(s, o));
262
- const n = u.join(o, Et);
263
- s.info(`writing configuration '${n}'...`), await p.writeFile(n, t.config);
264
- const c = await $t(s, u.join(o, "binaries"), t.plBinary), l = {
265
- cmd: e("binaryPath", u.join("binaries", c)),
261
+ return await k(s, async (e, i) => {
262
+ e("startOptions", { ...r, config: "too wordy" });
263
+ const o = d.resolve(r.workingDir);
264
+ r.closeOld && e("closeOld", await Dr(s, o));
265
+ const n = d.join(o, Fr);
266
+ s.info(`writing configuration '${n}'...`), await f.writeFile(n, r.config);
267
+ const c = d.join(o, "binaries"), a = await $r(s, c, r.plBinary), h = {
268
+ cmd: e("binaryPath", d.join("binaries", a)),
266
269
  args: ["-config", n],
267
270
  opts: {
268
271
  env: { ...process.env },
@@ -270,84 +273,88 @@ async function ir(s, r) {
270
273
  stdio: ["pipe", "ignore", "inherit"],
271
274
  windowsHide: !0,
272
275
  // hide a terminal on Windows
273
- ...t.spawnOptions
276
+ ...r.spawnOptions
274
277
  }
275
278
  };
276
279
  e("processOpts", {
277
- cmd: l.cmd,
278
- args: l.args,
279
- cwd: l.opts.cwd
280
+ cmd: h.cmd,
281
+ args: h.args,
282
+ cwd: h.opts.cwd
280
283
  });
281
- const h = new Ft(
284
+ const u = new Ar(
282
285
  s,
283
- t.workingDir,
284
- l,
286
+ r.workingDir,
287
+ h,
285
288
  i,
286
- t.onClose,
287
- t.onError,
288
- t.onCloseAndError,
289
- t.onCloseAndErrorNoStop
289
+ r.onClose,
290
+ r.onError,
291
+ r.onCloseAndError,
292
+ r.onCloseAndErrorNoStop
290
293
  );
291
- return await h.start(), h;
294
+ return await u.start(), u;
292
295
  });
293
296
  }
294
- async function Dt(s, r) {
295
- return await A(s, async (t, e) => {
296
- const i = t("pidFilePath", J(r)), o = t("pid", await Pt(i)), n = t("wasAlive", await D(o));
297
- return o !== void 0 && n && (t("stopped", _(o)), t("waitStopped", await j(o, 1e4))), e;
297
+ async function Dr(s, t) {
298
+ return await k(s, async (r, e) => {
299
+ const i = r("pidFilePath", J(t)), o = r("pid", await vr(i)), n = r("wasAlive", await b(o));
300
+ return o !== void 0 && n && (r("stopped", j(o)), r("waitStopped", await H(o, 1e4))), e;
298
301
  });
299
302
  }
300
- const bt = {
303
+ const br = {
301
304
  keepaliveInterval: 6e4,
302
305
  keepaliveCountMax: 10
303
306
  };
304
- class x {
305
- constructor(r, t) {
307
+ class R {
308
+ constructor(t, r) {
306
309
  w(this, "config");
307
310
  w(this, "homeDir");
308
- this.logger = r, this.client = t;
311
+ w(this, "forwardedServers", []);
312
+ this.logger = t, this.client = r;
309
313
  }
310
314
  /**
311
315
  * Initializes the SshClient and establishes a connection using the provided configuration.
312
316
  * @param config - The connection configuration object for the SSH client.
313
317
  * @returns A new instance of SshClient with an active connection.
314
318
  */
315
- static async init(r, t) {
319
+ static async init(t, r) {
316
320
  const e = {
317
- ...bt,
318
- ...t
319
- }, i = new x(r, new S());
321
+ ...br,
322
+ ...r
323
+ }, i = new R(t, new E());
320
324
  return await i.connect(e), i;
321
325
  }
326
+ getForwardedServers() {
327
+ return this.forwardedServers;
328
+ }
322
329
  getFullHostName() {
323
- var r, t;
324
- return `${(r = this.config) == null ? void 0 : r.host}:${(t = this.config) == null ? void 0 : t.port}`;
330
+ var t, r;
331
+ return `${(t = this.config) == null ? void 0 : t.host}:${(r = this.config) == null ? void 0 : r.port}`;
325
332
  }
326
333
  getUserName() {
327
- var r;
328
- return (r = this.config) == null ? void 0 : r.username;
334
+ var t;
335
+ return (t = this.config) == null ? void 0 : t.username;
329
336
  }
330
337
  /**
331
338
  * Connects to the SSH server using the specified configuration.
332
339
  * @param config - The connection configuration object for the SSH client.
333
340
  * @returns A promise that resolves when the connection is established or rejects on error.
334
341
  */
335
- async connect(r) {
336
- return this.config = r, await At(this.client, r);
342
+ async connect(t) {
343
+ return this.config = t, await xr(this.client, t);
337
344
  }
338
345
  /**
339
346
  * Executes a command on the SSH server.
340
347
  * @param command - The command to execute on the remote server.
341
348
  * @returns A promise resolving with the command's stdout and stderr outputs.
342
349
  */
343
- async exec(r) {
344
- return new Promise((t, e) => {
345
- this.client.exec(r, (i, o) => {
350
+ async exec(t) {
351
+ return new Promise((r, e) => {
352
+ this.client.exec(t, (i, o) => {
346
353
  if (i)
347
- return e(`ssh.exec: ${r}, error occurred: ${i}`);
354
+ return e(`ssh.exec: ${t}, error occurred: ${i}`);
348
355
  let n = "", c = "";
349
356
  o.on("close", (a) => {
350
- a === 0 ? t({ stdout: n, stderr: c }) : e(new Error(`Command ${r} exited with code ${a}`));
357
+ a === 0 ? r({ stdout: n, stderr: c }) : e(new Error(`Command ${t} exited with code ${a}`));
351
358
  }).on("data", (a) => {
352
359
  n += a.toString();
353
360
  }).stderr.on("data", (a) => {
@@ -362,10 +369,10 @@ class x {
362
369
  * @param port - The port number to connect to on the server.
363
370
  * @returns 'publickey' | 'password'[] A promise resolving with a list of supported authentication methods.
364
371
  */
365
- static async getAuthTypes(r, t) {
372
+ static async getAuthTypes(t, r) {
366
373
  return new Promise((e) => {
367
374
  let i = "";
368
- const o = new S();
375
+ const o = new E();
369
376
  o.on("ready", () => {
370
377
  o.end();
371
378
  const n = this.extractAuthMethods(i);
@@ -373,8 +380,8 @@ class x {
373
380
  }), o.on("error", () => {
374
381
  o.end(), e(["publickey", "password"]);
375
382
  }), o.connect({
376
- host: r,
377
- port: t,
383
+ host: t,
384
+ port: r,
378
385
  username: (/* @__PURE__ */ new Date()).getTime().toString(),
379
386
  debug: (n) => {
380
387
  i += `${n}
@@ -388,9 +395,9 @@ class x {
388
395
  * @param log - The debug log output containing authentication information.
389
396
  * @returns An array of extracted authentication methods.
390
397
  */
391
- static extractAuthMethods(r) {
392
- const t = r.match(/Inbound: Received USERAUTH_FAILURE \((.+)\)/);
393
- return t && t[1] ? t[1].split(",").map((e) => e.trim()) : [];
398
+ static extractAuthMethods(t) {
399
+ const r = t.match(/Inbound: Received USERAUTH_FAILURE \((.+)\)/);
400
+ return r && r[1] ? r[1].split(",").map((e) => e.trim()) : [];
394
401
  }
395
402
  /**
396
403
  * Sets up port forwarding between a remote port on the SSH server and a local port.
@@ -399,22 +406,22 @@ class x {
399
406
  * @param config - Optional connection configuration for the SSH client.
400
407
  * @returns { server: net.Server } A promise resolving with the created server instance.
401
408
  */
402
- async forwardPort(r, t) {
403
- const e = `ssh.forward:${r.localPort}:${r.remotePort}.id_${F(1).toString("hex")}`;
404
- t = t ?? this.config;
409
+ async forwardPort(t, r) {
410
+ const e = `ssh.forward:${t.localPort}:${t.remotePort}.id_${D(1).toString("hex")}`;
411
+ r = r ?? this.config;
405
412
  const i = new Y((o) => new Promise((n, c) => {
406
- const a = new S();
413
+ const a = new E();
407
414
  a.on("ready", () => {
408
415
  this.logger.info(`${e}.client.ready`), n(a);
409
416
  }), a.on("error", (l) => {
410
417
  this.logger.info(`${e}.client.error: ${l}`), o.reset(), c(l);
411
418
  }), a.on("close", () => {
412
419
  this.logger.info(`${e}.client.closed`), o.reset();
413
- }), a.connect(t);
420
+ }), a.connect(r);
414
421
  }));
415
422
  return await i.ensure(), new Promise((o, n) => {
416
- const c = B.createServer({ pauseOnConnect: !0 }, async (a) => {
417
- const l = `${e}.sock_${F(1).toString("hex")}`;
423
+ const c = I.createServer({ pauseOnConnect: !0 }, async (a) => {
424
+ const l = `${e}.sock_${D(1).toString("hex")}`;
418
425
  let h;
419
426
  try {
420
427
  h = await i.ensure();
@@ -422,39 +429,49 @@ class x {
422
429
  this.logger.info(`${l}.persistentClient.catch: ${g}`), a.end();
423
430
  return;
424
431
  }
425
- let d;
432
+ let u;
426
433
  try {
427
- d = await xt(this.logger, h, "127.0.0.1", 0, "127.0.0.1", r.remotePort);
434
+ u = await Or(this.logger, h, "127.0.0.1", 0, "127.0.0.1", t.remotePort);
428
435
  } catch (g) {
429
436
  this.logger.error(`${l}.forwardOut.err: ${g}`), a.end();
430
437
  return;
431
438
  }
432
- a.pipe(d), d.pipe(a), a.resume(), d.on("error", (g) => {
433
- this.logger.error(`${l}.stream.error: ${g}`), a.end(), d.end();
434
- }), d.on("close", () => {
435
- a.end(), d.end();
439
+ a.pipe(u), u.pipe(a), a.resume(), u.on("error", (g) => {
440
+ this.logger.error(`${l}.stream.error: ${g}`), a.end(), u.end();
441
+ }), u.on("close", () => {
442
+ a.end(), u.end();
436
443
  }), a.on("close", () => {
437
- this.logger.info(`${l}.localSocket: closed`), a.end(), d.end();
444
+ this.logger.info(`${l}.localSocket: closed`), a.end(), u.end();
438
445
  });
439
446
  });
440
- c.listen(r.localPort, "127.0.0.1", () => {
441
- this.logger.info(`${e}.server: started listening`), o({ server: c });
447
+ c.listen(t.localPort, "127.0.0.1", () => {
448
+ this.logger.info(`${e}.server: started listening`), this.forwardedServers.push(c), o({ server: c });
442
449
  }), c.on("error", (a) => {
443
450
  c.close(), n(new Error(`${e}.server: error: ${JSON.stringify(a)}`));
444
451
  }), c.on("close", () => {
445
- this.logger.info(`${e}.server: closed ${JSON.stringify(r)}`);
452
+ this.logger.info(`${e}.server: closed ${JSON.stringify(t)}`), this.forwardedServers = this.forwardedServers.filter((a) => a !== c);
446
453
  });
447
454
  });
448
455
  }
456
+ closeForwardedPorts() {
457
+ this.logger.info("[SSH] Closing all forwarded ports..."), this.forwardedServers.forEach((t) => {
458
+ const r = t.address();
459
+ if (r && typeof r != "string") {
460
+ const e = r;
461
+ this.logger.info(`[SSH] Closing port forward for server ${e.address}:${e.port}`);
462
+ }
463
+ t.close();
464
+ }), this.forwardedServers = [];
465
+ }
449
466
  /**
450
467
  * Checks if a specified host is available by performing a DNS lookup.
451
468
  * @param hostname - The hostname or IP address to check.
452
469
  * @returns A promise resolving with `true` if the host is reachable, otherwise `false`.
453
470
  */
454
- static async checkHostAvailability(r) {
455
- return new Promise((t) => {
456
- nt.lookup(r, (e) => {
457
- t(!e);
471
+ static async checkHostAvailability(t) {
472
+ return new Promise((r) => {
473
+ nr.lookup(t, (e) => {
474
+ r(!e);
458
475
  });
459
476
  });
460
477
  }
@@ -463,10 +480,10 @@ class x {
463
480
  * @param privateKey - The private key content to check.
464
481
  * @returns A promise resolving with `true` if a passphrase is required, otherwise `false`.
465
482
  */
466
- static async isPassphraseRequiredForKey(r) {
467
- return new Promise((t, e) => {
483
+ static async isPassphraseRequiredForKey(t) {
484
+ return new Promise((r, e) => {
468
485
  try {
469
- return st.utils.parseKey(r) instanceof Error && t(!0), t(!1);
486
+ return sr.utils.parseKey(t) instanceof Error && r(!0), r(!1);
470
487
  } catch (i) {
471
488
  console.log("Error parsing privateKey"), e(new Error(`ssh.isPassphraseRequiredForKey: err ${i}`));
472
489
  }
@@ -479,12 +496,12 @@ class x {
479
496
  * @param remotePath - The remote file path on the server.
480
497
  * @returns A promise resolving with `true` if the file was successfully uploaded.
481
498
  */
482
- async uploadFile(r, t) {
499
+ async uploadFile(t, r) {
483
500
  return await this.withSftp(async (e) => new Promise((i, o) => {
484
- e.fastPut(r, t, (n) => {
501
+ e.fastPut(t, r, (n) => {
485
502
  if (n) {
486
503
  const c = new Error(
487
- `ssh.uploadFile: err: ${n}, localPath: ${r}, remotePath: ${t}`
504
+ `ssh.uploadFile: err: ${n}, localPath: ${t}, remotePath: ${r}`
488
505
  );
489
506
  return o(c);
490
507
  }
@@ -492,17 +509,17 @@ class x {
492
509
  });
493
510
  }));
494
511
  }
495
- delay(r) {
496
- return new Promise((t, e) => {
497
- setTimeout(() => t(), r);
512
+ delay(t) {
513
+ return new Promise((r, e) => {
514
+ setTimeout(() => r(), t);
498
515
  });
499
516
  }
500
- async withSftp(r) {
501
- return new Promise((t, e) => {
517
+ async withSftp(t) {
518
+ return new Promise((r, e) => {
502
519
  this.client.sftp((i, o) => {
503
520
  if (i)
504
521
  return e(new Error(`ssh.withSftp: sftp err: ${i}`));
505
- r(o).then(t).catch((n) => {
522
+ t(o).then(r).catch((n) => {
506
523
  e(new Error(`ssh.withSftp.callback: err ${n}`));
507
524
  }).finally(() => {
508
525
  o == null || o.end();
@@ -510,20 +527,20 @@ class x {
510
527
  });
511
528
  });
512
529
  }
513
- async writeFileOnTheServer(r, t, e = 432) {
514
- return this.withSftp(async (i) => this.writeFile(i, r, t, e));
530
+ async writeFileOnTheServer(t, r, e = 432) {
531
+ return this.withSftp(async (i) => this.writeFile(i, t, r, e));
515
532
  }
516
- async getForderStructure(r, t, e = { files: [], directories: [] }) {
533
+ async getForderStructure(t, r, e = { files: [], directories: [] }) {
517
534
  return new Promise((i, o) => {
518
- r.readdir(t, async (n, c) => {
535
+ t.readdir(r, async (n, c) => {
519
536
  if (n)
520
537
  return o(n);
521
538
  for (const a of c) {
522
- const l = `${t}/${a.filename}`;
539
+ const l = `${r}/${a.filename}`;
523
540
  if (a.attrs.isDirectory()) {
524
541
  e.directories.push(l);
525
542
  try {
526
- await this.getForderStructure(r, l, e);
543
+ await this.getForderStructure(t, l, e);
527
544
  } catch (h) {
528
545
  return o(h);
529
546
  }
@@ -534,60 +551,60 @@ class x {
534
551
  });
535
552
  });
536
553
  }
537
- rmdir(r, t) {
554
+ rmdir(t, r) {
538
555
  return new Promise((e, i) => {
539
- r.rmdir(t, (o) => o ? i(o) : e(!0));
556
+ t.rmdir(r, (o) => o ? i(o) : e(!0));
540
557
  });
541
558
  }
542
- unlink(r, t) {
559
+ unlink(t, r) {
543
560
  return new Promise((e, i) => {
544
- r.unlink(t, (o) => o ? i(o) : e(!0));
561
+ t.unlink(r, (o) => o ? i(o) : e(!0));
545
562
  });
546
563
  }
547
- async deleteFolder(r) {
548
- return this.withSftp(async (t) => {
564
+ async deleteFolder(t) {
565
+ return this.withSftp(async (r) => {
549
566
  try {
550
- const e = await this.getForderStructure(t, r);
567
+ const e = await this.getForderStructure(r, t);
551
568
  this.logger.info("ssh.deleteFolder list of files and directories"), this.logger.info(`ssh.deleteFolder list of files: ${e.files}`), this.logger.info(`ssh.deleteFolder list of directories: ${e.directories}`);
552
569
  for (const i of e.files)
553
- this.logger.info(`ssh.deleteFolder unlink file ${i}`), await this.unlink(t, i);
570
+ this.logger.info(`ssh.deleteFolder unlink file ${i}`), await this.unlink(r, i);
554
571
  e.directories.sort((i, o) => o.length - i.length);
555
572
  for (const i of e.directories)
556
- this.logger.info(`ssh.deleteFolder rmdir ${i}`), await this.rmdir(t, i);
557
- return await this.rmdir(t, r), !0;
573
+ this.logger.info(`ssh.deleteFolder rmdir ${i}`), await this.rmdir(r, i);
574
+ return await this.rmdir(r, t), !0;
558
575
  } catch (e) {
559
576
  this.logger.error(e);
560
577
  const i = e instanceof Error ? e.message : "";
561
- throw new Error(`ssh.deleteFolder: path: ${r}, message: ${i}`);
578
+ throw new Error(`ssh.deleteFolder: path: ${t}, message: ${i}`);
562
579
  }
563
580
  });
564
581
  }
565
- async readFile(r) {
566
- return this.withSftp(async (t) => new Promise((e, i) => {
567
- t.readFile(r, (o, n) => {
582
+ async readFile(t) {
583
+ return this.withSftp(async (r) => new Promise((e, i) => {
584
+ r.readFile(t, (o, n) => {
568
585
  if (o)
569
586
  return i(new Error(`ssh.readFile: err occurred ${o}`));
570
587
  e(n.toString());
571
588
  });
572
589
  }));
573
590
  }
574
- async chmod(r, t) {
591
+ async chmod(t, r) {
575
592
  return this.withSftp(async (e) => new Promise((i, o) => {
576
- e.chmod(r, t, (n) => n ? o(new Error(`ssh.chmod: ${n}, path: ${r}, mode: ${t}`)) : i(void 0));
593
+ e.chmod(t, r, (n) => n ? o(new Error(`ssh.chmod: ${n}, path: ${t}, mode: ${r}`)) : i(void 0));
577
594
  }));
578
595
  }
579
- async checkFileExists(r) {
580
- return this.withSftp(async (t) => new Promise((e, i) => {
581
- t.stat(r, (o, n) => {
596
+ async checkFileExists(t) {
597
+ return this.withSftp(async (r) => new Promise((e, i) => {
598
+ r.stat(t, (o, n) => {
582
599
  if (o)
583
600
  return o.code === 2 ? e(!1) : i(new Error(`ssh.checkFileExists: err ${o}`));
584
601
  e(n.isFile());
585
602
  });
586
603
  }));
587
604
  }
588
- async checkPathExists(r) {
589
- return this.withSftp(async (t) => new Promise((e, i) => {
590
- t.stat(r, (o, n) => {
605
+ async checkPathExists(t) {
606
+ return this.withSftp(async (r) => new Promise((e, i) => {
607
+ r.stat(t, (o, n) => {
591
608
  if (o)
592
609
  return o.code === 2 ? e({ exists: !1, isFile: !1, isDirectory: !1 }) : i(new Error(`ssh.checkPathExists: ${o}`));
593
610
  e({
@@ -598,19 +615,19 @@ class x {
598
615
  });
599
616
  }));
600
617
  }
601
- async writeFile(r, t, e, i = 432) {
618
+ async writeFile(t, r, e, i = 432) {
602
619
  return new Promise((o, n) => {
603
- r.writeFile(t, e, { mode: i }, (c) => {
620
+ t.writeFile(r, e, { mode: i }, (c) => {
604
621
  if (c)
605
- return n(new Error(`ssh.writeFile: err ${c}, remotePath: ${t}`));
622
+ return n(new Error(`ssh.writeFile: err ${c}, remotePath: ${r}`));
606
623
  o(!0);
607
624
  });
608
625
  });
609
626
  }
610
- uploadFileUsingExistingSftp(r, t, e, i = 432) {
627
+ uploadFileUsingExistingSftp(t, r, e, i = 432) {
611
628
  return new Promise((o, n) => {
612
- Q(t).then(async (c) => {
613
- this.writeFile(r, e, c, i).then(() => {
629
+ Q(r).then(async (c) => {
630
+ this.writeFile(t, e, c, i).then(() => {
614
631
  o(void 0);
615
632
  }).catch((a) => {
616
633
  const l = `uploadFileUsingExistingSftp: error ${a} occurred`;
@@ -619,16 +636,16 @@ class x {
619
636
  });
620
637
  });
621
638
  }
622
- async __uploadDirectory(r, t, e, i = 432) {
639
+ async __uploadDirectory(t, r, e, i = 432) {
623
640
  return new Promise((o, n) => {
624
- E.readdir(t, async (c, a) => {
641
+ A.readdir(r, async (c, a) => {
625
642
  if (c)
626
- return n(new Error(`ssh.__uploadDir: err ${c}, localDir: ${t}, remoteDir: ${e}`));
643
+ return n(new Error(`ssh.__uploadDir: err ${c}, localDir: ${r}, remoteDir: ${e}`));
627
644
  try {
628
- await this.__createRemoteDirectory(r, e);
645
+ await this.__createRemoteDirectory(t, e);
629
646
  for (const l of a) {
630
- const h = u.join(t, l), d = `${e}/${l}`;
631
- E.lstatSync(h).isDirectory() ? await this.__uploadDirectory(r, h, d, i) : await this.uploadFileUsingExistingSftp(r, h, d, i);
647
+ const h = d.join(r, l), u = `${e}/${l}`;
648
+ A.lstatSync(h).isDirectory() ? await this.__uploadDirectory(t, h, u, i) : await this.uploadFileUsingExistingSftp(t, h, u, i);
632
649
  }
633
650
  o();
634
651
  } catch (l) {
@@ -644,10 +661,10 @@ class x {
644
661
  * @param remoteDir - The path to the remote directory on the server.
645
662
  * @returns A promise that resolves when the directory and its contents are uploaded.
646
663
  */
647
- async uploadDirectory(r, t, e = 432) {
664
+ async uploadDirectory(t, r, e = 432) {
648
665
  return new Promise((i, o) => {
649
666
  this.withSftp(async (n) => {
650
- await this.__uploadDirectory(n, r, t, e), i();
667
+ await this.__uploadDirectory(n, t, r, e), i();
651
668
  });
652
669
  });
653
670
  }
@@ -657,17 +674,17 @@ class x {
657
674
  * @param remotePath - The path to the remote directory.
658
675
  * @returns A promise that resolves when the directory is created.
659
676
  */
660
- __createRemoteDirectory(r, t) {
677
+ __createRemoteDirectory(t, r) {
661
678
  return new Promise((e, i) => {
662
- const o = t.split("/");
679
+ const o = r.split("/");
663
680
  let n = "";
664
681
  const c = (a) => {
665
682
  if (a >= o.length)
666
683
  return e();
667
- n += `${o[a]}/`, r.stat(n, (l) => {
668
- l ? r.mkdir(n, (h) => {
684
+ n += `${o[a]}/`, t.stat(n, (l) => {
685
+ l ? t.mkdir(n, (h) => {
669
686
  if (h)
670
- return i(new Error(`ssh.__createRemDir: err ${h}, remotePath: ${t}`));
687
+ return i(new Error(`ssh.__createRemDir: err ${h}, remotePath: ${r}`));
671
688
  c(a + 1);
672
689
  }) : c(a + 1);
673
690
  });
@@ -681,9 +698,9 @@ class x {
681
698
  * @param remotePath - The path to the remote directory.
682
699
  * @returns A promise that resolves when the directory is created.
683
700
  */
684
- createRemoteDirectory(r, t = 493) {
701
+ createRemoteDirectory(t, r = 493) {
685
702
  return this.withSftp(async (e) => {
686
- const i = r.split("/");
703
+ const i = t.split("/");
687
704
  let o = "";
688
705
  for (const n of i) {
689
706
  o += `${n}/`;
@@ -691,9 +708,9 @@ class x {
691
708
  await new Promise((c, a) => {
692
709
  e.stat(o, (l) => {
693
710
  if (!l) return c();
694
- e.mkdir(o, { mode: t }, (h) => {
711
+ e.mkdir(o, { mode: r }, (h) => {
695
712
  if (h)
696
- return a(new Error(`ssh.createRemoteDir: err ${h}, remotePath: ${r}`));
713
+ return a(new Error(`ssh.createRemoteDir: err ${h}, remotePath: ${t}`));
697
714
  c();
698
715
  });
699
716
  });
@@ -710,96 +727,96 @@ class x {
710
727
  * @param localPath - The local file path to save the file.
711
728
  * @returns A promise resolving with `true` if the file was successfully downloaded.
712
729
  */
713
- async downloadFile(r, t) {
730
+ async downloadFile(t, r) {
714
731
  return this.withSftp(async (e) => new Promise((i, o) => {
715
- e.fastGet(r, t, (n) => {
732
+ e.fastGet(t, r, (n) => {
716
733
  if (n)
717
- return o(new Error(`ssh.downloadFile: err ${n}, remotePath: ${r}, localPath: ${t}`));
734
+ return o(new Error(`ssh.downloadFile: err ${n}, remotePath: ${t}, localPath: ${r}`));
718
735
  i(!0);
719
736
  });
720
737
  }));
721
738
  }
722
739
  /**
723
- * Closes the SSH client connection.
740
+ * Closes the SSH client connection and forwarded ports.
724
741
  */
725
742
  close() {
726
- this.client.end();
743
+ this.closeForwardedPorts(), this.client.end();
727
744
  }
728
745
  }
729
- async function At(s, r, t, e) {
746
+ async function xr(s, t, r, e) {
730
747
  return new Promise((i, o) => {
731
748
  s.on("ready", () => {
732
749
  i(s);
733
750
  }), s.on("error", (n) => {
734
751
  o(new Error(`ssh.connect: error occurred: ${n}`));
735
752
  }), s.on("close", () => {
736
- }), s.connect(r);
753
+ }), s.connect(t);
737
754
  });
738
755
  }
739
- async function xt(s, r, t, e, i, o) {
756
+ async function Or(s, t, r, e, i, o) {
740
757
  return new Promise((n, c) => {
741
- r.forwardOut(t, e, i, o, (a, l) => a ? (s.error(`forwardOut.error: ${a}`), c(a)) : n(l));
758
+ t.forwardOut(r, e, i, o, (a, l) => a ? (s.error(`forwardOut.error: ${a}`), c(a)) : n(l));
742
759
  });
743
760
  }
744
- const Ot = "minio-2024-12-18T13-15-44Z", kt = "supervisord-0.7.3", Rt = "supervisord_0.7.3_Linux_64-bit";
761
+ const kr = "minio-2024-12-18T13-15-44Z", Rr = "supervisord-0.7.3", Ur = "supervisord_0.7.3_Linux_64-bit";
745
762
  function $(s) {
746
- return u.join(s, "platforma_ssh");
763
+ return d.join(s, "platforma_ssh");
747
764
  }
748
- function v(s) {
749
- return u.join(s, "platforma_ssh", "binaries");
765
+ function S(s) {
766
+ return d.join(s, "platforma_ssh", "binaries");
750
767
  }
751
- function Nt(s, r) {
752
- return u.join(v(s), `pl-${b()}-${P(r)}`);
768
+ function Nr(s, t) {
769
+ return d.join(S(s), `pl-${O()}-${P(t)}`);
753
770
  }
754
- function L(s, r) {
755
- return u.join(Nt(s, r), "binaries");
771
+ function L(s, t) {
772
+ return d.join(Nr(s, t), "binaries");
756
773
  }
757
- function R(s, r) {
758
- return u.join(L(s, r), "platforma");
774
+ function N(s, t) {
775
+ return d.join(L(s, t), "platforma");
759
776
  }
760
- function Ut(s, r) {
761
- return u.join(L(s, r), "free-port");
777
+ function Br(s, t) {
778
+ return d.join(L(s, t), "free-port");
762
779
  }
763
- function z(s, r) {
764
- return u.join(v(s), `minio-2024-12-18T13-15-44Z-${P(r)}`);
780
+ function z(s, t) {
781
+ return d.join(S(s), `minio-2024-12-18T13-15-44Z-${P(t)}`);
765
782
  }
766
- function Tt(s, r) {
767
- return u.join(z(s, r), "minio");
783
+ function Tr(s, t) {
784
+ return d.join(z(s, t), "minio");
768
785
  }
769
- function Bt(s, r) {
770
- return u.join(v(s), `supervisord-0.7.3-${P(r)}`, Rt);
786
+ function _r(s, t) {
787
+ return d.join(S(s), `supervisord-0.7.3-${P(t)}`, Ur);
771
788
  }
772
- function W(s, r) {
773
- return u.join(Bt(s, r), "supervisord");
789
+ function G(s, t) {
790
+ return d.join(_r(s, t), "supervisord");
774
791
  }
775
- function K(s) {
776
- return u.join($(s), "supervisor.conf");
792
+ function W(s) {
793
+ return d.join($(s), "supervisor.conf");
777
794
  }
778
- function N(s) {
779
- return u.join($(s), "connection.txt");
795
+ function B(s) {
796
+ return d.join($(s), "connection.txt");
780
797
  }
781
- async function _t(s, r, t) {
782
- const e = await O(s, r, t, "--daemon");
798
+ async function Ir(s, t, r) {
799
+ const e = await U(s, t, r, "--daemon");
783
800
  if (e.stderr)
784
801
  throw new Error(`Can not run ssh Platforma ${e.stderr}`);
785
802
  }
786
- async function jt(s, r, t) {
787
- const e = await O(s, r, t, "ctl shutdown");
803
+ async function jr(s, t, r) {
804
+ const e = await U(s, t, r, "ctl shutdown");
788
805
  if (e.stderr)
789
806
  throw new Error(`Can not stop ssh Platforma ${e.stderr}`);
790
807
  }
791
- async function It(s, r, t, e) {
792
- const i = await O(r, t, e, "ctl status");
808
+ async function Hr(s, t, r, e) {
809
+ const i = await U(t, r, e, "ctl status");
793
810
  if (i.stderr)
794
811
  return s.info(`supervisord ctl status: stderr occurred: ${i.stderr}, stdout: ${i.stdout}`), !1;
795
812
  const o = {
796
- platforma: U(i.stdout, "platforma"),
797
- minio: U(i.stdout, "minio")
813
+ platforma: T(i.stdout, "platforma"),
814
+ minio: T(i.stdout, "minio")
798
815
  };
799
816
  return o.platforma && o.minio ? !0 : (o.minio || s.warn("Minio is not running on the server"), o.platforma || s.warn("Platforma is not running on the server"), !1);
800
817
  }
801
- function Ht(s, r, t, e, i, o, n) {
802
- const c = Object.entries(r).map(([h, d]) => `${h}="${d}"`).join(","), a = F(16).toString("hex"), l = t;
818
+ function Mr(s, t, r, e, i, o, n) {
819
+ const c = Object.entries(t).map(([h, u]) => `${h}="${u}"`).join(","), a = D(16).toString("hex"), l = r;
803
820
  return `
804
821
  [supervisord]
805
822
  logfile=${e}/supervisord.log
@@ -831,21 +848,21 @@ directory=${e}
831
848
  autorestart=true
832
849
  `;
833
850
  }
834
- async function O(s, r, t, e) {
835
- const i = W(r, t), o = K(r), n = `${i} --configuration ${o} ${e}`;
851
+ async function U(s, t, r, e) {
852
+ const i = G(t, r), o = W(t), n = `${i} --configuration ${o} ${e}`;
836
853
  return await s.exec(n);
837
854
  }
838
- function U(s, r) {
855
+ function T(s, t) {
839
856
  return ((i) => i.replace(/\x1B\[[0-9;]*m/g, ""))(s).split(`
840
857
  `).some((i) => {
841
858
  const [o, n] = i.trim().split(/\s{2,}/);
842
- return o === r && n === "Running";
859
+ return o === t && n === "Running";
843
860
  });
844
861
  }
845
- class q {
846
- constructor(r, t, e) {
862
+ class K {
863
+ constructor(t, r, e) {
847
864
  w(this, "initState", {});
848
- this.logger = r, this.sshClient = t, this.username = e;
865
+ this.logger = t, this.sshClient = r, this.username = e;
849
866
  }
850
867
  info() {
851
868
  return {
@@ -853,141 +870,144 @@ class q {
853
870
  initState: this.initState
854
871
  };
855
872
  }
856
- static async init(r, t) {
873
+ static async init(t, r) {
857
874
  try {
858
- const e = await x.init(r, t);
859
- return new q(r, e, f(t.username));
875
+ const e = await R.init(t, r);
876
+ return new K(t, e, p(r.username));
860
877
  } catch (e) {
861
- throw r.error(`Connection error in SshClient.init: ${e}`), e;
878
+ throw t.error(`Connection error in SshClient.init: ${e}`), e;
862
879
  }
863
880
  }
881
+ cleanUp() {
882
+ this.sshClient.close();
883
+ }
864
884
  async isAlive() {
865
- const r = await this.getArch(), t = await this.getUserHomeDirectory();
885
+ const t = await this.getArch(), r = await this.getUserHomeDirectory();
866
886
  try {
867
- return await It(this.logger, this.sshClient, t, r.arch);
887
+ return await Hr(this.logger, this.sshClient, r, t.arch);
868
888
  } catch {
869
889
  return !1;
870
890
  }
871
891
  }
872
892
  async start() {
873
- const r = await this.getArch(), t = await this.getUserHomeDirectory();
893
+ const t = await this.getArch(), r = await this.getUserHomeDirectory();
874
894
  try {
875
- return await _t(this.sshClient, t, r.arch), await this.checkIsAliveWithInterval();
895
+ return await Ir(this.sshClient, r, t.arch), await this.checkIsAliveWithInterval();
876
896
  } catch (e) {
877
897
  const i = `ssh.start: error occurred ${e}`;
878
898
  throw this.logger.error(i), new Error(i);
879
899
  }
880
900
  }
881
901
  async stop() {
882
- const r = await this.getArch(), t = await this.getUserHomeDirectory();
902
+ const t = await this.getArch(), r = await this.getUserHomeDirectory();
883
903
  try {
884
- return await jt(this.sshClient, t, r.arch), await this.checkIsAliveWithInterval(void 0, void 0, !1);
904
+ return await jr(this.sshClient, r, t.arch), await this.checkIsAliveWithInterval(void 0, void 0, !1);
885
905
  } catch (e) {
886
906
  const i = `ssh.stop: error occurred ${e}`;
887
907
  throw this.logger.error(i), new Error(i);
888
908
  }
889
909
  }
890
910
  async reset() {
891
- const r = await this.getUserHomeDirectory();
892
- return this.logger.info("pl.reset: Stop Platforma on the server"), await this.stop(), this.logger.info(`pl.reset: Deleting Platforma workDir ${r} on the server`), await this.sshClient.deleteFolder($(r)), !0;
911
+ const t = await this.getUserHomeDirectory();
912
+ return this.logger.info("pl.reset: Stop Platforma on the server"), await this.stop(), this.logger.info(`pl.reset: Deleting Platforma workDir ${t} on the server`), await this.sshClient.deleteFolder($(t)), this.cleanUp(), !0;
893
913
  }
894
- async platformaInit(r) {
895
- const t = { localWorkdir: r };
914
+ async platformaInit(t) {
915
+ const r = { localWorkdir: t };
896
916
  try {
897
- if (t.arch = await this.getArch(), t.remoteHome = await this.getUserHomeDirectory(), t.isAlive = await this.isAlive(), t.isAlive) {
898
- if (t.userCredentials = await this.getUserCredentials(t.remoteHome), !t.userCredentials)
917
+ if (r.arch = await this.getArch(), r.remoteHome = await this.getUserHomeDirectory(), r.isAlive = await this.isAlive(), r.isAlive) {
918
+ if (r.userCredentials = await this.getUserCredentials(r.remoteHome), !r.userCredentials)
899
919
  throw new Error("SshPl.platformaInit: platforma is alive but userCredentials are not found");
900
- return t.userCredentials;
920
+ return r.userCredentials;
901
921
  }
902
922
  const e = await this.downloadBinariesAndUploadToTheServer(
903
- r,
904
- t.remoteHome,
905
- t.arch
923
+ t,
924
+ r.remoteHome,
925
+ r.arch
906
926
  );
907
- if (t.binPaths = { ...e, history: void 0 }, t.downloadedBinaries = e.history, t.ports = await this.fetchPorts(t.remoteHome, t.arch), !t.ports.debug.remote || !t.ports.grpc.remote || !t.ports.minioPort.remote || !t.ports.minioConsolePort.remote || !t.ports.monitoring.remote)
927
+ if (r.binPaths = { ...e, history: void 0 }, r.downloadedBinaries = e.history, r.ports = await this.fetchPorts(r.remoteHome, r.arch), !r.ports.debug.remote || !r.ports.grpc.remote || !r.ports.minioPort.remote || !r.ports.minioConsolePort.remote || !r.ports.monitoring.remote)
908
928
  throw new Error("SshPl.platformaInit: remote ports are not defined");
909
- const i = await at({
929
+ const i = await ar({
910
930
  logger: this.logger,
911
- workingDir: $(t.remoteHome),
931
+ workingDir: $(r.remoteHome),
912
932
  portsMode: {
913
933
  type: "customWithMinio",
914
934
  ports: {
915
- debug: t.ports.debug.remote,
916
- grpc: t.ports.grpc.remote,
917
- minio: t.ports.minioPort.remote,
918
- minioConsole: t.ports.minioConsolePort.remote,
919
- monitoring: t.ports.monitoring.remote,
920
- grpcLocal: t.ports.grpc.local,
921
- minioLocal: t.ports.minioPort.local
935
+ debug: r.ports.debug.remote,
936
+ grpc: r.ports.grpc.remote,
937
+ minio: r.ports.minioPort.remote,
938
+ minioConsole: r.ports.minioConsolePort.remote,
939
+ monitoring: r.ports.monitoring.remote,
940
+ grpcLocal: r.ports.grpc.local,
941
+ minioLocal: r.ports.minioPort.local
922
942
  }
923
943
  },
924
944
  licenseMode: {
925
945
  type: "env"
926
946
  }
927
947
  });
928
- t.generatedConfig = { ...i, filesToCreate: { skipped: "it is too wordy" } };
948
+ r.generatedConfig = { ...i, filesToCreate: { skipped: "it is too wordy" } };
929
949
  for (const [c, a] of Object.entries(i.filesToCreate))
930
950
  await this.sshClient.writeFileOnTheServer(c, a), this.logger.info(`Created file ${c}`);
931
951
  for (const c of i.dirsToCreate)
932
952
  await this.sshClient.createRemoteDirectory(c), this.logger.info(`Created directory ${c}`);
933
- const o = Ht(
953
+ const o = Mr(
934
954
  i.minioConfig.storageDir,
935
955
  i.minioConfig.envs,
936
- await this.getFreePortForPlatformaOnServer(t.remoteHome, t.arch),
956
+ await this.getFreePortForPlatformaOnServer(r.remoteHome, r.arch),
937
957
  i.workingDir,
938
958
  i.plConfig.configPath,
939
- t.binPaths.minioRelPath,
940
- t.binPaths.downloadedPl
959
+ r.binPaths.minioRelPath,
960
+ r.binPaths.downloadedPl
941
961
  );
942
- if (!await this.sshClient.writeFileOnTheServer(K(t.remoteHome), o))
943
- throw new Error(`Can not write supervisord config on the server ${$(t.remoteHome)}`);
944
- return t.connectionInfo = {
962
+ if (!await this.sshClient.writeFileOnTheServer(W(r.remoteHome), o))
963
+ throw new Error(`Can not write supervisord config on the server ${$(r.remoteHome)}`);
964
+ return r.connectionInfo = {
945
965
  plUser: i.plUser,
946
966
  plPassword: i.plPassword,
947
- ports: t.ports
967
+ ports: r.ports
948
968
  }, await this.sshClient.writeFileOnTheServer(
949
- N(t.remoteHome),
950
- JSON.stringify(t.connectionInfo, void 0, 2)
951
- ), await this.start(), t.started = !0, this.initState = t, {
969
+ B(r.remoteHome),
970
+ JSON.stringify(r.connectionInfo, void 0, 2)
971
+ ), await this.start(), r.started = !0, this.initState = r, {
952
972
  plUser: i.plUser,
953
973
  plPassword: i.plPassword,
954
- ports: t.ports
974
+ ports: r.ports
955
975
  };
956
976
  } catch (e) {
957
- const i = `SshPl.platformaInit: error occurred: ${e}, state: ${JSON.stringify(t)}`;
977
+ const i = `SshPl.platformaInit: error occurred: ${e}, state: ${JSON.stringify(r)}`;
958
978
  throw this.logger.error(i), new Error(i);
959
979
  }
960
980
  }
961
- async downloadBinariesAndUploadToTheServer(r, t, e) {
981
+ async downloadBinariesAndUploadToTheServer(t, r, e) {
962
982
  const i = [];
963
983
  try {
964
984
  const o = await this.downloadAndUntar(
965
- r,
966
985
  t,
986
+ r,
967
987
  e,
968
988
  "pl",
969
- `pl-${b()}`
989
+ `pl-${O()}`
970
990
  );
971
991
  i.push(o);
972
992
  const n = await this.downloadAndUntar(
973
- r,
974
993
  t,
994
+ r,
975
995
  e,
976
996
  "supervisord",
977
- kt
997
+ Rr
978
998
  );
979
999
  i.push(n);
980
- const c = Tt(t, e.arch), a = await this.downloadAndUntar(
981
- r,
1000
+ const c = Tr(r, e.arch), a = await this.downloadAndUntar(
982
1001
  t,
1002
+ r,
983
1003
  e,
984
1004
  "minio",
985
- Ot
1005
+ kr
986
1006
  );
987
1007
  return i.push(a), await this.sshClient.chmod(c, 488), {
988
1008
  history: i,
989
1009
  minioRelPath: c,
990
- downloadedPl: R(t, e.arch)
1010
+ downloadedPl: N(r, e.arch)
991
1011
  };
992
1012
  } catch (o) {
993
1013
  const n = `SshPl.downloadBinariesAndUploadToServer: error ${o} occurred, state: ${JSON.stringify(i)}`;
@@ -998,27 +1018,27 @@ class q {
998
1018
  * because Windows doesn't support symlinks
999
1019
  * that are found in linux pl binaries tgz archive.
1000
1020
  * For this reason, we extract all to the remote server. */
1001
- async downloadAndUntar(r, t, e, i, o) {
1021
+ async downloadAndUntar(t, r, e, i, o) {
1002
1022
  const n = {};
1003
- n.binBasePath = v(t), await this.sshClient.createRemoteDirectory(n.binBasePath), n.binBasePathCreated = !0;
1023
+ n.binBasePath = S(r), await this.sshClient.createRemoteDirectory(n.binBasePath), n.binBasePathCreated = !0;
1004
1024
  let c = null;
1005
1025
  const a = 5;
1006
1026
  for (let h = 1; h <= a; h++)
1007
1027
  try {
1008
- c = await ut(
1028
+ c = await wr(
1009
1029
  this.logger,
1010
- r,
1030
+ t,
1011
1031
  i,
1012
1032
  o,
1013
1033
  e.arch,
1014
1034
  e.platform
1015
1035
  );
1016
1036
  break;
1017
- } catch (d) {
1018
- if (await C(300), h == a)
1019
- throw new Error(`downloadAndUntar: ${a} attempts, last error: ${d}`);
1037
+ } catch (u) {
1038
+ if (await F(300), h == a)
1039
+ throw new Error(`downloadAndUntar: ${a} attempts, last error: ${u}`);
1020
1040
  }
1021
- n.downloadResult = f(c), n.localArchivePath = u.resolve(n.downloadResult.archivePath), n.remoteDir = u.join(n.binBasePath, n.downloadResult.baseName), n.remoteArchivePath = n.remoteDir + ".tgz", await this.sshClient.createRemoteDirectory(n.remoteDir), await this.sshClient.uploadFile(n.localArchivePath, n.remoteArchivePath);
1041
+ n.downloadResult = p(c), n.localArchivePath = d.resolve(n.downloadResult.archivePath), n.remoteDir = d.join(n.binBasePath, n.downloadResult.baseName), n.remoteArchivePath = n.remoteDir + ".tgz", await this.sshClient.createRemoteDirectory(n.remoteDir), await this.sshClient.uploadFile(n.localArchivePath, n.remoteArchivePath);
1022
1042
  const l = await this.sshClient.exec(
1023
1043
  `tar xvf ${n.remoteArchivePath} --directory=${n.remoteDir}`
1024
1044
  );
@@ -1026,67 +1046,67 @@ class q {
1026
1046
  throw new Error(`downloadAndUntar: untar: stderr occurred: ${l.stderr}, stdout: ${l.stdout}`);
1027
1047
  return n.plUntarDone = !0, n;
1028
1048
  }
1029
- async needDownload(r, t) {
1030
- const e = W(r, t.arch), i = z(r, t.arch), o = R(r, t.arch);
1049
+ async needDownload(t, r) {
1050
+ const e = G(t, r.arch), i = z(t, r.arch), o = N(t, r.arch);
1031
1051
  return !await this.sshClient.checkFileExists(o) || !await this.sshClient.checkFileExists(i) || !await this.sshClient.checkFileExists(e);
1032
1052
  }
1033
- async checkIsAliveWithInterval(r = 1e3, t = 15, e = !0) {
1034
- const i = t * r;
1053
+ async checkIsAliveWithInterval(t = 1e3, r = 15, e = !0) {
1054
+ const i = r * t;
1035
1055
  let o = 0, n = await this.isAlive();
1036
1056
  for (; e ? !n : n; ) {
1037
- if (await C(r), o += r, o > i)
1057
+ if (await F(t), o += t, o > i)
1038
1058
  throw new Error(`isAliveWithInterval: The process did not ${e ? "started" : "stopped"} after ${i} ms.`);
1039
1059
  n = await this.isAlive();
1040
1060
  }
1041
1061
  }
1042
- async getUserCredentials(r) {
1043
- const t = await this.sshClient.readFile(N(r));
1044
- return JSON.parse(t);
1062
+ async getUserCredentials(t) {
1063
+ const r = await this.sshClient.readFile(B(t));
1064
+ return JSON.parse(r);
1045
1065
  }
1046
- async fetchPorts(r, t) {
1066
+ async fetchPorts(t, r) {
1047
1067
  return {
1048
1068
  grpc: {
1049
1069
  local: await y(),
1050
- remote: await this.getFreePortForPlatformaOnServer(r, t)
1070
+ remote: await this.getFreePortForPlatformaOnServer(t, r)
1051
1071
  },
1052
1072
  monitoring: {
1053
1073
  local: await y(),
1054
- remote: await this.getFreePortForPlatformaOnServer(r, t)
1074
+ remote: await this.getFreePortForPlatformaOnServer(t, r)
1055
1075
  },
1056
1076
  debug: {
1057
1077
  local: await y(),
1058
- remote: await this.getFreePortForPlatformaOnServer(r, t)
1078
+ remote: await this.getFreePortForPlatformaOnServer(t, r)
1059
1079
  },
1060
1080
  minioPort: {
1061
1081
  local: await y(),
1062
- remote: await this.getFreePortForPlatformaOnServer(r, t)
1082
+ remote: await this.getFreePortForPlatformaOnServer(t, r)
1063
1083
  },
1064
1084
  minioConsolePort: {
1065
1085
  local: await y(),
1066
- remote: await this.getFreePortForPlatformaOnServer(r, t)
1086
+ remote: await this.getFreePortForPlatformaOnServer(t, r)
1067
1087
  }
1068
1088
  };
1069
1089
  }
1070
1090
  async getLocalFreePort() {
1071
- return new Promise((r) => {
1072
- const t = B.createServer();
1073
- t.listen(0, () => {
1074
- const e = t.address().port;
1075
- t.close((i) => r(e));
1091
+ return new Promise((t) => {
1092
+ const r = I.createServer();
1093
+ r.listen(0, () => {
1094
+ const e = r.address().port;
1095
+ r.close((i) => t(e));
1076
1096
  });
1077
1097
  });
1078
1098
  }
1079
- async getFreePortForPlatformaOnServer(r, t) {
1080
- const e = Ut(r, t.arch), { stdout: i, stderr: o } = await this.sshClient.exec(`${e}`);
1099
+ async getFreePortForPlatformaOnServer(t, r) {
1100
+ const e = Br(t, r.arch), { stdout: i, stderr: o } = await this.sshClient.exec(`${e}`);
1081
1101
  if (o)
1082
1102
  throw new Error(`getFreePortForPlatformaOnServer: stderr is not empty: ${o}, stdout: ${i}`);
1083
1103
  return +i;
1084
1104
  }
1085
1105
  async getArch() {
1086
- const { stdout: r, stderr: t } = await this.sshClient.exec("uname -s && uname -m");
1087
- if (t)
1088
- throw new Error(`getArch: stderr is not empty: ${t}, stdout: ${r}`);
1089
- const e = r.split(`
1106
+ const { stdout: t, stderr: r } = await this.sshClient.exec("uname -s && uname -m");
1107
+ if (r)
1108
+ throw new Error(`getArch: stderr is not empty: ${r}, stdout: ${t}`);
1109
+ const e = t.split(`
1090
1110
  `);
1091
1111
  return {
1092
1112
  platform: e[0],
@@ -1094,20 +1114,20 @@ class q {
1094
1114
  };
1095
1115
  }
1096
1116
  async getUserHomeDirectory() {
1097
- const { stdout: r, stderr: t } = await this.sshClient.exec("echo $HOME");
1098
- if (t) {
1117
+ const { stdout: t, stderr: r } = await this.sshClient.exec("echo $HOME");
1118
+ if (r) {
1099
1119
  const e = `/home/${this.username}`;
1100
- return console.warn(`getUserHomeDirectory: stderr is not empty: ${t}, stdout: ${r}, will get a default home: ${e}`), e;
1120
+ return console.warn(`getUserHomeDirectory: stderr is not empty: ${r}, stdout: ${t}, will get a default home: ${e}`), e;
1101
1121
  }
1102
- return r.trim();
1122
+ return t.trim();
1103
1123
  }
1104
1124
  }
1105
1125
  export {
1106
- Et as LocalConfigYaml,
1107
- Ft as LocalPl,
1108
- x as SshClient,
1109
- q as SshPl,
1110
- b as getDefaultPlVersion,
1111
- ir as localPlatformaInit
1126
+ Fr as LocalConfigYaml,
1127
+ Ar as LocalPl,
1128
+ R as SshClient,
1129
+ K as SshPl,
1130
+ O as getDefaultPlVersion,
1131
+ st as localPlatformaInit
1112
1132
  };
1113
1133
  //# sourceMappingURL=index.mjs.map