Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore(frontend): use `useSsl` in instance form (#12677)

boojack29d2d55b021a
diff --git a/backend/store/data_source.go b/backend/store/data_source.go
index 986da77bcb..3396625324 100644
--- a/backend/store/data_source.go
+++ b/backend/store/data_source.go
@@ -374,7 +374,7 @@ func (s *Store) UpdateDataSourceV2(ctx context.Context, patch *UpdateDataSourceM
optionSet, args = append(optionSet, fmt.Sprintf("jsonb_build_object('warehouseId', $%d::TEXT)", len(args)+1)), append(args, *v)
}
if v := patch.UseSSL; v != nil {
- optionSet, args = append(optionSet, fmt.Sprintf("jsonb_build_object('useSsl', $%d::TEXT)", len(args)+1)), append(args, *v)
+ optionSet, args = append(optionSet, fmt.Sprintf("jsonb_build_object('useSsl', $%d::BOOLEAN)", len(args)+1)), append(args, *v)
}
if len(optionSet) != 0 {
set = append(set, fmt.Sprintf(`options = options || %s`, strings.Join(optionSet, "||")))
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
index 9d5e265661..21a8d4670b 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
@@ -712,22 +712,19 @@ MIIEvQ...
"
class="mt-4 sm:col-span-3 sm:col-start-1"
>
- <div class="flex flex-row items-center">
+ <div class="flex flex-row items-center gap-2">
+ <NSwitch
+ :value="dataSource.useSsl"
+ size="small"
+ @update:value="handleUseSslChanged"
+ />
<label for="ssl" class="textlabel block">
{{ $t("data-source.ssl-connection") }}
</label>
</div>
- <template v-if="dataSource.pendingCreate">
- <SslCertificateForm
- :value="dataSource"
- :engine-type="basicInfo.engine"
- :disabled="!allowEdit"
- @change="handleSSLChange"
- />
- </template>
- <template v-else>
- <template v-if="dataSource.updateSsl">
- <SslCertificateForm
+ <template v-if="dataSource.useSsl">
+ <template v-if="dataSource.pendingCreate">
+ <SslCertificateFormV1
:value="dataSource"
:engine-type="basicInfo.engine"
:disabled="!allowEdit"
@@ -735,13 +732,23 @@ MIIEvQ...
/>
</template>
<template v-else>
- <NButton
- class="!mt-2"
- :disabled="!allowEdit"
- @click.prevent="handleEditSSL"
- >
- {{ $t("common.edit") }} - {{ $t("common.write-only") }}
- </NButton>
+ <template v-if="dataSource.updateSsl">
+ <SslCertificateFormV1
+ :value="dataSource"
+ :engine-type="basicInfo.engine"
+ :disabled="!allowEdit"
+ @change="handleSSLChange"
+ />
+ </template>
+ <template v-else>
+ <NButton
+ class="!mt-2"
+ :disabled="!allowEdit"
+ @click.prevent="handleEditSSL"
+ >
+ {{ $t("common.edit") }} - {{ $t("common.write-only") }}
+ </NButton>
+ </template>
</template>
</template>
</div>
@@ -802,6 +809,7 @@ import {
NUpload,
NUploadDragger,
type UploadFileInfo,
+ NSwitch,
} from "naive-ui";
import { watch, reactive, computed, ref } from "vue";
import { useI18n } from "vue-i18n";
@@ -823,7 +831,7 @@ import type { EditDataSource } from "../common";
import { useInstanceFormContext } from "../context";
import GcpCredentialInput from "./GcpCredentialInput.vue";
import SshConnectionForm from "./SshConnectionForm.vue";
-import SslCertificateForm from "./SslCertificateForm.vue";
+import SslCertificateFormV1 from "./SslCertificateFormV1.vue";
interface LocalState {
passwordType: DataSourceExternalSecret_SecretType;
@@ -1030,6 +1038,13 @@ const handlePortInput = (value: string) => {
}
ds.port = value.trim();
};
+
+const handleUseSslChanged = (useSSL: boolean) => {
+ const ds = props.dataSource;
+ ds.useSsl = useSSL;
+ ds.updateSsl = true;
+};
+
const handleEditSSL = () => {
const ds = props.dataSource;
ds.sslCa = "";
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateFormV1.vue
similarity index 52%
rename from frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
rename to frontend/src/components/InstanceForm/DataSourceSection/SslCertificateFormV1.vue
index b4ee858e9a..8476aa4d24 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateFormV1.vue
@@ -1,32 +1,5 @@
<template>
- <NRadioGroup
- v-model:value="state.type"
- :disabled="disabled"
- class="!flex flex-row items-center gap-x-4 mt-2"
- >
- <NRadio
- v-for="type in sslTypeCandidatesOfEngine(props.engineType)"
- :key="type"
- :value="type"
- >
- <span class="textlabel">{{ getSslTypeLabel(type) }}</span>
- </NRadio>
- </NRadioGroup>
-
- <DroppableTextarea
- v-if="state.type === 'CA'"
- v-model:value="state.value.sslCa"
- :resizable="false"
- :disabled="disabled"
- class="w-full h-24 mt-4 whitespace-pre-wrap"
- placeholder="Input or drag and drop YOUR_CA_CERTIFICATE"
- />
- <NTabs
- v-else-if="state.type === 'CA+KEY+CERT'"
- v-model:value="state.tab"
- class="mt-2"
- pane-style="padding-top: 0.25rem"
- >
+ <NTabs :default-value="'CA'" class="mt-2" pane-style="padding-top: 0.25rem">
<NTabPane
name="CA"
:tab="$t('data-source.ssl.ca-cert')"
@@ -41,7 +14,7 @@
/>
</NTabPane>
<NTabPane
- v-if="state.type === 'CA+KEY+CERT'"
+ v-if="hasSSLKeyField"
name="KEY"
:tab="$t('data-source.ssl.client-key')"
display-directive="show"
@@ -55,7 +28,7 @@
/>
</NTabPane>
<NTabPane
- v-if="state.type === 'CA+KEY+CERT'"
+ v-if="hasSSLCertField"
name="CERT"
:tab="$t('data-source.ssl.client-cert')"
display-directive="show"
@@ -73,21 +46,16 @@
<script lang="ts" setup>
import { cloneDeep } from "lodash-es";
-import { NTabs, NTabPane, NRadio, NRadioGroup } from "naive-ui";
-import { reactive, watch } from "vue";
-import { useI18n } from "vue-i18n";
+import { NTabs, NTabPane } from "naive-ui";
+import { computed, reactive, watch } from "vue";
import DroppableTextarea from "@/components/misc/DroppableTextarea.vue";
import { Engine } from "@/types/proto/v1/common";
import type { DataSource } from "@/types/proto/v1/instance_service";
-type SslType = "NONE" | "CA" | "CA+KEY+CERT";
-
type WithSslOptions = Partial<Pick<DataSource, "sslCa" | "sslCert" | "sslKey">>;
type LocalState = {
- type: SslType;
value: WithSslOptions;
- tab: "CA" | "KEY" | "CERT";
};
const props = defineProps<{
@@ -100,23 +68,26 @@ const emit = defineEmits<{
(e: "change", value: WithSslOptions): void;
}>();
-const { t } = useI18n();
-
const state = reactive<LocalState>({
- type: guessSslType(props.value),
value: {
sslCa: props.value.sslCa,
sslCert: props.value.sslCert,
sslKey: props.value.sslKey,
},
- tab: "CA",
+});
+
+const hasSSLKeyField = computed(() => {
+ return ![Engine.MONGODB, Engine.MSSQL].includes(props.engineType);
+});
+
+const hasSSLCertField = computed(() => {
+ return ![Engine.MONGODB, Engine.MSSQL].includes(props.engineType);
});
// Sync the latest version to local state when props.value changed.
watch(
() => props.value,
(newValue) => {
- state.type = guessSslType(newValue);
state.value = {
sslCa: newValue.sslCa,
sslCert: newValue.sslCert,
@@ -133,44 +104,4 @@ watch(
},
{ deep: true }
);
-
-watch(
- () => state.type,
- (type) => {
- if (type === "NONE") {
- state.value.sslCa = "";
- state.value.sslCert = "";
- state.value.sslKey = "";
- } else if (type === "CA") {
- state.value.sslCert = "";
- state.value.sslKey = "";
- state.tab = "CA";
- }
- }
-);
-
-function getSslTypeLabel(type: SslType): string {
- if (type === "CA") {
- return t("data-source.ssl-type.ca");
- }
- if (type === "CA+KEY+CERT") {
- return t("data-source.ssl-type.ca-and-key-and-cert");
- }
- return t("data-source.ssl-type.none");
-}
-
-function guessSslType(value: WithSslOptions): SslType {
- if (value.sslCa) {
- if (value.sslCert && value.sslKey) return "CA+KEY+CERT";
- return "CA";
- }
- return "NONE";
-}
-
-function sslTypeCandidatesOfEngine(engineType: Engine): SslType[] {
- if (engineType === Engine.MONGODB || engineType === Engine.MSSQL) {
- return ["NONE", "CA"];
- }
- return ["NONE", "CA", "CA+KEY+CERT"];
-}
</script>
diff --git a/frontend/src/components/InstanceForm/common.ts b/frontend/src/components/InstanceForm/common.ts
index 234aa50c06..49ac6bf88f 100644
--- a/frontend/src/components/InstanceForm/common.ts
+++ b/frontend/src/components/InstanceForm/common.ts
@@ -110,6 +110,7 @@ export const calcDataSourceUpdateMask = (
updateMask.add("password");
}
if (updateSsl) {
+ updateMask.add("use_ssl");
updateMask.add("ssl_ca");
updateMask.add("ssl_key");
updateMask.add("ssl_cert");