@heroku/heroku-cli-util 9.1.0 → 9.1.1
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.
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Server } from 'node:net';
|
|
2
|
-
import * as createTunnel from 'tunnel-ssh';
|
|
3
2
|
import type { ExtendedAddonAttachment } from './data-api';
|
|
4
3
|
export type ConnectionDetails = {
|
|
5
4
|
_tunnel?: Server;
|
|
@@ -14,7 +13,15 @@ export type ConnectionDetails = {
|
|
|
14
13
|
export type ConnectionDetailsWithAttachment = {
|
|
15
14
|
attachment: ExtendedAddonAttachment;
|
|
16
15
|
} & ConnectionDetails;
|
|
17
|
-
export
|
|
16
|
+
export interface TunnelConfig {
|
|
17
|
+
dstHost: string;
|
|
18
|
+
dstPort: number;
|
|
19
|
+
host?: string;
|
|
20
|
+
localHost: string;
|
|
21
|
+
localPort: number;
|
|
22
|
+
privateKey?: string;
|
|
23
|
+
username: string;
|
|
24
|
+
}
|
|
18
25
|
export interface BastionConfigResponse {
|
|
19
26
|
host: string;
|
|
20
27
|
private_key: string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { APIClient } from '@heroku-cli/command';
|
|
2
2
|
import { Server } from 'node:net';
|
|
3
|
-
import * as createTunnel from 'tunnel-ssh';
|
|
4
3
|
import { ExtendedAddonAttachment } from '../../types/pg/data-api';
|
|
5
4
|
import { BastionConfig, ConnectionDetailsWithAttachment, TunnelConfig } from '../../types/pg/tunnel';
|
|
6
5
|
/**
|
|
@@ -46,7 +45,7 @@ export declare const getBastionConfig: (config: Record<string, string>, baseName
|
|
|
46
45
|
*/
|
|
47
46
|
export declare function getPsqlConfigs(connectionDetails: ConnectionDetailsWithAttachment): {
|
|
48
47
|
dbEnv: NodeJS.ProcessEnv;
|
|
49
|
-
dbTunnelConfig:
|
|
48
|
+
dbTunnelConfig: TunnelConfig;
|
|
50
49
|
};
|
|
51
50
|
export type PsqlConfigs = ReturnType<typeof getPsqlConfigs>;
|
|
52
51
|
/**
|
|
@@ -55,8 +54,18 @@ export type PsqlConfigs = ReturnType<typeof getPsqlConfigs>;
|
|
|
55
54
|
* @param connectionDetails - The database connection details with attachment information
|
|
56
55
|
* @param dbTunnelConfig - The tunnel configuration object
|
|
57
56
|
* @param timeout - The timeout in milliseconds (default: 10000)
|
|
58
|
-
* @param createSSHTunnel - The function to create the SSH tunnel
|
|
57
|
+
* @param createSSHTunnel - The function to create the SSH tunnel
|
|
59
58
|
* @returns Promise that resolves to the tunnel server or null if no bastion key is provided
|
|
60
59
|
* @throws Error if unable to establish the tunnel
|
|
61
60
|
*/
|
|
62
|
-
export declare function sshTunnel(connectionDetails: ConnectionDetailsWithAttachment, dbTunnelConfig: TunnelConfig, timeout?: number, createSSHTunnel?:
|
|
61
|
+
export declare function sshTunnel(connectionDetails: ConnectionDetailsWithAttachment, dbTunnelConfig: TunnelConfig, timeout?: number, createSSHTunnel?: typeof createSSHTunnelAdapter): Promise<Server | void>;
|
|
62
|
+
/**
|
|
63
|
+
* Adapter for tunnel-ssh v5 API. Translates our TunnelConfig into the v5
|
|
64
|
+
* createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) call
|
|
65
|
+
* and returns the created local Server.
|
|
66
|
+
*
|
|
67
|
+
* @param config - The tunnel configuration to translate for v5 API
|
|
68
|
+
* @returns Promise that resolves to the created local TCP Server
|
|
69
|
+
*/
|
|
70
|
+
declare function createSSHTunnelAdapter(config: TunnelConfig): Promise<Server>;
|
|
71
|
+
export {};
|
package/dist/utils/pg/bastion.js
CHANGED
|
@@ -8,8 +8,7 @@ exports.sshTunnel = sshTunnel;
|
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
9
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
10
10
|
const node_events_1 = require("node:events");
|
|
11
|
-
const
|
|
12
|
-
const createTunnel = tslib_1.__importStar(require("tunnel-ssh"));
|
|
11
|
+
const tunnelSsh = tslib_1.__importStar(require("tunnel-ssh"));
|
|
13
12
|
const host_1 = tslib_1.__importDefault(require("./host"));
|
|
14
13
|
const pgDebug = (0, debug_1.default)('pg');
|
|
15
14
|
/**
|
|
@@ -140,11 +139,11 @@ function tunnelConfig(connectionDetails) {
|
|
|
140
139
|
* @param connectionDetails - The database connection details with attachment information
|
|
141
140
|
* @param dbTunnelConfig - The tunnel configuration object
|
|
142
141
|
* @param timeout - The timeout in milliseconds (default: 10000)
|
|
143
|
-
* @param createSSHTunnel - The function to create the SSH tunnel
|
|
142
|
+
* @param createSSHTunnel - The function to create the SSH tunnel
|
|
144
143
|
* @returns Promise that resolves to the tunnel server or null if no bastion key is provided
|
|
145
144
|
* @throws Error if unable to establish the tunnel
|
|
146
145
|
*/
|
|
147
|
-
async function sshTunnel(connectionDetails, dbTunnelConfig, timeout = 10000, createSSHTunnel =
|
|
146
|
+
async function sshTunnel(connectionDetails, dbTunnelConfig, timeout = 10000, createSSHTunnel = createSSHTunnelAdapter) {
|
|
148
147
|
if (!connectionDetails.bastionKey) {
|
|
149
148
|
return;
|
|
150
149
|
}
|
|
@@ -205,3 +204,34 @@ class Timeout {
|
|
|
205
204
|
}
|
|
206
205
|
}
|
|
207
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Adapter for tunnel-ssh v5 API. Translates our TunnelConfig into the v5
|
|
209
|
+
* createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) call
|
|
210
|
+
* and returns the created local Server.
|
|
211
|
+
*
|
|
212
|
+
* @param config - The tunnel configuration to translate for v5 API
|
|
213
|
+
* @returns Promise that resolves to the created local TCP Server
|
|
214
|
+
*/
|
|
215
|
+
async function createSSHTunnelAdapter(config) {
|
|
216
|
+
const tunnelOptions = {
|
|
217
|
+
autoClose: true,
|
|
218
|
+
reconnectOnError: false,
|
|
219
|
+
};
|
|
220
|
+
const serverOptions = {
|
|
221
|
+
host: config.localHost,
|
|
222
|
+
port: config.localPort,
|
|
223
|
+
};
|
|
224
|
+
const sshOptions = {
|
|
225
|
+
host: config.host,
|
|
226
|
+
privateKey: config.privateKey,
|
|
227
|
+
username: config.username,
|
|
228
|
+
};
|
|
229
|
+
const forwardOptions = {
|
|
230
|
+
dstAddr: config.dstHost,
|
|
231
|
+
dstPort: config.dstPort,
|
|
232
|
+
srcAddr: config.localHost,
|
|
233
|
+
srcPort: config.localPort,
|
|
234
|
+
};
|
|
235
|
+
const [server] = await tunnelSsh.createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions);
|
|
236
|
+
return server;
|
|
237
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heroku/heroku-cli-util",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.1",
|
|
4
4
|
"description": "Set of helpful CLI utilities",
|
|
5
5
|
"author": "Heroku",
|
|
6
6
|
"license": "ISC",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"@types/node": "^22.15.3",
|
|
20
20
|
"@types/sinon": "^17.0.4",
|
|
21
21
|
"@types/sinon-chai": "^4.0.0",
|
|
22
|
-
"@types/tunnel-ssh": "4.1.1",
|
|
23
22
|
"chai": "^4.4.1",
|
|
24
23
|
"chai-as-promised": "^7.1.2",
|
|
25
24
|
"eslint": "^8.57.0",
|
|
@@ -45,7 +44,7 @@
|
|
|
45
44
|
"@heroku/http-call": "^5.4.0",
|
|
46
45
|
"@oclif/core": "^2.16.0",
|
|
47
46
|
"debug": "^4.4.0",
|
|
48
|
-
"tunnel-ssh": "
|
|
47
|
+
"tunnel-ssh": "5.2.0"
|
|
49
48
|
},
|
|
50
49
|
"engines": {
|
|
51
50
|
"node": ">=20"
|