From 88b4c9daff8a1866afc439ac44809a5e5d17eda5 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sat, 10 Apr 2021 10:47:36 +0200 Subject: [PATCH] custom DB URI support (used by Mongo) --- packages/api/src/utility/connectUtility.js | 4 + packages/types/engines.d.ts | 2 + .../web/src/forms/FormRadioGroupField.svelte | 22 +++ .../web/src/modals/ConnectionModal.svelte | 6 +- .../modals/ConnectionModalDriverFields.svelte | 141 +++++++++++------- .../modals/ConnectionModalSslFields.svelte | 6 + 6 files changed, 124 insertions(+), 57 deletions(-) create mode 100644 packages/web/src/forms/FormRadioGroupField.svelte diff --git a/packages/api/src/utility/connectUtility.js b/packages/api/src/utility/connectUtility.js index 48ff303c..81f7cf0c 100644 --- a/packages/api/src/utility/connectUtility.js +++ b/packages/api/src/utility/connectUtility.js @@ -38,6 +38,10 @@ async function connectUtility(driver, storedConnection) { connection.ssl.key = await fs.readFile(connection.sslKeyFile); } + if (connection.sslCertFilePassword) { + connection.ssl.password = connection.sslCertFilePassword; + } + if (!connection.ssl.key && !connection.ssl.ca && !connection.ssl.cert) { // TODO: provide this as an option in settings // or per-connection as 'reject self-signed certs' diff --git a/packages/types/engines.d.ts b/packages/types/engines.d.ts index fb4fa5e6..0862fce8 100644 --- a/packages/types/engines.d.ts +++ b/packages/types/engines.d.ts @@ -37,6 +37,8 @@ export interface EngineDriver { engine: string; title: string; defaultPort?: number; + supportsDatabaseUrl?: boolean; + databaseUrlPlaceholder?: string; connect({ server, port, user, password, database }): any; query(pool: any, sql: string): Promise; stream(pool: any, sql: string, options: StreamOptions); diff --git a/packages/web/src/forms/FormRadioGroupField.svelte b/packages/web/src/forms/FormRadioGroupField.svelte new file mode 100644 index 00000000..387a6ff9 --- /dev/null +++ b/packages/web/src/forms/FormRadioGroupField.svelte @@ -0,0 +1,22 @@ + + +{#each optionsWithId as option} +
+ + +
+{/each} diff --git a/packages/web/src/modals/ConnectionModal.svelte b/packages/web/src/modals/ConnectionModal.svelte index ee8090ac..3fa8d3eb 100644 --- a/packages/web/src/modals/ConnectionModal.svelte +++ b/packages/web/src/modals/ConnectionModal.svelte @@ -86,7 +86,7 @@ {/if} {#if !isTesting && sqlConnectResult && sqlConnectResult.msgtype == 'error'} -
+
Connect failed: {sqlConnectResult.error}
@@ -113,4 +113,8 @@ overflow: hidden; text-overflow: ellipsis; } + + .error-result { + white-space: normal; + } diff --git a/packages/web/src/modals/ConnectionModalDriverFields.svelte b/packages/web/src/modals/ConnectionModalDriverFields.svelte index 55946900..3929e356 100644 --- a/packages/web/src/modals/ConnectionModalDriverFields.svelte +++ b/packages/web/src/modals/ConnectionModalDriverFields.svelte @@ -2,6 +2,7 @@ import FormPasswordField from '../forms/FormPasswordField.svelte'; import { getFormContext } from '../forms/FormProviderCore.svelte'; + import FormRadioGroupField from '../forms/FormRadioGroupField.svelte'; import FormSelectField from '../forms/FormSelectField.svelte'; import FormTextField from '../forms/FormTextField.svelte'; @@ -11,6 +12,7 @@ const { values } = getFormContext(); $: authType = $values.authType; $: engine = $values.engine; + $: useDatabaseUrl = $values.useDatabaseUrl; $: authTypes = useAuthTypes({ engine }); $: currentAuthType = $authTypes && $authTypes.find(x => x.name == authType); $: disabledFields = (currentAuthType ? currentAuthType.disabledFields : null) || []; @@ -29,65 +31,85 @@ ]} /> -{#if $authTypes} - ({ - value: auth.name, - label: auth.title, - }))} - /> +{#if driver?.supportsDatabaseUrl} +
+ +
{/if} -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -{#if !disabledFields.includes('password')} - +{:else} + {#if $authTypes} + ({ + value: auth.name, + label: auth.title, + }))} + /> + {/if} + +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + {#if !disabledFields.includes('password')} + + {/if} {/if} @@ -97,4 +119,11 @@ margin: var(--dim-large-form-margin); display: flex; } + .radio { + margin-left: var(--dim-large-form-margin); + display: flex; + } + .radio :global(label) { + margin-right: 10px; + } diff --git a/packages/web/src/modals/ConnectionModalSslFields.svelte b/packages/web/src/modals/ConnectionModalSslFields.svelte index 64e3c250..5b7cae50 100644 --- a/packages/web/src/modals/ConnectionModalSslFields.svelte +++ b/packages/web/src/modals/ConnectionModalSslFields.svelte @@ -5,6 +5,7 @@ import FormCheckboxField from '../forms/FormCheckboxField.svelte'; import getElectron from '../utility/getElectron'; + import FormPasswordField from '../forms/FormPasswordField.svelte'; const { values, setFieldValue } = getFormContext(); const electron = getElectron(); @@ -15,5 +16,10 @@ +