sap-adt-cli 1.5.1 → 1.5.3
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/README.md +10 -0
- package/package.json +1 -1
- package/runtime-manifest.json +16 -5
- package/scripts/install.js +224 -6
package/README.md
CHANGED
|
@@ -9,6 +9,12 @@ if Node.js is not an option, use the desktop installer / portable archive
|
|
|
9
9
|
from the [repository releases](https://github.com/shrek-abaper/sap-engineering-skill)
|
|
10
10
|
instead.
|
|
11
11
|
|
|
12
|
+
Linux x86_64 and Windows x86_64 runtimes are provided. Windows support
|
|
13
|
+
starts with package 1.5.3 and also requires `tar.exe` (included in current
|
|
14
|
+
Windows 10/11). macOS has no self-contained runtime yet; use the Python
|
|
15
|
+
package there. Upgrading an older Windows launcher requires reinstalling
|
|
16
|
+
the npm package before running `sap-adt install` again.
|
|
17
|
+
|
|
12
18
|
## Install the runtime (once)
|
|
13
19
|
|
|
14
20
|
The package is named `sap-adt-cli`; its bin is **`sap-adt`**.
|
|
@@ -34,6 +40,10 @@ artifact over HTTPS, verifies its SHA-256 (from the manifest bundled with
|
|
|
34
40
|
the package — never from the download endpoint), extracts safely and swaps
|
|
35
41
|
it in atomically, then self-tests with the absolute install path.
|
|
36
42
|
|
|
43
|
+
On a proxied network, set `HTTPS_PROXY` (and `NO_PROXY` for hosts that go
|
|
44
|
+
direct) before running `install`; the wizard tunnels through an `http://`
|
|
45
|
+
proxy, reports download progress, and aborts on a timeout instead of hanging.
|
|
46
|
+
|
|
37
47
|
## Use
|
|
38
48
|
|
|
39
49
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sap-adt-cli",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"description": "Installer and launcher for the self-contained sap-adt CLI (SAP ADT REST API). No Python required; Node.js >=18 needed for this npm channel only.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
package/runtime-manifest.json
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
"cli_version": "1.5.
|
|
3
|
-
"release_state": "
|
|
2
|
+
"cli_version": "1.5.3",
|
|
3
|
+
"release_state": "published",
|
|
4
4
|
"artifacts": {
|
|
5
5
|
"linux-x86_64": {
|
|
6
|
-
"url": "https://github.com/shrek-abaper/sap-engineering-skill/releases/download/sap-adt-v1.5.
|
|
7
|
-
"sha256": "
|
|
6
|
+
"url": "https://github.com/shrek-abaper/sap-engineering-skill/releases/download/sap-adt-v1.5.3/sap-adt-1.5.3-linux-x86_64.tar.gz",
|
|
7
|
+
"sha256": "19d13fc0512265b2612bb8b01d3a45592e6eecfbdeb108ba4ddb1679cf27476d",
|
|
8
8
|
"format": "tar.gz",
|
|
9
|
-
"size_bytes":
|
|
9
|
+
"size_bytes": 16557337,
|
|
10
|
+
"allowed_redirect_hosts": [
|
|
11
|
+
"github.com",
|
|
12
|
+
"release-assets.githubusercontent.com",
|
|
13
|
+
"objects.githubusercontent.com"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"windows-x86_64": {
|
|
17
|
+
"url": "https://github.com/shrek-abaper/sap-engineering-skill/releases/download/sap-adt-v1.5.3/sap-adt-1.5.3-windows-x86_64.zip",
|
|
18
|
+
"sha256": "5989c1d65a4c202e925c48ad825b8350caf4440b9aca6706df31eb3c6984b152",
|
|
19
|
+
"format": "zip",
|
|
20
|
+
"size_bytes": 15569808,
|
|
10
21
|
"allowed_redirect_hosts": [
|
|
11
22
|
"github.com",
|
|
12
23
|
"release-assets.githubusercontent.com",
|
package/scripts/install.js
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* explicitly allow-listed redirect host in the manifest
|
|
14
14
|
* - extraction rejects absolute paths, ".." traversal, and symlinks
|
|
15
15
|
* - no curl|sh, no shell:true, no string-concatenated commands
|
|
16
|
+
* - the only network egress is the artifact download, through the proxy
|
|
17
|
+
* named by HTTPS_PROXY/HTTP_PROXY when the environment sets one
|
|
16
18
|
*
|
|
17
19
|
* Test seam: file:// artifact URLs are accepted ONLY when the environment
|
|
18
20
|
* variable SAP_ADT_INSTALL_ALLOW_FILE=1 is set (local packaging tests).
|
|
@@ -22,13 +24,31 @@
|
|
|
22
24
|
const { spawnSync } = require("node:child_process");
|
|
23
25
|
const crypto = require("node:crypto");
|
|
24
26
|
const fs = require("node:fs");
|
|
27
|
+
const http = require("node:http");
|
|
25
28
|
const https = require("node:https");
|
|
29
|
+
const net = require("node:net");
|
|
26
30
|
const os = require("node:os");
|
|
27
31
|
const path = require("node:path");
|
|
32
|
+
const tls = require("node:tls");
|
|
33
|
+
const { Transform } = require("node:stream");
|
|
28
34
|
const { pipeline } = require("node:stream/promises");
|
|
35
|
+
const { fileURLToPath } = require("node:url");
|
|
29
36
|
|
|
30
37
|
const PKG_DIR = path.resolve(__dirname, "..");
|
|
31
38
|
const MAX_REDIRECTS = 3;
|
|
39
|
+
// Node's core https client ignores HTTPS_PROXY before v24, so a blocked
|
|
40
|
+
// direct route hung this wizard forever. Both timers are inactivity-based:
|
|
41
|
+
// a slow but progressing download is never aborted.
|
|
42
|
+
const CONNECT_TIMEOUT_MS = intEnv("SAP_ADT_INSTALL_CONNECT_TIMEOUT_MS", 30_000);
|
|
43
|
+
const IDLE_TIMEOUT_MS = 60_000;
|
|
44
|
+
const PROGRESS_INTERVAL_MS = 5_000;
|
|
45
|
+
|
|
46
|
+
function intEnv(name, fallback) {
|
|
47
|
+
const raw = process.env[name];
|
|
48
|
+
if (!raw) return fallback;
|
|
49
|
+
const value = Number(raw);
|
|
50
|
+
return Number.isFinite(value) && value > 0 ? value : fallback;
|
|
51
|
+
}
|
|
32
52
|
|
|
33
53
|
function fail(message, code = 1) {
|
|
34
54
|
process.stderr.write(`[sap-adt install] ERROR: ${message}\n`);
|
|
@@ -77,6 +97,157 @@ function pickArtifact(manifest, key) {
|
|
|
77
97
|
return entry;
|
|
78
98
|
}
|
|
79
99
|
|
|
100
|
+
function firstEnv(env, names) {
|
|
101
|
+
for (const name of names) {
|
|
102
|
+
const value = env[name];
|
|
103
|
+
if (value && value.trim()) return value.trim();
|
|
104
|
+
}
|
|
105
|
+
return "";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* Proxy for a target URL, or null when the request should go direct.
|
|
109
|
+
* Honors the usual spellings plus npm's own config variables; `env` is
|
|
110
|
+
* injectable so the tests never depend on the machine's network. */
|
|
111
|
+
function proxyForUrl(targetUrl, env = process.env) {
|
|
112
|
+
const raw = firstEnv(env, [
|
|
113
|
+
"https_proxy", "HTTPS_PROXY", "npm_config_https_proxy", "npm_config_proxy",
|
|
114
|
+
"http_proxy", "HTTP_PROXY",
|
|
115
|
+
]);
|
|
116
|
+
if (!raw) return null;
|
|
117
|
+
|
|
118
|
+
let proxy;
|
|
119
|
+
try {
|
|
120
|
+
proxy = new URL(raw.includes("://") ? raw : `http://${raw}`);
|
|
121
|
+
} catch {
|
|
122
|
+
throw new Error(`HTTPS_PROXY is not a valid URL (got "${raw.replace(/:[^:@/]*@/, ":***@")}")`);
|
|
123
|
+
}
|
|
124
|
+
// Only plain HTTP CONNECT proxies: TLS-to-the-proxy would need TLS-in-TLS,
|
|
125
|
+
// and refusing loudly beats a half-working tunnel.
|
|
126
|
+
if (proxy.protocol !== "http:") {
|
|
127
|
+
throw new Error(`unsupported proxy scheme "${proxy.protocol}" in HTTPS_PROXY (only http:// proxies are supported)`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const target = new URL(targetUrl);
|
|
131
|
+
const noProxy = firstEnv(env, ["no_proxy", "NO_PROXY", "npm_config_noproxy"]);
|
|
132
|
+
return bypassesProxy(target.hostname, target.port || "443", noProxy) ? null : proxy;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function bypassesProxy(hostname, port, noProxy) {
|
|
136
|
+
if (!noProxy) return false;
|
|
137
|
+
const host = hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
138
|
+
for (let entry of noProxy.split(",")) {
|
|
139
|
+
entry = entry.trim().toLowerCase();
|
|
140
|
+
if (!entry) continue;
|
|
141
|
+
if (entry === "*") return true;
|
|
142
|
+
// "host:port" (never "::1" — the host part must be colon-free)
|
|
143
|
+
const withPort = /^([^:]+):(\d+)$/.exec(entry);
|
|
144
|
+
if (withPort) {
|
|
145
|
+
if (withPort[2] !== String(port)) continue;
|
|
146
|
+
entry = withPort[1];
|
|
147
|
+
}
|
|
148
|
+
entry = entry.replace(/^\[|\]$/g, "");
|
|
149
|
+
if (entry.startsWith("*.")) entry = entry.slice(1); // *.corp.com -> .corp.com
|
|
150
|
+
if (entry.startsWith(".")) {
|
|
151
|
+
if (host === entry.slice(1) || host.endsWith(entry)) return true;
|
|
152
|
+
} else if (entry.endsWith(".*")) {
|
|
153
|
+
if (host.startsWith(entry.slice(0, -1))) return true; // 10.* -> 10.
|
|
154
|
+
} else if (host === entry) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function fmtBytes(n) {
|
|
162
|
+
const units = ["B", "KiB", "MiB", "GiB"];
|
|
163
|
+
let value = n;
|
|
164
|
+
let unit = 0;
|
|
165
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
166
|
+
value /= 1024;
|
|
167
|
+
unit += 1;
|
|
168
|
+
}
|
|
169
|
+
return `${unit === 0 ? value : value.toFixed(1)} ${units[unit]}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/* HTTPS through an HTTP(S) proxy: CONNECT tunnel, then TLS to the target so
|
|
173
|
+
* the certificate is still verified against the real host name. */
|
|
174
|
+
function openTunnel(proxy, host, port) {
|
|
175
|
+
return new Promise((resolve, reject) => {
|
|
176
|
+
const target = net.isIP(host) === 6 ? `[${host}]` : host;
|
|
177
|
+
const headers = { Host: `${target}:${port}` };
|
|
178
|
+
if (proxy.username) {
|
|
179
|
+
const user = decodeURIComponent(proxy.username);
|
|
180
|
+
const pass = decodeURIComponent(proxy.password || "");
|
|
181
|
+
headers["Proxy-Authorization"] =
|
|
182
|
+
`Basic ${Buffer.from(`${user}:${pass}`).toString("base64")}`;
|
|
183
|
+
}
|
|
184
|
+
const req = http.request({
|
|
185
|
+
host: proxy.hostname,
|
|
186
|
+
port: proxy.port || 80,
|
|
187
|
+
method: "CONNECT",
|
|
188
|
+
path: `${target}:${port}`,
|
|
189
|
+
headers,
|
|
190
|
+
agent: false,
|
|
191
|
+
timeout: CONNECT_TIMEOUT_MS,
|
|
192
|
+
});
|
|
193
|
+
req.on("connect", (res, socket) => {
|
|
194
|
+
if (res.statusCode === 407) {
|
|
195
|
+
socket.destroy();
|
|
196
|
+
return reject(new Error(
|
|
197
|
+
`proxy ${proxy.host} requires authentication (HTTP 407) — put credentials in ` +
|
|
198
|
+
"HTTPS_PROXY as http://user:pass@host:port"));
|
|
199
|
+
}
|
|
200
|
+
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
201
|
+
socket.destroy();
|
|
202
|
+
return reject(new Error(
|
|
203
|
+
`proxy CONNECT ${proxy.host} -> ${target}:${port} failed: HTTP ${res.statusCode}`));
|
|
204
|
+
}
|
|
205
|
+
const secure = tls.connect({
|
|
206
|
+
socket,
|
|
207
|
+
servername: net.isIP(host) ? undefined : host,
|
|
208
|
+
});
|
|
209
|
+
secure.setTimeout(CONNECT_TIMEOUT_MS, () => secure.destroy(new Error(
|
|
210
|
+
`TLS handshake with ${target} through the proxy timed out after ${CONNECT_TIMEOUT_MS} ms`)));
|
|
211
|
+
secure.once("secureConnect", () => {
|
|
212
|
+
secure.setTimeout(0);
|
|
213
|
+
resolve(secure);
|
|
214
|
+
});
|
|
215
|
+
secure.once("error", (e) => reject(new Error(
|
|
216
|
+
`TLS handshake with ${target} through the proxy failed: ${e.message} ` +
|
|
217
|
+
"(a TLS-intercepting proxy needs NODE_EXTRA_CA_CERTS pointing at its CA)")));
|
|
218
|
+
});
|
|
219
|
+
req.on("timeout", () => req.destroy(new Error(
|
|
220
|
+
`proxy CONNECT to ${proxy.host} timed out after ${CONNECT_TIMEOUT_MS} ms — ` +
|
|
221
|
+
"check HTTPS_PROXY/NO_PROXY and that the proxy allows CONNECT")));
|
|
222
|
+
req.on("error", reject);
|
|
223
|
+
req.end();
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
class TunnelAgent extends https.Agent {
|
|
228
|
+
constructor(proxy) {
|
|
229
|
+
super({ keepAlive: false, maxSockets: 1 });
|
|
230
|
+
this.proxy = proxy;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Node's Agent contract: a 2-argument createConnection is the async form.
|
|
234
|
+
createConnection(options, cb) {
|
|
235
|
+
const host = options.servername || options.host;
|
|
236
|
+
openTunnel(this.proxy, host, options.port || 443).then(
|
|
237
|
+
(socket) => cb(null, socket),
|
|
238
|
+
cb,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function timeoutHint(target, proxy) {
|
|
244
|
+
const via = proxy ? ` via proxy ${proxy.host}` : "";
|
|
245
|
+
const advice = proxy
|
|
246
|
+
? "check HTTPS_PROXY or add this host to NO_PROXY"
|
|
247
|
+
: "if this network requires a proxy, set HTTPS_PROXY=http://host:port";
|
|
248
|
+
return `timed out after ${IDLE_TIMEOUT_MS} ms connecting to ${target}${via} — ${advice}`;
|
|
249
|
+
}
|
|
250
|
+
|
|
80
251
|
function download(url, allowedHosts, dest, redirectsLeft) {
|
|
81
252
|
return new Promise((resolve, reject) => {
|
|
82
253
|
const parsed = new URL(url);
|
|
@@ -85,7 +256,7 @@ function download(url, allowedHosts, dest, redirectsLeft) {
|
|
|
85
256
|
return reject(new Error(
|
|
86
257
|
"file:// artifacts are refused (test-only; set SAP_ADT_INSTALL_ALLOW_FILE=1 to allow)"));
|
|
87
258
|
}
|
|
88
|
-
return fs.promises.copyFile(
|
|
259
|
+
return fs.promises.copyFile(fileURLToPath(parsed), dest)
|
|
89
260
|
.then(resolve, reject);
|
|
90
261
|
}
|
|
91
262
|
if (parsed.protocol !== "https:") {
|
|
@@ -94,7 +265,14 @@ function download(url, allowedHosts, dest, redirectsLeft) {
|
|
|
94
265
|
if (!allowedHosts.includes(parsed.host)) {
|
|
95
266
|
return reject(new Error(`artifact host not allow-listed: ${parsed.host}`));
|
|
96
267
|
}
|
|
97
|
-
|
|
268
|
+
const proxy = proxyForUrl(url);
|
|
269
|
+
const options = { timeout: IDLE_TIMEOUT_MS };
|
|
270
|
+
if (proxy) {
|
|
271
|
+
info(`using proxy ${proxy.host} for ${parsed.host}`);
|
|
272
|
+
options.agent = new TunnelAgent(proxy);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const req = https.get(url, options, (res) => {
|
|
98
276
|
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
99
277
|
res.resume();
|
|
100
278
|
if (redirectsLeft <= 0) return reject(new Error("too many redirects"));
|
|
@@ -116,8 +294,31 @@ function download(url, allowedHosts, dest, redirectsLeft) {
|
|
|
116
294
|
res.resume();
|
|
117
295
|
return reject(new Error(`download failed: HTTP ${res.statusCode}`));
|
|
118
296
|
}
|
|
119
|
-
|
|
120
|
-
|
|
297
|
+
const total = Number(res.headers["content-length"]) || 0;
|
|
298
|
+
info(`downloading ${total ? fmtBytes(total) : "artifact"}${proxy ? ` via ${proxy.host}` : ""}`);
|
|
299
|
+
const started = Date.now();
|
|
300
|
+
let received = 0;
|
|
301
|
+
let lastReport = started;
|
|
302
|
+
const counter = new Transform({
|
|
303
|
+
transform(chunk, _encoding, callback) {
|
|
304
|
+
received += chunk.length;
|
|
305
|
+
const now = Date.now();
|
|
306
|
+
if (now - lastReport >= PROGRESS_INTERVAL_MS) {
|
|
307
|
+
lastReport = now;
|
|
308
|
+
const pct = total ? ` (${Math.floor((received / total) * 100)}%)` : "";
|
|
309
|
+
info(`downloading ${fmtBytes(received)}${total ? ` of ${fmtBytes(total)}` : ""}${pct}`);
|
|
310
|
+
}
|
|
311
|
+
callback(null, chunk);
|
|
312
|
+
},
|
|
313
|
+
flush(callback) {
|
|
314
|
+
info(`downloaded ${fmtBytes(received)} in ${((Date.now() - started) / 1000).toFixed(1)} s`);
|
|
315
|
+
callback();
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
pipeline(res, counter, fs.createWriteStream(dest)).then(resolve, reject);
|
|
319
|
+
});
|
|
320
|
+
req.on("timeout", () => req.destroy(new Error(timeoutHint(parsed.host, proxy))));
|
|
321
|
+
req.on("error", reject);
|
|
121
322
|
});
|
|
122
323
|
}
|
|
123
324
|
|
|
@@ -155,6 +356,18 @@ function extract(archive, format, destDir) {
|
|
|
155
356
|
}
|
|
156
357
|
}
|
|
157
358
|
|
|
359
|
+
/* Rename, or copy when staging and target sit on different filesystems
|
|
360
|
+
* (os.tmpdir() is tmpfs on many Linux/WSL setups → EXDEV). */
|
|
361
|
+
function moveTree(staging, target) {
|
|
362
|
+
try {
|
|
363
|
+
fs.renameSync(staging, target);
|
|
364
|
+
} catch (e) {
|
|
365
|
+
if (e.code !== "EXDEV") throw e;
|
|
366
|
+
fs.cpSync(staging, target, { recursive: true });
|
|
367
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
158
371
|
/* Swap runtime atomically-ish: stage -> rename old aside -> rename new in ->
|
|
159
372
|
* on any failure, restore the old one and leave it working. */
|
|
160
373
|
function installTree(staging, runtimeDir) {
|
|
@@ -165,7 +378,7 @@ function installTree(staging, runtimeDir) {
|
|
|
165
378
|
fs.renameSync(runtimeDir, backup);
|
|
166
379
|
movedOld = true;
|
|
167
380
|
}
|
|
168
|
-
|
|
381
|
+
moveTree(staging, runtimeDir);
|
|
169
382
|
if (movedOld) fs.rmSync(backup, { recursive: true, force: true });
|
|
170
383
|
} catch (e) {
|
|
171
384
|
fs.rmSync(runtimeDir, { recursive: true, force: true });
|
|
@@ -223,4 +436,9 @@ async function main() {
|
|
|
223
436
|
}
|
|
224
437
|
}
|
|
225
438
|
|
|
226
|
-
|
|
439
|
+
if (require.main === module) {
|
|
440
|
+
main().catch((e) => fail(e.message));
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Pure helpers only; the wizard itself stays a script.
|
|
444
|
+
module.exports = { moveTree, proxyForUrl };
|