heroku 10.13.2-beta.0 → 10.13.3-beta.0

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.
Files changed (79) hide show
  1. package/lib/commands/pg/backups/cancel.js +4 -4
  2. package/lib/commands/pg/backups/capture.js +5 -5
  3. package/lib/commands/pg/backups/delete.js +2 -2
  4. package/lib/commands/pg/backups/download.js +3 -3
  5. package/lib/commands/pg/backups/index.js +2 -2
  6. package/lib/commands/pg/backups/info.js +3 -3
  7. package/lib/commands/pg/backups/restore.js +5 -5
  8. package/lib/commands/pg/backups/schedule.js +7 -7
  9. package/lib/commands/pg/backups/schedules.js +2 -2
  10. package/lib/commands/pg/backups/unschedule.js +6 -5
  11. package/lib/commands/pg/backups/url.js +3 -3
  12. package/lib/commands/pg/bloat.js +5 -4
  13. package/lib/commands/pg/blocking.js +5 -4
  14. package/lib/commands/pg/connection-pooling/attach.js +5 -6
  15. package/lib/commands/pg/copy.js +6 -7
  16. package/lib/commands/pg/credentials/create.js +4 -4
  17. package/lib/commands/pg/credentials/destroy.js +4 -4
  18. package/lib/commands/pg/credentials/repair-default.js +4 -4
  19. package/lib/commands/pg/credentials/rotate.js +4 -4
  20. package/lib/commands/pg/credentials/url.js +4 -4
  21. package/lib/commands/pg/credentials.js +4 -4
  22. package/lib/commands/pg/diagnose.js +6 -5
  23. package/lib/commands/pg/info.js +5 -3
  24. package/lib/commands/pg/kill.js +6 -5
  25. package/lib/commands/pg/killall.js +4 -4
  26. package/lib/commands/pg/links/create.js +10 -8
  27. package/lib/commands/pg/links/destroy.js +4 -4
  28. package/lib/commands/pg/links/index.js +14 -8
  29. package/lib/commands/pg/locks.js +5 -4
  30. package/lib/commands/pg/maintenance/index.js +4 -4
  31. package/lib/commands/pg/maintenance/run.js +4 -4
  32. package/lib/commands/pg/maintenance/window.js +4 -4
  33. package/lib/commands/pg/outliers.d.ts +2 -2
  34. package/lib/commands/pg/outliers.js +9 -7
  35. package/lib/commands/pg/promote.js +5 -4
  36. package/lib/commands/pg/ps.js +6 -5
  37. package/lib/commands/pg/psql.js +6 -4
  38. package/lib/commands/pg/pull.d.ts +1 -1
  39. package/lib/commands/pg/pull.js +4 -4
  40. package/lib/commands/pg/push.d.ts +1 -1
  41. package/lib/commands/pg/push.js +4 -4
  42. package/lib/commands/pg/reset.js +4 -4
  43. package/lib/commands/pg/settings/index.js +2 -2
  44. package/lib/commands/pg/unfollow.js +5 -5
  45. package/lib/commands/pg/upgrade/cancel.js +5 -5
  46. package/lib/commands/pg/upgrade/dryrun.js +5 -5
  47. package/lib/commands/pg/upgrade/index.js +5 -5
  48. package/lib/commands/pg/upgrade/prepare.js +5 -5
  49. package/lib/commands/pg/upgrade/run.js +5 -5
  50. package/lib/commands/pg/upgrade/wait.js +9 -4
  51. package/lib/commands/pg/vacuum-stats.js +5 -4
  52. package/lib/commands/pg/wait.js +6 -4
  53. package/lib/commands/run/detached.d.ts +1 -0
  54. package/lib/commands/run/detached.js +5 -1
  55. package/lib/commands/run/index.d.ts +1 -0
  56. package/lib/commands/run/index.js +7 -2
  57. package/lib/commands/run/inside.js +1 -6
  58. package/lib/lib/addons/resolve.d.ts +6 -7
  59. package/lib/lib/pg/backups.js +4 -4
  60. package/lib/lib/pg/fetcher.d.ts +3 -34
  61. package/lib/lib/pg/fetcher.js +3 -92
  62. package/lib/lib/pg/psql.d.ts +5 -36
  63. package/lib/lib/pg/psql.js +17 -195
  64. package/lib/lib/pg/push_pull.d.ts +2 -7
  65. package/lib/lib/pg/push_pull.js +9 -7
  66. package/lib/lib/pg/setter.js +3 -3
  67. package/lib/lib/pg/types.d.ts +10 -15
  68. package/lib/lib/pg/util.d.ts +6 -32
  69. package/lib/lib/pg/util.js +3 -70
  70. package/lib/lib/run/helpers.d.ts +10 -0
  71. package/lib/lib/run/helpers.js +22 -1
  72. package/oclif.manifest.json +42 -30
  73. package/package.json +5 -7
  74. package/lib/lib/pg/bastion.d.ts +0 -29
  75. package/lib/lib/pg/bastion.js +0 -121
  76. package/lib/lib/pg/config.d.ts +0 -2
  77. package/lib/lib/pg/config.js +0 -13
  78. package/lib/lib/pg/host.d.ts +0 -1
  79. package/lib/lib/pg/host.js +0 -6
@@ -1,20 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePostgresConnectionString = exports.databaseNameFromUrl = exports.configVarNamesFromValue = exports.bastionKeyPlan = exports.getConnectionDetails = exports.presentCredentialAttachments = exports.formatResponseWithCommands = exports.getConfigVarNameFromAttachment = exports.essentialPlan = exports.legacyEssentialPlan = exports.essentialNumPlan = exports.getConfigVarName = void 0;
3
+ exports.databaseNameFromUrl = exports.configVarNamesFromValue = exports.presentCredentialAttachments = exports.formatResponseWithCommands = exports.essentialPlan = exports.legacyEssentialPlan = exports.essentialNumPlan = void 0;
4
4
  const color_1 = require("@heroku-cli/color");
5
5
  const core_1 = require("@oclif/core");
6
- const debug_1 = require("debug");
7
6
  const addons_1 = require("../../commands/addons");
8
7
  const multisort_1 = require("../utils/multisort");
9
- const bastion_1 = require("./bastion");
10
- const process_1 = require("process");
11
- function getConfigVarName(configVars) {
12
- const connStringVars = configVars.filter(cv => (cv.endsWith('_URL')));
13
- if (connStringVars.length === 0)
14
- throw new Error('Database URL not found for this addon');
15
- return connStringVars[0];
16
- }
17
- exports.getConfigVarName = getConfigVarName;
8
+ const heroku_cli_util_1 = require("@heroku/heroku-cli-util");
18
9
  const essentialNumPlan = (addon) => { var _a, _b; return Boolean((_b = (_a = addon === null || addon === void 0 ? void 0 : addon.plan) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.split(':')[1].match(/^essential/)); };
19
10
  exports.essentialNumPlan = essentialNumPlan;
20
11
  const legacyEssentialPlan = (addon) => { var _a, _b; return Boolean((_b = (_a = addon === null || addon === void 0 ? void 0 : addon.plan) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.split(':')[1].match(/(dev|basic|mini)$/)); };
@@ -23,22 +14,6 @@ function essentialPlan(addon) {
23
14
  return (0, exports.essentialNumPlan)(addon) || (0, exports.legacyEssentialPlan)(addon);
24
15
  }
25
16
  exports.essentialPlan = essentialPlan;
26
- function getConfigVarNameFromAttachment(attachment, config = {}) {
27
- var _a, _b;
28
- const configVars = (_b = (_a = attachment.config_vars) === null || _a === void 0 ? void 0 : _a.filter((cv) => {
29
- var _a;
30
- return (_a = config[cv]) === null || _a === void 0 ? void 0 : _a.startsWith('postgres://');
31
- })) !== null && _b !== void 0 ? _b : [];
32
- if (configVars.length === 0) {
33
- core_1.ux.error(`No config vars found for ${attachment.name}; perhaps they were removed as a side effect of ${color_1.default.cmd('heroku rollback')}? Use ${color_1.default.cmd('heroku addons:attach')} to create a new attachment and then ${color_1.default.cmd('heroku addons:detach')} to remove the current attachment.`);
34
- }
35
- const configVarName = `${attachment.name}_URL`;
36
- if (configVars.includes(configVarName) && configVarName in config) {
37
- return configVarName;
38
- }
39
- return getConfigVarName(configVars);
40
- }
41
- exports.getConfigVarNameFromAttachment = getConfigVarNameFromAttachment;
42
17
  function formatResponseWithCommands(response) {
43
18
  return response.replace(/`(.*?)`/g, (_, word) => color_1.default.cmd(word));
44
19
  }
@@ -102,33 +77,6 @@ function presentCredentialAttachments(app, credAttachments, credentials, cred) {
102
77
  return [cred, ...attLines, ...rotationLines].join('\n');
103
78
  }
104
79
  exports.presentCredentialAttachments = presentCredentialAttachments;
105
- const getConnectionDetails = (attachment, configVars = {}) => {
106
- const connStringVar = getConfigVarNameFromAttachment(attachment, configVars);
107
- // remove _URL from the end of the config var name
108
- const baseName = connStringVar.slice(0, -4);
109
- // build the default payload for non-bastion dbs
110
- (0, debug_1.default)(`Using "${connStringVar}" to connect to your database…`);
111
- const conn = (0, exports.parsePostgresConnectionString)(configVars[connStringVar]);
112
- const payload = {
113
- user: conn.user,
114
- password: conn.password,
115
- database: conn.database,
116
- host: conn.host,
117
- port: conn.port,
118
- pathname: conn.pathname,
119
- url: conn.url,
120
- attachment,
121
- };
122
- // If bastion creds exist, graft it into the payload
123
- const bastion = (0, bastion_1.getBastion)(configVars, baseName);
124
- if (bastion) {
125
- Object.assign(payload, bastion);
126
- }
127
- return payload;
128
- };
129
- exports.getConnectionDetails = getConnectionDetails;
130
- const bastionKeyPlan = (a) => Boolean(a.plan.name.match(/private/));
131
- exports.bastionKeyPlan = bastionKeyPlan;
132
80
  const configVarNamesFromValue = (config, value) => {
133
81
  const keys = [];
134
82
  for (const key of Object.keys(config)) {
@@ -166,22 +114,7 @@ const databaseNameFromUrl = (uri, config) => {
166
114
  if (name) {
167
115
  return color_1.default.configVar(name.replace(/_URL$/, ''));
168
116
  }
169
- const conn = (0, exports.parsePostgresConnectionString)(uri);
117
+ const conn = heroku_cli_util_1.utils.pg.DatabaseResolver.parsePostgresConnectionString(uri);
170
118
  return `${conn.host}:${conn.port}${conn.pathname}`;
171
119
  };
172
120
  exports.databaseNameFromUrl = databaseNameFromUrl;
173
- const parsePostgresConnectionString = (db) => {
174
- const dbPath = db.match(/:\/\//) ? db : `postgres:///${db}`;
175
- const url = new URL(dbPath);
176
- const { username, password, hostname, pathname, port } = url;
177
- return {
178
- user: username,
179
- password,
180
- database: pathname.charAt(0) === '/' ? pathname.slice(1) : pathname,
181
- host: hostname,
182
- port: port || process_1.env.PGPORT || (hostname && '5432'),
183
- pathname,
184
- url: dbPath,
185
- };
186
- };
187
- exports.parsePostgresConnectionString = parsePostgresConnectionString;
@@ -1,3 +1,13 @@
1
+ import type { APIClient } from '@heroku-cli/command';
1
2
  export declare function revertSortedArgs(processArgs: Array<string>, argv: Array<string>): string[];
2
3
  export declare function buildCommand(args: Array<string>, prependLauncher?: boolean): string;
3
4
  export declare function buildEnvFromFlag(flag: string): {};
5
+ /**
6
+ * Determines whether to prepend `launcher` to the command for a given app.
7
+ * Behavior: Only prepend on CNB stack apps and when not explicitly disabled.
8
+ */
9
+ export declare function shouldPrependLauncher(heroku: APIClient, appName: string, disableLauncher: boolean): Promise<boolean>;
10
+ /**
11
+ * Builds the command string, automatically deciding whether to prepend `launcher`.
12
+ */
13
+ export declare function buildCommandWithLauncher(heroku: APIClient, appName: string, args: string[], disableLauncher: boolean): Promise<string>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildEnvFromFlag = exports.buildCommand = exports.revertSortedArgs = void 0;
3
+ exports.buildCommandWithLauncher = exports.shouldPrependLauncher = exports.buildEnvFromFlag = exports.buildCommand = exports.revertSortedArgs = void 0;
4
4
  /* eslint-disable @typescript-eslint/ban-ts-comment */
5
5
  const core_1 = require("@oclif/core");
6
6
  // this function exists because oclif sorts argv
@@ -56,3 +56,24 @@ function buildEnvFromFlag(flag) {
56
56
  return env;
57
57
  }
58
58
  exports.buildEnvFromFlag = buildEnvFromFlag;
59
+ /**
60
+ * Determines whether to prepend `launcher` to the command for a given app.
61
+ * Behavior: Only prepend on CNB stack apps and when not explicitly disabled.
62
+ */
63
+ async function shouldPrependLauncher(heroku, appName, disableLauncher) {
64
+ if (disableLauncher)
65
+ return false;
66
+ const { body: app } = await heroku.get(`/apps/${appName}`, {
67
+ headers: { Accept: 'application/vnd.heroku+json; version=3.sdk' },
68
+ });
69
+ return (app.stack && app.stack.name) === 'cnb';
70
+ }
71
+ exports.shouldPrependLauncher = shouldPrependLauncher;
72
+ /**
73
+ * Builds the command string, automatically deciding whether to prepend `launcher`.
74
+ */
75
+ async function buildCommandWithLauncher(heroku, appName, args, disableLauncher) {
76
+ const prependLauncher = await shouldPrependLauncher(heroku, appName, disableLauncher);
77
+ return buildCommand(args, prependLauncher);
78
+ }
79
+ exports.buildCommandWithLauncher = buildCommandWithLauncher;
@@ -9399,6 +9399,12 @@
9399
9399
  "hasDynamicHelp": false,
9400
9400
  "multiple": false,
9401
9401
  "type": "option"
9402
+ },
9403
+ "no-launcher": {
9404
+ "description": "don’t prepend ‘launcher’ before a command",
9405
+ "name": "no-launcher",
9406
+ "allowNo": false,
9407
+ "type": "boolean"
9402
9408
  }
9403
9409
  },
9404
9410
  "hasDynamicHelp": false,
@@ -9419,7 +9425,7 @@
9419
9425
  "run": {
9420
9426
  "aliases": [],
9421
9427
  "args": {},
9422
- "description": "run a one-off process inside a heroku dyno\nShows a notification if the dyno takes more than 20 seconds to start.",
9428
+ "description": "run a one-off process inside a heroku dyno\nShows a notification if the dyno takes more than 20 seconds to start.\nHeroku automatically prepends ‘launcher’ to the command on CNB apps (use --no-launcher to disable).",
9423
9429
  "examples": [
9424
9430
  "$ heroku run bash",
9425
9431
  "$ heroku run -s standard-2x -- myscript.sh -a arg1 -s arg2"
@@ -9490,6 +9496,12 @@
9490
9496
  "name": "no-notify",
9491
9497
  "allowNo": false,
9492
9498
  "type": "boolean"
9499
+ },
9500
+ "no-launcher": {
9501
+ "description": "don’t prepend ‘launcher’ before a command",
9502
+ "name": "no-launcher",
9503
+ "allowNo": false,
9504
+ "type": "boolean"
9493
9505
  }
9494
9506
  },
9495
9507
  "hasDynamicHelp": false,
@@ -9635,34 +9647,6 @@
9635
9647
  "index.js"
9636
9648
  ]
9637
9649
  },
9638
- "teams": {
9639
- "aliases": [],
9640
- "args": {},
9641
- "description": "list the teams that you are a member of\n\nUse heroku members:* to manage team members.",
9642
- "flags": {
9643
- "json": {
9644
- "description": "output in json format",
9645
- "name": "json",
9646
- "allowNo": false,
9647
- "type": "boolean"
9648
- }
9649
- },
9650
- "hasDynamicHelp": false,
9651
- "hiddenAliases": [],
9652
- "id": "teams",
9653
- "pluginAlias": "heroku",
9654
- "pluginName": "heroku",
9655
- "pluginType": "core",
9656
- "strict": true,
9657
- "topic": "teams",
9658
- "isESM": false,
9659
- "relativePath": [
9660
- "lib",
9661
- "commands",
9662
- "teams",
9663
- "index.js"
9664
- ]
9665
- },
9666
9650
  "spaces:create": {
9667
9651
  "aliases": [],
9668
9652
  "args": {
@@ -10171,6 +10155,34 @@
10171
10155
  "wait.js"
10172
10156
  ]
10173
10157
  },
10158
+ "teams": {
10159
+ "aliases": [],
10160
+ "args": {},
10161
+ "description": "list the teams that you are a member of\n\nUse heroku members:* to manage team members.",
10162
+ "flags": {
10163
+ "json": {
10164
+ "description": "output in json format",
10165
+ "name": "json",
10166
+ "allowNo": false,
10167
+ "type": "boolean"
10168
+ }
10169
+ },
10170
+ "hasDynamicHelp": false,
10171
+ "hiddenAliases": [],
10172
+ "id": "teams",
10173
+ "pluginAlias": "heroku",
10174
+ "pluginName": "heroku",
10175
+ "pluginType": "core",
10176
+ "strict": true,
10177
+ "topic": "teams",
10178
+ "isESM": false,
10179
+ "relativePath": [
10180
+ "lib",
10181
+ "commands",
10182
+ "teams",
10183
+ "index.js"
10184
+ ]
10185
+ },
10174
10186
  "telemetry:add": {
10175
10187
  "aliases": [],
10176
10188
  "args": {
@@ -15007,5 +15019,5 @@
15007
15019
  ]
15008
15020
  }
15009
15021
  },
15010
- "version": "10.13.2-beta.0"
15022
+ "version": "10.13.3-beta.0"
15011
15023
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "heroku",
3
3
  "description": "CLI to interact with Heroku",
4
- "version": "10.13.2-beta.0",
4
+ "version": "10.13.3-beta.0",
5
5
  "author": "Heroku",
6
6
  "bin": "./bin/run",
7
7
  "bugs": "https://github.com/heroku/cli/issues",
@@ -13,7 +13,7 @@
13
13
  "@heroku-cli/schema": "^1.0.25",
14
14
  "@heroku/buildpack-registry": "^1.0.1",
15
15
  "@heroku/eventsource": "^1.0.7",
16
- "@heroku/heroku-cli-util": "^9.0.2",
16
+ "@heroku/heroku-cli-util": "^9.1.3",
17
17
  "@heroku/http-call": "^5.5.0",
18
18
  "@heroku/mcp-server": "1.0.7-alpha.1",
19
19
  "@heroku/plugin-ai": "^1.0.1",
@@ -36,7 +36,6 @@
36
36
  "@opentelemetry/sdk-trace-node": "^1.15.1",
37
37
  "@opentelemetry/semantic-conventions": "^1.24.1",
38
38
  "@types/js-yaml": "^3.12.5",
39
- "@types/tunnel-ssh": "4.1.1",
40
39
  "ansi-escapes": "3.2.0",
41
40
  "async-file": "^2.0.2",
42
41
  "bytes": "^3.1.2",
@@ -62,7 +61,7 @@
62
61
  "printf": "0.6.1",
63
62
  "psl": "^1.9.0",
64
63
  "redis-parser": "^3.0.0",
65
- "rollbar": "^2.26.2",
64
+ "rollbar": "^2.26.4",
66
65
  "semver": "7.6.1",
67
66
  "shell-escape": "^0.2.0",
68
67
  "shell-quote": "^1.8.1",
@@ -76,7 +75,6 @@
76
75
  "true-myth": "2.2.3",
77
76
  "tsheredoc": "^1.0.1",
78
77
  "tslib": "1.14.1",
79
- "tunnel-ssh": "4.1.6",
80
78
  "urijs": "^1.19.11",
81
79
  "validator": "^13.7.0",
82
80
  "word-wrap": "^1.2.5",
@@ -344,7 +342,7 @@
344
342
  },
345
343
  "update": {
346
344
  "node": {
347
- "version": "20.19.4"
345
+ "version": "20.19.5"
348
346
  },
349
347
  "s3": {
350
348
  "xz": true,
@@ -400,5 +398,5 @@
400
398
  "version": "oclif readme --multi && git add README.md ../../docs"
401
399
  },
402
400
  "types": "lib/index.d.ts",
403
- "gitHead": "9b0be97ff1e81738dd9b1d68c23634d85bd8a764"
401
+ "gitHead": "ab7b708ba071c64166847e53632d8fe71f3ea39a"
404
402
  }
@@ -1,29 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { APIClient } from '@heroku-cli/command';
4
- import * as createTunnel from 'tunnel-ssh';
5
- import { ConnectionDetails } from './util';
6
- export declare const getBastion: (config: Record<string, string>, baseName: string) => {
7
- bastionHost: string;
8
- bastionKey: string;
9
- } | {
10
- bastionHost?: undefined;
11
- bastionKey?: undefined;
12
- };
13
- export declare const env: (db: ConnectionDetails) => {
14
- PGAPPNAME: string;
15
- PGSSLMODE: string;
16
- } & NodeJS.ProcessEnv;
17
- export declare type TunnelConfig = createTunnel.Config;
18
- export declare function tunnelConfig(db: ConnectionDetails): TunnelConfig;
19
- export declare function getConfigs(db: ConnectionDetails): {
20
- dbEnv: NodeJS.ProcessEnv;
21
- dbTunnelConfig: createTunnel.Config;
22
- };
23
- export declare function sshTunnel(db: ConnectionDetails, dbTunnelConfig: TunnelConfig, timeout?: number): Promise<void | import("net").Server | null>;
24
- export declare function fetchConfig(heroku: APIClient, db: {
25
- id: string;
26
- }): Promise<import("@heroku/http-call").HTTP<{
27
- host: string;
28
- private_key: string;
29
- }>>;
@@ -1,121 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchConfig = exports.sshTunnel = exports.getConfigs = exports.tunnelConfig = exports.env = exports.getBastion = void 0;
4
- const debug = require('debug')('pg');
5
- const EventEmitter = require("node:events");
6
- const createTunnel = require("tunnel-ssh");
7
- const util_1 = require("util");
8
- const host_1 = require("./host");
9
- const core_1 = require("@oclif/core");
10
- const getBastion = function (config, baseName) {
11
- // If there are bastions, extract a host and a key
12
- // otherwise, return an empty Object
13
- // If there are bastions:
14
- // * there should be one *_BASTION_KEY
15
- // * pick one host from the comma-separated list in *_BASTIONS
16
- // We assert that _BASTIONS and _BASTION_KEY always exist together
17
- // If either is falsy, pretend neither exist
18
- const bastionKey = config[`${baseName}_BASTION_KEY`];
19
- const bastions = (config[`${baseName}_BASTIONS`] || '').split(',');
20
- const bastionHost = bastions[Math.floor(Math.random() * bastions.length)];
21
- return (bastionKey && bastionHost) ? { bastionHost, bastionKey } : {};
22
- };
23
- exports.getBastion = getBastion;
24
- const env = (db) => {
25
- const baseEnv = Object.assign({
26
- PGAPPNAME: 'psql non-interactive',
27
- PGSSLMODE: (!db.host || db.host === 'localhost') ? 'prefer' : 'require',
28
- }, process.env);
29
- const mapping = {
30
- PGUSER: 'user',
31
- PGPASSWORD: 'password',
32
- PGDATABASE: 'database',
33
- PGPORT: 'port',
34
- PGHOST: 'host',
35
- };
36
- Object.keys(mapping).forEach(envVar => {
37
- const val = db[mapping[envVar]];
38
- if (val) {
39
- baseEnv[envVar] = val;
40
- }
41
- });
42
- return baseEnv;
43
- };
44
- exports.env = env;
45
- function tunnelConfig(db) {
46
- const localHost = '127.0.0.1';
47
- const localPort = Math.floor((Math.random() * (65535 - 49152)) + 49152);
48
- return {
49
- username: 'bastion',
50
- host: db.bastionHost,
51
- privateKey: db.bastionKey,
52
- dstHost: db.host || undefined,
53
- dstPort: (db.port && Number.parseInt(db.port, 10)) || undefined,
54
- localHost,
55
- localPort,
56
- };
57
- }
58
- exports.tunnelConfig = tunnelConfig;
59
- function getConfigs(db) {
60
- const dbEnv = (0, exports.env)(db);
61
- const dbTunnelConfig = tunnelConfig(db);
62
- if (db.bastionKey) {
63
- Object.assign(dbEnv, {
64
- PGPORT: dbTunnelConfig.localPort,
65
- PGHOST: dbTunnelConfig.localHost,
66
- });
67
- }
68
- return {
69
- dbEnv,
70
- dbTunnelConfig,
71
- };
72
- }
73
- exports.getConfigs = getConfigs;
74
- class Timeout {
75
- constructor(timeout, message) {
76
- this.events = new EventEmitter();
77
- this.timeout = timeout;
78
- this.message = message;
79
- }
80
- async promise() {
81
- this.timer = setTimeout(() => {
82
- this.events.emit('error', new Error(this.message));
83
- }, this.timeout);
84
- try {
85
- await EventEmitter.once(this.events, 'cancelled');
86
- }
87
- finally {
88
- clearTimeout(this.timer);
89
- }
90
- }
91
- cancel() {
92
- this.events.emit('cancelled');
93
- }
94
- }
95
- async function sshTunnel(db, dbTunnelConfig, timeout = 10000) {
96
- if (!db.bastionKey) {
97
- return null;
98
- }
99
- const timeoutInstance = new Timeout(timeout, 'Establishing a secure tunnel timed out');
100
- const createSSHTunnel = (0, util_1.promisify)(createTunnel);
101
- try {
102
- return await Promise.race([
103
- timeoutInstance.promise(),
104
- createSSHTunnel(dbTunnelConfig),
105
- ]);
106
- }
107
- catch (error) {
108
- debug(error);
109
- core_1.ux.error('Unable to establish a secure tunnel to your database.');
110
- }
111
- finally {
112
- timeoutInstance.cancel();
113
- }
114
- }
115
- exports.sshTunnel = sshTunnel;
116
- async function fetchConfig(heroku, db) {
117
- return heroku.get(`/client/v11/databases/${encodeURIComponent(db.id)}/bastion`, {
118
- hostname: (0, host_1.default)(),
119
- });
120
- }
121
- exports.fetchConfig = fetchConfig;
@@ -1,2 +0,0 @@
1
- import type { APIClient } from '@heroku-cli/command';
2
- export declare function getConfig(heroku: APIClient, app: string): Promise<Record<string, string> | undefined>;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfig = void 0;
4
- const responseByAppId = new Map();
5
- async function getConfig(heroku, app) {
6
- if (!responseByAppId.has(app)) {
7
- const promise = heroku.get(`/apps/${app}/config-vars`);
8
- responseByAppId.set(app, promise);
9
- }
10
- const result = await responseByAppId.get(app);
11
- return result === null || result === void 0 ? void 0 : result.body;
12
- }
13
- exports.getConfig = getConfig;
@@ -1 +0,0 @@
1
- export default function (): string;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- function default_1() {
4
- return process.env.HEROKU_DATA_HOST || 'api.data.heroku.com';
5
- }
6
- exports.default = default_1;