Merge branch 'master' into sqlite

This commit is contained in:
Jan Prochazka
2021-05-03 21:09:41 +02:00
3 changed files with 39 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
{ {
"private": true, "private": true,
"version": "4.1.11", "version": "4.1.12-beta.2",
"name": "dbgate-all", "name": "dbgate-all",
"workspaces": [ "workspaces": [
"packages/*", "packages/*",

View File

@@ -4,6 +4,8 @@ const portfinder = require('portfinder');
const stableStringify = require('json-stable-stringify'); const stableStringify = require('json-stable-stringify');
const _ = require('lodash'); const _ = require('lodash');
const platformInfo = require('./platformInfo'); const platformInfo = require('./platformInfo');
const AsyncLock = require('async-lock');
const lock = new AsyncLock();
const sshConnectionCache = {}; const sshConnectionCache = {};
const sshTunnelCache = {}; const sshTunnelCache = {};
@@ -45,8 +47,10 @@ async function getSshConnection(connection) {
} }
async function getSshTunnel(connection) { async function getSshTunnel(connection) {
const sshConn = await getSshConnection(connection);
const tunnelCacheKey = stableStringify(_.pick(connection, TUNNEL_FIELDS)); const tunnelCacheKey = stableStringify(_.pick(connection, TUNNEL_FIELDS));
return await lock.acquire(tunnelCacheKey, async () => {
const sshConn = await getSshConnection(connection);
if (sshTunnelCache[tunnelCacheKey]) return sshTunnelCache[tunnelCacheKey]; if (sshTunnelCache[tunnelCacheKey]) return sshTunnelCache[tunnelCacheKey];
const localPort = await portfinder.getPortPromise({ port: 10000, stopPort: 60000 }); const localPort = await portfinder.getPortPromise({ port: 10000, stopPort: 60000 });
@@ -58,6 +62,10 @@ async function getSshTunnel(connection) {
toHost: connection.server, toHost: connection.server,
}; };
try { try {
console.log(
`Creating SSH tunnel to ${connection.sshHost}-${connection.server}:${connection.port}, using local port ${localPort}`
);
const tunnel = await sshConn.forward(tunnelConfig); const tunnel = await sshConn.forward(tunnelConfig);
console.log( console.log(
`Created SSH tunnel to ${connection.sshHost}-${connection.server}:${connection.port}, using local port ${localPort}` `Created SSH tunnel to ${connection.sshHost}-${connection.server}:${connection.port}, using local port ${localPort}`
@@ -75,6 +83,7 @@ async function getSshTunnel(connection) {
message: err.message, message: err.message,
}; };
} }
});
} }
module.exports = { module.exports = {

View File

@@ -2,10 +2,12 @@
import { getFormContext } from './FormProviderCore.svelte'; import { getFormContext } from './FormProviderCore.svelte';
import SelectField from './SelectField.svelte'; import SelectField from './SelectField.svelte';
import { createEventDispatcher } from 'svelte'; import { createEventDispatcher } from 'svelte';
import _ from 'lodash';
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
export let name; export let name;
export let options;
export let isClearable = false; export let isClearable = false;
const { values, setFieldValue } = getFormContext(); const { values, setFieldValue } = getFormContext();
@@ -14,6 +16,7 @@
<SelectField <SelectField
{...$$restProps} {...$$restProps}
value={$values[name]} value={$values[name]}
options={_.compact(options)}
on:change={e => { on:change={e => {
setFieldValue(name, e.detail); setFieldValue(name, e.detail);
dispatch('change', e.detail); dispatch('change', e.detail);