Skip to content
Snippets Groups Projects
Unverified Commit 7905f345 authored by Gustavo Saiani's avatar Gustavo Saiani Committed by GitHub
Browse files

Update logic to hide db add/edit fields (#17845)

parent 86e196b9
No related branches found
No related tags found
No related merge requests found
......@@ -206,32 +206,18 @@ function getEngineInfo(engine, details, id) {
}
}
function isHiddenField(field, details) {
// NOTE: special case to hide tunnel settings if tunnel is disabled
const isDisabledTunnelSettingsField =
field.name.startsWith("tunnel-") &&
field.name !== "tunnel-enabled" &&
!details["tunnel-enabled"];
function shouldShowEngineProvidedField(field, details) {
const detailAndValueRequiredToShowField = field["visible-if"];
// hide the auth settings based on which auth method is selected
// private key auth needs tunnel-private-key and tunnel-private-key-passphrase
const isTunnelPrivateFieldWithoutProperAuthMethod =
field.name.startsWith("tunnel-private-") &&
details["tunnel-auth-option"] !== "ssh-key";
if (detailAndValueRequiredToShowField) {
const [detail, expectedDetailValue] = Object.entries(
detailAndValueRequiredToShowField,
)[0];
// username / password auth uses tunnel-pass
const isTunnelPassFieldWithoutProperAuthMethod =
field.name === "tunnel-pass" && details["tunnel-auth-option"] === "ssh-key";
// NOTE: special case to hide the SSL cert field if SSL is disabled
const isDisabledSslField = field.name === "ssl-cert" && !details["ssl"];
return details[detail] === expectedDetailValue;
}
return (
isDisabledTunnelSettingsField ||
isTunnelPrivateFieldWithoutProperAuthMethod ||
isTunnelPassFieldWithoutProperAuthMethod ||
isDisabledSslField
);
return true;
}
function getDefaultValue(field) {
......@@ -257,7 +243,7 @@ function getEngineFormFields(engine, details, id) {
// convert database details-fields to Form fields
return engineFields
.filter(field => !isHiddenField(field, details))
.filter(field => shouldShowEngineProvidedField(field, details))
.map(field => {
const overrides = DATABASE_DETAIL_OVERRIDES[field.name];
......
......@@ -38,6 +38,9 @@ driver:
- name: ssl-cert
type: string
display-name: Server SSL certificate chain
visible-if:
ssl: true
connection-properties-include-tunnel-config: true
init:
- step: load-namespace
......
......@@ -79,7 +79,9 @@
"Server SSL certificate chain, in PEM format."
{:name "ssl-cert"
:display-name (deferred-tru "Server SSL certificate chain")
:placeholder ""})
:placeholder ""
:visible-if {"ssl" true}}
)
(defmethod driver/connection-properties :mysql
[_]
......
......@@ -80,36 +80,43 @@
{:name "tunnel-host"
:display-name "SSH tunnel host"
:placeholder "What hostname do you use to connect to the SSH tunnel?"
:required true}
:required true
:visible-if {"tunnel-enabled" true}}
{:name "tunnel-port"
:display-name "SSH tunnel port"
:type :integer
:default 22
:required false}
:required false
:visible-if {"tunnel-enabled" true}}
{:name "tunnel-user"
:display-name "SSH tunnel username"
:placeholder "What username do you use to login to the SSH tunnel?"
:required true}
:required true
:visible-if {"tunnel-enabled" true}}
;; this is entirely a UI flag
{:name "tunnel-auth-option"
:display-name "SSH Authentication"
:type :select
:options [{:name "SSH Key" :value "ssh-key"}
{:name "Password" :value "password"}]
:default "ssh-key"}
:default "ssh-key"
:visible-if {"tunnel-enabled" true}}
{:name "tunnel-pass"
:display-name "SSH tunnel password"
:type :password
:placeholder "******"}
:placeholder "******"
:visible-if {"tunnel-auth-option" "password"}}
{:name "tunnel-private-key"
:display-name "SSH private key to connect to the tunnel"
:type :string
:placeholder "Paste the contents of an ssh private key here"
:required true}
:required true
:visible-if {"tunnel-auth-option" "ssh-key"}}
{:name "tunnel-private-key-passphrase"
:display-name "Passphrase for SSH private key"
:type :password
:placeholder "******"}])
:placeholder "******"
:visible-if {"tunnel-auth-option" "ssh-key"}}])
(defn with-tunnel-config
"Add preferences for ssh tunnels to a drivers :connection-properties"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment