Skip to content

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

chore: optimize ssh config (#16425)

ecmadaof281c85d80ad
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index d319180a63..5a51888f21 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -1156,6 +1156,9 @@ func convertDataSources(dataSources []*storepb.DataSource) ([]*v1pb.DataSource,
AuthenticationDatabase: ds.GetAuthenticationDatabase(),
Sid: ds.GetSid(),
ServiceName: ds.GetServiceName(),
+ SshHost: ds.GetSshHost(),
+ SshPort: ds.GetSshPort(),
+ SshUser: ds.GetSshUser(),
ExternalSecret: externalSecret,
AuthenticationType: authenticationType,
SaslConfig: convertDataSourceSaslConfig(ds.GetSaslConfig()),
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
index 68a36f336a..26b84f1a77 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
@@ -826,10 +826,7 @@ MIIEvQ...
/>
</div>
- <div
- v-if="hasExtraParameters"
- class="mt-4 sm:col-span-3 sm:col-start-1"
- >
+ <div v-if="hasExtraParameters" class="mt-4 sm:col-span-3 sm:col-start-1">
<div class="flex flex-row items-center justify-between">
<label class="textlabel block">
{{ $t("data-source.extra-params.self") }}
@@ -838,9 +835,12 @@ MIIEvQ...
<div class="text-gray-400 text-sm mt-1 mb-2">
{{ $t("data-source.extra-params.description") }}
</div>
-
+
<!-- Add parameter form -->
- <div v-if="allowEdit" class="flex mt-2 mb-4 space-x-2 bg-gray-50 p-3 rounded-md">
+ <div
+ v-if="allowEdit"
+ class="flex mt-2 mb-4 space-x-2 bg-gray-50 p-3 rounded-md"
+ >
<NInput
v-model:value="newParam.key"
class="w-full"
@@ -851,8 +851,8 @@ MIIEvQ...
class="w-full"
:placeholder="$t('instance.parameter-value-placeholder')"
/>
- <NButton
- type="primary"
+ <NButton
+ type="primary"
ghost
size="small"
:disabled="!newParam.key.trim()"
@@ -861,11 +861,11 @@ MIIEvQ...
Add
</NButton>
</div>
-
+
<!-- Existing parameters -->
- <div
- v-for="(param, index) in extraConnectionParamsList"
- :key="param.key"
+ <div
+ v-for="(param, index) in extraConnectionParamsList"
+ :key="param.key"
class="flex mt-2 space-x-2"
>
<NInput
@@ -882,24 +882,28 @@ MIIEvQ...
placeholder="Parameter value"
@update:value="(v) => updateExtraConnectionParamValue(index, v)"
/>
- <NButton
+ <NButton
v-if="allowEdit"
- type="error"
+ type="error"
secondary
- size="small"
+ size="small"
@click="removeExtraConnectionParam(index)"
title="Remove parameter"
>
Remove
</NButton>
</div>
-
+
<!-- Show a message when there are no parameters -->
- <div
- v-if="extraConnectionParamsList.length === 0"
+ <div
+ v-if="extraConnectionParamsList.length === 0"
class="text-gray-500 text-sm mt-2 italic"
>
- {{ allowEdit ? $t('instance.no-params-yet-add-above') : $t('instance.no-extra-params-configured') }}
+ {{
+ allowEdit
+ ? $t("instance.no-params-yet-add-above")
+ : $t("instance.no-extra-params-configured")
+ }}
</div>
</div>
@@ -968,33 +972,12 @@ MIIEvQ...
:instance="instance"
/>
</div>
- <template v-if="dataSource.pendingCreate">
- <SshConnectionForm
- :value="dataSource"
- :instance="instance"
- :disabled="!allowEdit"
- @change="handleSSHChange"
- />
- </template>
- <template v-else>
- <template v-if="dataSource.updateSsh">
- <SshConnectionForm
- :value="dataSource"
- :instance="instance"
- :disabled="!allowEdit"
- @change="handleSSHChange"
- />
- </template>
- <template v-else>
- <NButton
- class="!mt-2"
- :disabled="!allowEdit"
- @click.prevent="handleEditSSH"
- >
- {{ $t("common.edit") }} - {{ $t("common.write-only") }}
- </NButton>
- </template>
- </template>
+ <SshConnectionForm
+ :value="dataSource"
+ :instance="instance"
+ :disabled="!allowEdit"
+ @change="handleSSHChange"
+ />
</div>
</template>
@@ -1095,10 +1078,9 @@ const newParam = reactive({ key: "", value: "" });
const extraConnectionParamsList = computed<ExtraConnectionParam[]>(() => {
// Ensure we're using a non-null object for the params
const params = props.dataSource.extraConnectionParameters || {};
-
+
// Convert to plain entries for display
- return Object.entries(params)
- .map(([key, value]) => ({ key, value }));
+ return Object.entries(params).map(([key, value]) => ({ key, value }));
});
const { t } = useI18n();
@@ -1306,17 +1288,6 @@ const handleEditSSL = () => {
ds.updateSsl = true;
};
-const handleEditSSH = () => {
- const ds = props.dataSource;
- if (!ds) return;
- ds.sshHost = "";
- ds.sshPort = "";
- ds.sshUser = "";
- ds.sshPassword = "";
- ds.sshPrivateKey = "";
- ds.updateSsh = true;
-};
-
const handleSSLChange = (
value: Partial<Pick<DataSource, "sslCa" | "sslCert" | "sslKey">>
) => {
@@ -1335,7 +1306,6 @@ const handleSSHChange = (
) => {
const ds = props.dataSource;
Object.assign(ds, value);
- ds.updateSsh = true;
};
watch(
@@ -1396,41 +1366,43 @@ const resetIAMExtension = () => {
const addNewParameter = () => {
// Skip if key is empty
if (!newParam.key.trim()) return;
-
+
const ds = props.dataSource;
-
+
// Get plain params object using our helper
const plainParams = createPlainParamsObject(ds.extraConnectionParameters);
-
+
// Add the new parameter
const trimmedKey = newParam.key.trim();
plainParams[trimmedKey] = newParam.value;
-
+
// Create a fresh object to ensure we're using a plain JS object
const freshParams: Record<string, string> = {};
- Object.keys(plainParams).forEach(key => {
+ Object.keys(plainParams).forEach((key) => {
freshParams[key] = plainParams[key];
});
-
+
// Set the object directly using a brand new object
ds.extraConnectionParameters = freshParams;
-
+
// Clear the form
newParam.key = "";
newParam.value = "";
};
// Helper function to create plain parameters object from existing parameters
-const createPlainParamsObject = (existingParams: Record<string, string> | undefined): Record<string, string> => {
+const createPlainParamsObject = (
+ existingParams: Record<string, string> | undefined
+): Record<string, string> => {
const plainParams: Record<string, string> = {};
-
+
if (existingParams) {
// Copy all properties from the potentially proxied object
Object.entries(existingParams).forEach(([key, value]) => {
plainParams[key] = value;
});
}
-
+
return plainParams;
};
@@ -1438,24 +1410,24 @@ const updateExtraConnectionParamKey = (index: number, newKey: string) => {
const ds = props.dataSource;
const params = extraConnectionParamsList.value;
if (index >= params.length) return;
-
+
// Get plain params object
const plainParams = createPlainParamsObject(ds.extraConnectionParameters);
-
+
const oldKey = params[index].key;
const value = params[index].value;
-
+
// Skip if the key hasn't changed
if (oldKey === newKey) return;
-
+
// Delete the old key
delete plainParams[oldKey];
-
+
// Only add if the key is not empty
if (newKey.trim()) {
plainParams[newKey] = value;
}
-
+
// Set the object directly
ds.extraConnectionParameters = plainParams;
};
@@ -1464,15 +1436,15 @@ const updateExtraConnectionParamValue = (index: number, newValue: string) => {
const ds = props.dataSource;
const params = extraConnectionParamsList.value;
if (index >= params.length) return;
-
+
const key = params[index].key;
-
+
// Get plain params object
const plainParams = createPlainParamsObject(ds.extraConnectionParameters);
-
+
// Update the value
plainParams[key] = newValue;
-
+
// Set the object directly
ds.extraConnectionParameters = plainParams;
};
@@ -1481,13 +1453,13 @@ const removeExtraConnectionParam = (index: number) => {
const ds = props.dataSource;
const params = extraConnectionParamsList.value;
if (index >= params.length) return;
-
+
// Get plain params object
const plainParams = createPlainParamsObject(ds.extraConnectionParameters);
-
+
// Remove the parameter
delete plainParams[params[index].key];
-
+
// Set the object directly
ds.extraConnectionParameters = plainParams;
};
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
index 8ad9698e94..fa12ee9d3e 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
@@ -12,7 +12,7 @@
</NRadio>
</div>
- <template v-if="state.type === 'TUNNEL' || state.type === 'TUNNEL+PK'">
+ <template v-if="state.type !== 'NONE'">
<div
class="sm:col-span-1 sm:col-start-1 mt-4 grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-4"
>
@@ -68,18 +68,17 @@
/>
</div>
</div>
- <div
- v-if="state.type === 'TUNNEL+PK'"
- class="mt-4 sm:col-span-3 sm:col-start-1"
- >
+ <div class="mt-4 sm:col-span-3 sm:col-start-1">
<div class="mt-2 sm:col-span-1 sm:col-start-1 flex flex-col">
<label for="sshPrivateKey" class="textlabel block">
{{ $t("data-source.ssh.ssh-key") }}
+ ({{ t("common.optional") }})
</label>
<DroppableTextarea
v-model:value="state.value.sshPrivateKey"
:resizable="false"
:disabled="disabled"
+ :placeholder="$t('common.write-only')"
class="w-full h-24 mt-2 whitespace-pre-wrap"
/>
</div>
@@ -95,7 +94,6 @@
</template>
<script lang="ts" setup>
-import { cloneDeep } from "lodash-es";
import { NInput, NRadio } from "naive-ui";
import { reactive, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
@@ -105,9 +103,9 @@ import { useSubscriptionV1Store } from "@/store";
import type { Instance } from "@/types/proto/v1/instance_service";
import { onlyAllowNumber } from "@/utils";
-const SshTypes = ["NONE", "TUNNEL", "TUNNEL+PK"] as const;
+const SshTypes = ["NONE", "TUNNEL+PK"] as const;
-type SshType = "NONE" | "TUNNEL" | "TUNNEL+PK";
+type SshType = (typeof SshTypes)[number];
type WithSshOptions = {
sshHost?: string;
@@ -120,7 +118,6 @@ type WithSshOptions = {
type LocalState = {
type: SshType;
value: WithSshOptions;
- tab: "TUNNEL" | "TUNNEL+PK";
showFeatureModal: boolean;
};
@@ -138,14 +135,7 @@ const { t } = useI18n();
const state = reactive<LocalState>({
type: guessSshType(props.value),
- value: {
- sshHost: props.value.sshHost,
- sshPort: props.value.sshPort,
- sshUser: props.value.sshUser,
- sshPassword: props.value.sshPassword,
- sshPrivateKey: props.value.sshPrivateKey,
- },
- tab: "TUNNEL",
+ value: {},
showFeatureModal: false,
});
@@ -182,6 +172,9 @@ watch(
sshPassword: props.value.sshPassword,
sshPrivateKey: props.value.sshPrivateKey,
};
+ },
+ {
+ immediate: true,
}
);
@@ -189,7 +182,7 @@ watch(
watch(
() => state.value,
(localValue) => {
- emit("change", cloneDeep(localValue));
+ emit("change", { ...localValue });
},
{ deep: true }
);
@@ -203,17 +196,11 @@ watch(
state.value.sshUser = "";
state.value.sshPassword = "";
state.value.sshPrivateKey = "";
- } else if (type === "TUNNEL") {
- state.value.sshPrivateKey = "";
- state.tab = "TUNNEL";
}
}
);
function getSshTypeLabel(type: SshType): string {
- if (type === "TUNNEL") {
- return t("data-source.ssh-type.tunnel");
- }
if (type === "TUNNEL+PK") {
return t("data-source.ssh-type.tunnel-and-private-key");
}
@@ -222,8 +209,7 @@ function getSshTypeLabel(type: SshType): string {
function guessSshType(value: WithSshOptions): SshType {
if (value.sshPort) {
- if (value.sshPrivateKey) return "TUNNEL+PK";
- return "TUNNEL";
+ return "TUNNEL+PK";
}
return "NONE";
}
diff --git a/frontend/src/components/InstanceForm/common.ts b/frontend/src/components/InstanceForm/common.ts
index 1abfb09a05..67ef216299 100644
--- a/frontend/src/components/InstanceForm/common.ts
+++ b/frontend/src/components/InstanceForm/common.ts
@@ -21,7 +21,6 @@ export type EditDataSource = DataSource & {
useEmptyPassword?: boolean;
useEmptyMasterPassword?: boolean;
updateSsl?: boolean;
- updateSsh?: boolean;
updateAuthenticationPrivateKey?: boolean;
extraConnectionParameters?: Record<string, string>;
};
@@ -126,12 +125,8 @@ export const calcDataSourceUpdateMask = (
const updateMask = new Set(
calcUpdateMask(editing, original, true /* toSnakeCase */)
);
- const {
- useEmptyPassword,
- updateSsh,
- updateSsl,
- updateAuthenticationPrivateKey,
- } = editState;
+ const { useEmptyPassword, updateSsl, updateAuthenticationPrivateKey } =
+ editState;
if (useEmptyPassword) {
// We need to implicitly set "password" need to be updated
// if the "use empty password" option if checked
@@ -144,13 +139,6 @@ export const calcDataSourceUpdateMask = (
updateMask.add("ssl_key");
updateMask.add("ssl_cert");
}
- if (updateSsh) {
- updateMask.add("ssh_host");
- updateMask.add("ssh_port");
- updateMask.add("ssh_user");
- updateMask.add("ssh_password");
- updateMask.add("ssh_private_key");
- }
if (updateAuthenticationPrivateKey) {
updateMask.add("authentication_private_key");
}
diff --git a/frontend/src/components/InstanceForm/context.ts b/frontend/src/components/InstanceForm/context.ts
index fd6e039b2b..7825b3e968 100644
--- a/frontend/src/components/InstanceForm/context.ts
+++ b/frontend/src/components/InstanceForm/context.ts
@@ -1,3 +1,9 @@
+import Emittery from "emittery";
+import { cloneDeep, isEqual, omit } from "lodash-es";
+import { useDialog } from "naive-ui";
+import type { InjectionKey, Ref } from "vue";
+import { computed, inject, provide, ref } from "vue";
+import { useI18n } from "vue-i18n";
import { instanceServiceClient } from "@/grpcweb";
import {
environmentNamePrefix,
@@ -25,12 +31,6 @@ import {
isValidSpannerHost,
} from "@/utils";
import { extractGrpcErrorMessage } from "@/utils/grpcweb";
-import Emittery from "emittery";
-import { cloneDeep, isEqual, omit } from "lodash-es";
-import { useDialog } from "naive-ui";
-import type { InjectionKey, Ref } from "vue";
-import { computed, inject, provide, ref } from "vue";
-import { useI18n } from "vue-i18n";
import type { ResourceIdField } from "../v2";
import type { EditDataSource } from "./common";
import {
@@ -204,7 +204,9 @@ export const provideInstanceFormContext = (baseContext: {
if (!hasWorkspacePermissionV2("bb.instances.create")) {
return false;
}
- if (!isValidEnvironmentName(`${environmentNamePrefix}${environment.value.id}`)) {
+ if (
+ !isValidEnvironmentName(`${environmentNamePrefix}${environment.value.id}`)
+ ) {
return false;
}
if (basicInfo.value.engine === Engine.SPANNER) {
@@ -256,7 +258,6 @@ export const provideInstanceFormContext = (baseContext: {
"updatedMasterPassword",
"useEmptyMasterPassword",
"updateSsl",
- "updateSsh",
"updateAuthenticationPrivateKey"
)
);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 90f766ee7c..104e6e5889 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1708,7 +1708,6 @@
"client-cert": "Client Certificate"
},
"ssh-type": {
- "tunnel": "@:{'data-source.ssh.tunnel'}",
"tunnel-and-private-key": "@:{'data-source.ssh.tunnel'} + @:{'data-source.ssh.private-key'}",
"none": "None"
},
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 5d8249c9ce..4301718325 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1708,7 +1708,6 @@
"client-cert": "Certificado del cliente"
},
"ssh-type": {
- "tunnel": "@:{'data-source.ssh.tunnel'}",
"tunnel-and-private-key": "@:{'data-source.ssh.tunnel'} + @:{'data-source.ssh.private-key'}",
"none": "Ninguno"
},
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 3b572b473f..e128175adb 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1708,7 +1708,6 @@
"client-cert": "クライアント証明書"
},
"ssh-type": {
- "tunnel": "@:{'data-source.ssh.tunnel'}",
"tunnel-and-private-key": "@:{'data-source.ssh.tunnel'} + @:{'data-source.ssh.private-key'}",
"none": "なし"
},
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 7ac0c85543..a59a4e8bce 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1708,7 +1708,6 @@
"client-cert": "Chứng chỉ máy khách"
},
"ssh-type": {
- "tunnel": "@:{'data-source.ssh.tunnel'}",
"tunnel-and-private-key": "@:{'data-source.ssh.tunnel'} + @:{'data-source.ssh.private-key'}",
"none": "Không có"
},
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 686624211f..972387ba13 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1708,7 +1708,6 @@
"client-cert": "客户端证书"
},
"ssh-type": {
- "tunnel": "@:{'data-source.ssh.tunnel'}",
"tunnel-and-private-key": "@:{'data-source.ssh.tunnel'} + @:{'data-source.ssh.private-key'}",
"none": "不使用"
},