@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/common/pl_binary.d.ts +2 -0
- package/dist/common/pl_binary.d.ts.map +1 -1
- package/dist/common/pl_binary_download.d.ts +2 -4
- package/dist/common/pl_binary_download.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +417 -397
- package/dist/index.mjs.map +1 -1
- package/dist/local/pl.d.ts.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 +4 -1
- package/dist/ssh/ssh.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/pl_binary.ts +11 -2
- package/src/common/pl_binary_download.ts +26 -55
- package/src/local/pl.ts +3 -1
- package/src/ssh/__tests__/pl-docker.test.ts +5 -5
- package/src/ssh/pl.ts +8 -2
- package/src/ssh/ssh.ts +23 -1
package/dist/index.mjs
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
var
|
|
2
|
-
var Z = (s,
|
|
3
|
-
var w = (s,
|
|
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
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
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
|
|
11
|
-
import { text as
|
|
12
|
-
import * as
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import { randomBytes as
|
|
19
|
-
import { generateSshPlConfigs as
|
|
20
|
-
function
|
|
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([
|
|
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 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
|
|
32
|
+
function j(s) {
|
|
33
33
|
return process.kill(s, "SIGINT");
|
|
34
34
|
}
|
|
35
|
-
async function
|
|
35
|
+
async function H(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 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
|
|
42
|
-
function
|
|
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(
|
|
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
|
|
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(
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
77
|
-
const
|
|
78
|
-
|
|
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
|
|
81
|
-
const 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
|
-
|
|
95
|
+
alternativeArchiveGAUrl: l,
|
|
96
|
+
archivePath: h,
|
|
85
97
|
archiveType: n,
|
|
86
|
-
targetFolder:
|
|
98
|
+
targetFolder: u,
|
|
87
99
|
baseName: o
|
|
88
100
|
};
|
|
89
101
|
}
|
|
90
|
-
function
|
|
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 =
|
|
104
|
+
e.dstArchive = r;
|
|
104
105
|
try {
|
|
105
|
-
if (e.fileExisted = await m(
|
|
106
|
-
return s.info(`Platforma Backend archive download skipped: '${
|
|
107
|
-
await
|
|
108
|
-
URL: ${
|
|
109
|
-
Save to: ${
|
|
110
|
-
const { body: i, statusCode: o } = await X(
|
|
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
|
|
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 =
|
|
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
|
|
122
|
-
async function
|
|
123
|
-
if (s.info("extracting archive..."), s.info(` archive path: '${
|
|
124
|
-
const o = `Platforma Backend binary archive not found at '${
|
|
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 =
|
|
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
|
|
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: ${
|
|
135
|
+
Archive: ${t}
|
|
135
136
|
Target dir: ${e}`
|
|
136
|
-
),
|
|
137
|
+
), r) {
|
|
137
138
|
case "tgz":
|
|
138
|
-
await
|
|
139
|
-
file:
|
|
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
|
|
146
|
+
await or(t, e);
|
|
146
147
|
break;
|
|
147
148
|
default:
|
|
148
|
-
|
|
149
|
+
_(r);
|
|
149
150
|
}
|
|
150
|
-
await
|
|
151
|
+
await f.writeFile(i, "ok"), s.info(" ... unpack done.");
|
|
151
152
|
}
|
|
152
|
-
const
|
|
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
|
|
158
|
+
function O() {
|
|
162
159
|
return "1.18.3";
|
|
163
160
|
}
|
|
164
|
-
function
|
|
165
|
-
return { type: "Download", version:
|
|
161
|
+
function yr() {
|
|
162
|
+
return { type: "Download", version: O() };
|
|
166
163
|
}
|
|
167
|
-
async function $
|
|
168
|
-
switch (
|
|
164
|
+
async function $r(s, t, r) {
|
|
165
|
+
switch (r.type) {
|
|
169
166
|
case "Download":
|
|
170
|
-
|
|
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
|
|
170
|
+
return r.path;
|
|
173
171
|
default:
|
|
174
|
-
|
|
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
|
|
181
|
+
return d.join(s, "pl_pid");
|
|
179
182
|
}
|
|
180
|
-
async function
|
|
183
|
+
async function vr(s) {
|
|
181
184
|
if (!await m(s))
|
|
182
185
|
return;
|
|
183
|
-
const
|
|
184
|
-
return Number(
|
|
186
|
+
const t = await f.readFile(s);
|
|
187
|
+
return Number(t.toString());
|
|
185
188
|
}
|
|
186
|
-
async function
|
|
187
|
-
await
|
|
189
|
+
async function Sr(s, t) {
|
|
190
|
+
await f.writeFile(s, JSON.stringify(t));
|
|
188
191
|
}
|
|
189
|
-
function
|
|
192
|
+
function Cr() {
|
|
190
193
|
return {};
|
|
191
194
|
}
|
|
192
|
-
function
|
|
193
|
-
return s[
|
|
195
|
+
function Er(s, t, r) {
|
|
196
|
+
return s[t] = r, r;
|
|
194
197
|
}
|
|
195
|
-
async function
|
|
196
|
-
const
|
|
198
|
+
async function k(s, t) {
|
|
199
|
+
const r = Cr();
|
|
197
200
|
try {
|
|
198
|
-
return await
|
|
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(
|
|
203
|
+
throw s.error(`error ${e} while doing traced operation, state: ${JSON.stringify(r)}`), e;
|
|
201
204
|
}
|
|
202
205
|
}
|
|
203
|
-
const
|
|
204
|
-
class
|
|
205
|
-
constructor(
|
|
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 =
|
|
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
|
|
217
|
+
await k(this.logger, async (t, r) => {
|
|
215
218
|
this.wasStopped = !1;
|
|
216
|
-
const e =
|
|
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
|
-
}),
|
|
224
|
-
const i =
|
|
225
|
-
|
|
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,
|
|
232
|
+
this.wasStopped = !0, j(p(this.pid));
|
|
230
233
|
}
|
|
231
234
|
async waitStopped() {
|
|
232
|
-
await
|
|
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
|
|
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
|
|
252
|
-
const
|
|
253
|
-
plBinary:
|
|
254
|
+
async function st(s, t) {
|
|
255
|
+
const r = {
|
|
256
|
+
plBinary: yr(),
|
|
254
257
|
spawnOptions: {},
|
|
255
258
|
closeOld: !0,
|
|
256
|
-
...
|
|
259
|
+
...t
|
|
257
260
|
};
|
|
258
|
-
return await
|
|
259
|
-
e("startOptions", { ...
|
|
260
|
-
const o =
|
|
261
|
-
|
|
262
|
-
const n =
|
|
263
|
-
s.info(`writing configuration '${n}'...`), await
|
|
264
|
-
const c =
|
|
265
|
-
cmd: e("binaryPath",
|
|
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
|
-
...
|
|
276
|
+
...r.spawnOptions
|
|
274
277
|
}
|
|
275
278
|
};
|
|
276
279
|
e("processOpts", {
|
|
277
|
-
cmd:
|
|
278
|
-
args:
|
|
279
|
-
cwd:
|
|
280
|
+
cmd: h.cmd,
|
|
281
|
+
args: h.args,
|
|
282
|
+
cwd: h.opts.cwd
|
|
280
283
|
});
|
|
281
|
-
const
|
|
284
|
+
const u = new Ar(
|
|
282
285
|
s,
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
r.workingDir,
|
|
287
|
+
h,
|
|
285
288
|
i,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
289
|
+
r.onClose,
|
|
290
|
+
r.onError,
|
|
291
|
+
r.onCloseAndError,
|
|
292
|
+
r.onCloseAndErrorNoStop
|
|
290
293
|
);
|
|
291
|
-
return await
|
|
294
|
+
return await u.start(), u;
|
|
292
295
|
});
|
|
293
296
|
}
|
|
294
|
-
async function
|
|
295
|
-
return await
|
|
296
|
-
const i =
|
|
297
|
-
return o !== void 0 && n && (
|
|
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
|
|
303
|
+
const br = {
|
|
301
304
|
keepaliveInterval: 6e4,
|
|
302
305
|
keepaliveCountMax: 10
|
|
303
306
|
};
|
|
304
|
-
class
|
|
305
|
-
constructor(
|
|
307
|
+
class R {
|
|
308
|
+
constructor(t, r) {
|
|
306
309
|
w(this, "config");
|
|
307
310
|
w(this, "homeDir");
|
|
308
|
-
this
|
|
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(
|
|
319
|
+
static async init(t, r) {
|
|
316
320
|
const e = {
|
|
317
|
-
...
|
|
318
|
-
...
|
|
319
|
-
}, i = new
|
|
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
|
|
324
|
-
return `${(
|
|
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
|
|
328
|
-
return (
|
|
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(
|
|
336
|
-
return this.config =
|
|
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(
|
|
344
|
-
return new Promise((
|
|
345
|
-
this.client.exec(
|
|
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: ${
|
|
354
|
+
return e(`ssh.exec: ${t}, error occurred: ${i}`);
|
|
348
355
|
let n = "", c = "";
|
|
349
356
|
o.on("close", (a) => {
|
|
350
|
-
a === 0 ?
|
|
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(
|
|
372
|
+
static async getAuthTypes(t, r) {
|
|
366
373
|
return new Promise((e) => {
|
|
367
374
|
let i = "";
|
|
368
|
-
const o = new
|
|
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:
|
|
377
|
-
port:
|
|
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(
|
|
392
|
-
const
|
|
393
|
-
return
|
|
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(
|
|
403
|
-
const e = `ssh.forward:${
|
|
404
|
-
|
|
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
|
|
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(
|
|
420
|
+
}), a.connect(r);
|
|
414
421
|
}));
|
|
415
422
|
return await i.ensure(), new Promise((o, n) => {
|
|
416
|
-
const c =
|
|
417
|
-
const l = `${e}.sock_${
|
|
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
|
|
432
|
+
let u;
|
|
426
433
|
try {
|
|
427
|
-
|
|
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(
|
|
433
|
-
this.logger.error(`${l}.stream.error: ${g}`), a.end(),
|
|
434
|
-
}),
|
|
435
|
-
a.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(),
|
|
444
|
+
this.logger.info(`${l}.localSocket: closed`), a.end(), u.end();
|
|
438
445
|
});
|
|
439
446
|
});
|
|
440
|
-
c.listen(
|
|
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(
|
|
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(
|
|
455
|
-
return new Promise((
|
|
456
|
-
|
|
457
|
-
|
|
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(
|
|
467
|
-
return new Promise((
|
|
483
|
+
static async isPassphraseRequiredForKey(t) {
|
|
484
|
+
return new Promise((r, e) => {
|
|
468
485
|
try {
|
|
469
|
-
return
|
|
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(
|
|
499
|
+
async uploadFile(t, r) {
|
|
483
500
|
return await this.withSftp(async (e) => new Promise((i, o) => {
|
|
484
|
-
e.fastPut(
|
|
501
|
+
e.fastPut(t, r, (n) => {
|
|
485
502
|
if (n) {
|
|
486
503
|
const c = new Error(
|
|
487
|
-
`ssh.uploadFile: err: ${n}, localPath: ${
|
|
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(
|
|
496
|
-
return new Promise((
|
|
497
|
-
setTimeout(() =>
|
|
512
|
+
delay(t) {
|
|
513
|
+
return new Promise((r, e) => {
|
|
514
|
+
setTimeout(() => r(), t);
|
|
498
515
|
});
|
|
499
516
|
}
|
|
500
|
-
async withSftp(
|
|
501
|
-
return new Promise((
|
|
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
|
-
|
|
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(
|
|
514
|
-
return this.withSftp(async (i) => this.writeFile(i,
|
|
530
|
+
async writeFileOnTheServer(t, r, e = 432) {
|
|
531
|
+
return this.withSftp(async (i) => this.writeFile(i, t, r, e));
|
|
515
532
|
}
|
|
516
|
-
async getForderStructure(
|
|
533
|
+
async getForderStructure(t, r, e = { files: [], directories: [] }) {
|
|
517
534
|
return new Promise((i, o) => {
|
|
518
|
-
|
|
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 = `${
|
|
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(
|
|
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(
|
|
554
|
+
rmdir(t, r) {
|
|
538
555
|
return new Promise((e, i) => {
|
|
539
|
-
|
|
556
|
+
t.rmdir(r, (o) => o ? i(o) : e(!0));
|
|
540
557
|
});
|
|
541
558
|
}
|
|
542
|
-
unlink(
|
|
559
|
+
unlink(t, r) {
|
|
543
560
|
return new Promise((e, i) => {
|
|
544
|
-
|
|
561
|
+
t.unlink(r, (o) => o ? i(o) : e(!0));
|
|
545
562
|
});
|
|
546
563
|
}
|
|
547
|
-
async deleteFolder(
|
|
548
|
-
return this.withSftp(async (
|
|
564
|
+
async deleteFolder(t) {
|
|
565
|
+
return this.withSftp(async (r) => {
|
|
549
566
|
try {
|
|
550
|
-
const e = await this.getForderStructure(
|
|
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(
|
|
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(
|
|
557
|
-
return await this.rmdir(
|
|
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: ${
|
|
578
|
+
throw new Error(`ssh.deleteFolder: path: ${t}, message: ${i}`);
|
|
562
579
|
}
|
|
563
580
|
});
|
|
564
581
|
}
|
|
565
|
-
async readFile(
|
|
566
|
-
return this.withSftp(async (
|
|
567
|
-
|
|
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(
|
|
591
|
+
async chmod(t, r) {
|
|
575
592
|
return this.withSftp(async (e) => new Promise((i, o) => {
|
|
576
|
-
e.chmod(
|
|
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(
|
|
580
|
-
return this.withSftp(async (
|
|
581
|
-
|
|
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(
|
|
589
|
-
return this.withSftp(async (
|
|
590
|
-
|
|
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(
|
|
618
|
+
async writeFile(t, r, e, i = 432) {
|
|
602
619
|
return new Promise((o, n) => {
|
|
603
|
-
|
|
620
|
+
t.writeFile(r, e, { mode: i }, (c) => {
|
|
604
621
|
if (c)
|
|
605
|
-
return n(new Error(`ssh.writeFile: err ${c}, remotePath: ${
|
|
622
|
+
return n(new Error(`ssh.writeFile: err ${c}, remotePath: ${r}`));
|
|
606
623
|
o(!0);
|
|
607
624
|
});
|
|
608
625
|
});
|
|
609
626
|
}
|
|
610
|
-
uploadFileUsingExistingSftp(
|
|
627
|
+
uploadFileUsingExistingSftp(t, r, e, i = 432) {
|
|
611
628
|
return new Promise((o, n) => {
|
|
612
|
-
Q(
|
|
613
|
-
this.writeFile(
|
|
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(
|
|
639
|
+
async __uploadDirectory(t, r, e, i = 432) {
|
|
623
640
|
return new Promise((o, n) => {
|
|
624
|
-
|
|
641
|
+
A.readdir(r, async (c, a) => {
|
|
625
642
|
if (c)
|
|
626
|
-
return n(new Error(`ssh.__uploadDir: err ${c}, localDir: ${
|
|
643
|
+
return n(new Error(`ssh.__uploadDir: err ${c}, localDir: ${r}, remoteDir: ${e}`));
|
|
627
644
|
try {
|
|
628
|
-
await this.__createRemoteDirectory(
|
|
645
|
+
await this.__createRemoteDirectory(t, e);
|
|
629
646
|
for (const l of a) {
|
|
630
|
-
const h =
|
|
631
|
-
|
|
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(
|
|
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,
|
|
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(
|
|
677
|
+
__createRemoteDirectory(t, r) {
|
|
661
678
|
return new Promise((e, i) => {
|
|
662
|
-
const o =
|
|
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]}/`,
|
|
668
|
-
l ?
|
|
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: ${
|
|
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(
|
|
701
|
+
createRemoteDirectory(t, r = 493) {
|
|
685
702
|
return this.withSftp(async (e) => {
|
|
686
|
-
const i =
|
|
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:
|
|
711
|
+
e.mkdir(o, { mode: r }, (h) => {
|
|
695
712
|
if (h)
|
|
696
|
-
return a(new Error(`ssh.createRemoteDir: err ${h}, remotePath: ${
|
|
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(
|
|
730
|
+
async downloadFile(t, r) {
|
|
714
731
|
return this.withSftp(async (e) => new Promise((i, o) => {
|
|
715
|
-
e.fastGet(
|
|
732
|
+
e.fastGet(t, r, (n) => {
|
|
716
733
|
if (n)
|
|
717
|
-
return o(new Error(`ssh.downloadFile: err ${n}, remotePath: ${
|
|
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
|
|
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(
|
|
753
|
+
}), s.connect(t);
|
|
737
754
|
});
|
|
738
755
|
}
|
|
739
|
-
async function
|
|
756
|
+
async function Or(s, t, r, e, i, o) {
|
|
740
757
|
return new Promise((n, c) => {
|
|
741
|
-
|
|
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
|
|
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
|
|
763
|
+
return d.join(s, "platforma_ssh");
|
|
747
764
|
}
|
|
748
|
-
function
|
|
749
|
-
return
|
|
765
|
+
function S(s) {
|
|
766
|
+
return d.join(s, "platforma_ssh", "binaries");
|
|
750
767
|
}
|
|
751
|
-
function
|
|
752
|
-
return
|
|
768
|
+
function Nr(s, t) {
|
|
769
|
+
return d.join(S(s), `pl-${O()}-${P(t)}`);
|
|
753
770
|
}
|
|
754
|
-
function L(s,
|
|
755
|
-
return
|
|
771
|
+
function L(s, t) {
|
|
772
|
+
return d.join(Nr(s, t), "binaries");
|
|
756
773
|
}
|
|
757
|
-
function
|
|
758
|
-
return
|
|
774
|
+
function N(s, t) {
|
|
775
|
+
return d.join(L(s, t), "platforma");
|
|
759
776
|
}
|
|
760
|
-
function
|
|
761
|
-
return
|
|
777
|
+
function Br(s, t) {
|
|
778
|
+
return d.join(L(s, t), "free-port");
|
|
762
779
|
}
|
|
763
|
-
function z(s,
|
|
764
|
-
return
|
|
780
|
+
function z(s, t) {
|
|
781
|
+
return d.join(S(s), `minio-2024-12-18T13-15-44Z-${P(t)}`);
|
|
765
782
|
}
|
|
766
|
-
function
|
|
767
|
-
return
|
|
783
|
+
function Tr(s, t) {
|
|
784
|
+
return d.join(z(s, t), "minio");
|
|
768
785
|
}
|
|
769
|
-
function
|
|
770
|
-
return
|
|
786
|
+
function _r(s, t) {
|
|
787
|
+
return d.join(S(s), `supervisord-0.7.3-${P(t)}`, Ur);
|
|
771
788
|
}
|
|
772
|
-
function
|
|
773
|
-
return
|
|
789
|
+
function G(s, t) {
|
|
790
|
+
return d.join(_r(s, t), "supervisord");
|
|
774
791
|
}
|
|
775
|
-
function
|
|
776
|
-
return
|
|
792
|
+
function W(s) {
|
|
793
|
+
return d.join($(s), "supervisor.conf");
|
|
777
794
|
}
|
|
778
|
-
function
|
|
779
|
-
return
|
|
795
|
+
function B(s) {
|
|
796
|
+
return d.join($(s), "connection.txt");
|
|
780
797
|
}
|
|
781
|
-
async function
|
|
782
|
-
const e = await
|
|
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
|
|
787
|
-
const e = await
|
|
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
|
|
792
|
-
const i = await
|
|
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:
|
|
797
|
-
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
|
|
802
|
-
const c = Object.entries(
|
|
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
|
|
835
|
-
const i =
|
|
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
|
|
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 ===
|
|
859
|
+
return o === t && n === "Running";
|
|
843
860
|
});
|
|
844
861
|
}
|
|
845
|
-
class
|
|
846
|
-
constructor(
|
|
862
|
+
class K {
|
|
863
|
+
constructor(t, r, e) {
|
|
847
864
|
w(this, "initState", {});
|
|
848
|
-
this.logger =
|
|
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(
|
|
873
|
+
static async init(t, r) {
|
|
857
874
|
try {
|
|
858
|
-
const e = await
|
|
859
|
-
return new
|
|
875
|
+
const e = await R.init(t, r);
|
|
876
|
+
return new K(t, e, p(r.username));
|
|
860
877
|
} catch (e) {
|
|
861
|
-
throw
|
|
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
|
|
885
|
+
const t = await this.getArch(), r = await this.getUserHomeDirectory();
|
|
866
886
|
try {
|
|
867
|
-
return await
|
|
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
|
|
893
|
+
const t = await this.getArch(), r = await this.getUserHomeDirectory();
|
|
874
894
|
try {
|
|
875
|
-
return await
|
|
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
|
|
902
|
+
const t = await this.getArch(), r = await this.getUserHomeDirectory();
|
|
883
903
|
try {
|
|
884
|
-
return await
|
|
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
|
|
892
|
-
return this.logger.info("pl.reset: Stop Platforma on the server"), await this.stop(), this.logger.info(`pl.reset: Deleting Platforma workDir ${
|
|
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(
|
|
895
|
-
const
|
|
914
|
+
async platformaInit(t) {
|
|
915
|
+
const r = { localWorkdir: t };
|
|
896
916
|
try {
|
|
897
|
-
if (
|
|
898
|
-
if (
|
|
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
|
|
920
|
+
return r.userCredentials;
|
|
901
921
|
}
|
|
902
922
|
const e = await this.downloadBinariesAndUploadToTheServer(
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
923
|
+
t,
|
|
924
|
+
r.remoteHome,
|
|
925
|
+
r.arch
|
|
906
926
|
);
|
|
907
|
-
if (
|
|
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
|
|
929
|
+
const i = await ar({
|
|
910
930
|
logger: this.logger,
|
|
911
|
-
workingDir: $(
|
|
931
|
+
workingDir: $(r.remoteHome),
|
|
912
932
|
portsMode: {
|
|
913
933
|
type: "customWithMinio",
|
|
914
934
|
ports: {
|
|
915
|
-
debug:
|
|
916
|
-
grpc:
|
|
917
|
-
minio:
|
|
918
|
-
minioConsole:
|
|
919
|
-
monitoring:
|
|
920
|
-
grpcLocal:
|
|
921
|
-
minioLocal:
|
|
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
|
-
|
|
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 =
|
|
953
|
+
const o = Mr(
|
|
934
954
|
i.minioConfig.storageDir,
|
|
935
955
|
i.minioConfig.envs,
|
|
936
|
-
await this.getFreePortForPlatformaOnServer(
|
|
956
|
+
await this.getFreePortForPlatformaOnServer(r.remoteHome, r.arch),
|
|
937
957
|
i.workingDir,
|
|
938
958
|
i.plConfig.configPath,
|
|
939
|
-
|
|
940
|
-
|
|
959
|
+
r.binPaths.minioRelPath,
|
|
960
|
+
r.binPaths.downloadedPl
|
|
941
961
|
);
|
|
942
|
-
if (!await this.sshClient.writeFileOnTheServer(
|
|
943
|
-
throw new Error(`Can not write supervisord config on the server ${$(
|
|
944
|
-
return
|
|
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:
|
|
967
|
+
ports: r.ports
|
|
948
968
|
}, await this.sshClient.writeFileOnTheServer(
|
|
949
|
-
|
|
950
|
-
JSON.stringify(
|
|
951
|
-
), await this.start(),
|
|
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:
|
|
974
|
+
ports: r.ports
|
|
955
975
|
};
|
|
956
976
|
} catch (e) {
|
|
957
|
-
const i = `SshPl.platformaInit: error occurred: ${e}, state: ${JSON.stringify(
|
|
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(
|
|
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-${
|
|
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
|
-
|
|
997
|
+
Rr
|
|
978
998
|
);
|
|
979
999
|
i.push(n);
|
|
980
|
-
const c =
|
|
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
|
-
|
|
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:
|
|
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(
|
|
1021
|
+
async downloadAndUntar(t, r, e, i, o) {
|
|
1002
1022
|
const n = {};
|
|
1003
|
-
n.binBasePath =
|
|
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
|
|
1028
|
+
c = await wr(
|
|
1009
1029
|
this.logger,
|
|
1010
|
-
|
|
1030
|
+
t,
|
|
1011
1031
|
i,
|
|
1012
1032
|
o,
|
|
1013
1033
|
e.arch,
|
|
1014
1034
|
e.platform
|
|
1015
1035
|
);
|
|
1016
1036
|
break;
|
|
1017
|
-
} catch (
|
|
1018
|
-
if (await
|
|
1019
|
-
throw new Error(`downloadAndUntar: ${a} attempts, last error: ${
|
|
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 =
|
|
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(
|
|
1030
|
-
const e =
|
|
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(
|
|
1034
|
-
const i =
|
|
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
|
|
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(
|
|
1043
|
-
const
|
|
1044
|
-
return JSON.parse(
|
|
1062
|
+
async getUserCredentials(t) {
|
|
1063
|
+
const r = await this.sshClient.readFile(B(t));
|
|
1064
|
+
return JSON.parse(r);
|
|
1045
1065
|
}
|
|
1046
|
-
async fetchPorts(
|
|
1066
|
+
async fetchPorts(t, r) {
|
|
1047
1067
|
return {
|
|
1048
1068
|
grpc: {
|
|
1049
1069
|
local: await y(),
|
|
1050
|
-
remote: await this.getFreePortForPlatformaOnServer(
|
|
1070
|
+
remote: await this.getFreePortForPlatformaOnServer(t, r)
|
|
1051
1071
|
},
|
|
1052
1072
|
monitoring: {
|
|
1053
1073
|
local: await y(),
|
|
1054
|
-
remote: await this.getFreePortForPlatformaOnServer(
|
|
1074
|
+
remote: await this.getFreePortForPlatformaOnServer(t, r)
|
|
1055
1075
|
},
|
|
1056
1076
|
debug: {
|
|
1057
1077
|
local: await y(),
|
|
1058
|
-
remote: await this.getFreePortForPlatformaOnServer(
|
|
1078
|
+
remote: await this.getFreePortForPlatformaOnServer(t, r)
|
|
1059
1079
|
},
|
|
1060
1080
|
minioPort: {
|
|
1061
1081
|
local: await y(),
|
|
1062
|
-
remote: await this.getFreePortForPlatformaOnServer(
|
|
1082
|
+
remote: await this.getFreePortForPlatformaOnServer(t, r)
|
|
1063
1083
|
},
|
|
1064
1084
|
minioConsolePort: {
|
|
1065
1085
|
local: await y(),
|
|
1066
|
-
remote: await this.getFreePortForPlatformaOnServer(
|
|
1086
|
+
remote: await this.getFreePortForPlatformaOnServer(t, r)
|
|
1067
1087
|
}
|
|
1068
1088
|
};
|
|
1069
1089
|
}
|
|
1070
1090
|
async getLocalFreePort() {
|
|
1071
|
-
return new Promise((
|
|
1072
|
-
const
|
|
1073
|
-
|
|
1074
|
-
const e =
|
|
1075
|
-
|
|
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(
|
|
1080
|
-
const 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:
|
|
1087
|
-
if (
|
|
1088
|
-
throw new Error(`getArch: stderr is not empty: ${
|
|
1089
|
-
const e =
|
|
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:
|
|
1098
|
-
if (
|
|
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: ${
|
|
1120
|
+
return console.warn(`getUserHomeDirectory: stderr is not empty: ${r}, stdout: ${t}, will get a default home: ${e}`), e;
|
|
1101
1121
|
}
|
|
1102
|
-
return
|
|
1122
|
+
return t.trim();
|
|
1103
1123
|
}
|
|
1104
1124
|
}
|
|
1105
1125
|
export {
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
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
|