@getpaseo/protocol 0.7.0-beta.1 → 0.7.0-beta.2
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/ssh-transport.d.ts +11 -0
- package/dist/ssh-transport.js +72 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const DEFAULT_SSH_DAEMON_PORT = 6767;
|
|
2
|
+
export interface SshTransportTarget {
|
|
3
|
+
host: string;
|
|
4
|
+
sshPort?: number;
|
|
5
|
+
daemonPort: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function validatePort(value: string | number, label: string): number;
|
|
8
|
+
export declare function validateSshHost(host: string): string;
|
|
9
|
+
export declare function parseSshTransportUri(value: string): SshTransportTarget;
|
|
10
|
+
export declare function buildSshTunnelArgs(target: SshTransportTarget): string[];
|
|
11
|
+
//# sourceMappingURL=ssh-transport.d.ts.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export const DEFAULT_SSH_DAEMON_PORT = 6767;
|
|
2
|
+
export function validatePort(value, label) {
|
|
3
|
+
const port = Number(value);
|
|
4
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
5
|
+
throw new Error(`${label} must be between 1 and 65535`);
|
|
6
|
+
}
|
|
7
|
+
return port;
|
|
8
|
+
}
|
|
9
|
+
export function validateSshHost(host) {
|
|
10
|
+
const normalized = host.trim();
|
|
11
|
+
if (!normalized)
|
|
12
|
+
throw new Error("SSH host is required");
|
|
13
|
+
if (/\s/u.test(normalized) || normalized.startsWith("-")) {
|
|
14
|
+
throw new Error("SSH host is invalid");
|
|
15
|
+
}
|
|
16
|
+
return normalized;
|
|
17
|
+
}
|
|
18
|
+
export function parseSshTransportUri(value) {
|
|
19
|
+
let url;
|
|
20
|
+
try {
|
|
21
|
+
url = new URL(value);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Error("Invalid SSH host URI", { cause: error });
|
|
25
|
+
}
|
|
26
|
+
if (url.protocol !== "ssh:" || url.password || (url.pathname !== "" && url.pathname !== "/")) {
|
|
27
|
+
throw new Error("Invalid SSH host URI");
|
|
28
|
+
}
|
|
29
|
+
if (url.hash)
|
|
30
|
+
throw new Error("SSH host URI does not support fragments");
|
|
31
|
+
for (const key of url.searchParams.keys()) {
|
|
32
|
+
if (key !== "daemonPort")
|
|
33
|
+
throw new Error(`Unsupported SSH host option: ${key}`);
|
|
34
|
+
}
|
|
35
|
+
const daemonPorts = url.searchParams.getAll("daemonPort");
|
|
36
|
+
if (daemonPorts.length > 1)
|
|
37
|
+
throw new Error("daemonPort may only be specified once");
|
|
38
|
+
const urlHostname = url.hostname;
|
|
39
|
+
const hostname = validateSshHost(urlHostname.startsWith("[") && urlHostname.endsWith("]")
|
|
40
|
+
? urlHostname.slice(1, -1)
|
|
41
|
+
: urlHostname);
|
|
42
|
+
const username = decodeURIComponent(url.username);
|
|
43
|
+
const host = validateSshHost(username ? `${username}@${hostname}` : hostname);
|
|
44
|
+
return {
|
|
45
|
+
host,
|
|
46
|
+
...(url.port ? { sshPort: validatePort(url.port, "SSH port") } : {}),
|
|
47
|
+
daemonPort: daemonPorts[0] === undefined
|
|
48
|
+
? DEFAULT_SSH_DAEMON_PORT
|
|
49
|
+
: validatePort(daemonPorts[0], "Daemon port"),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function buildSshTunnelArgs(target) {
|
|
53
|
+
const host = validateSshHost(target.host);
|
|
54
|
+
const daemonPort = validatePort(target.daemonPort, "Daemon port");
|
|
55
|
+
const args = [
|
|
56
|
+
"-T",
|
|
57
|
+
"-o",
|
|
58
|
+
"BatchMode=yes",
|
|
59
|
+
"-o",
|
|
60
|
+
"ConnectTimeout=10",
|
|
61
|
+
"-o",
|
|
62
|
+
"ClearAllForwardings=yes",
|
|
63
|
+
"-o",
|
|
64
|
+
"ExitOnForwardFailure=yes",
|
|
65
|
+
];
|
|
66
|
+
if (target.sshPort !== undefined) {
|
|
67
|
+
args.push("-p", String(validatePort(target.sshPort, "SSH port")));
|
|
68
|
+
}
|
|
69
|
+
args.push("-W", `127.0.0.1:${daemonPort}`, host);
|
|
70
|
+
return args;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=ssh-transport.js.map
|