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