Skip to content

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

chore: improve & fix instance connection (#11765)

ecmadao0d258b32c731
diff --git a/backend/store/data_source.go b/backend/store/data_source.go
index ac47a3eb9d..11d6e3f889 100644
--- a/backend/store/data_source.go
+++ b/backend/store/data_source.go
@@ -364,6 +364,7 @@ func (*Store) addDataSourceToInstanceImplV2(ctx context.Context, tx *Tx, instanc
SshObfuscatedPrivateKey: dataSource.SSHObfuscatedPrivateKey,
AuthenticationPrivateKeyObfuscated: dataSource.AuthenticationPrivateKeyObfuscated,
ExternalSecret: dataSource.ExternalSecret,
+ AuthenticationType: dataSource.AuthenticationType,
}
protoBytes, err := protojson.Marshal(&dataSourceOptions)
if err != nil {
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
index 9cb7fe4b06..36dec5cd85 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/DataSourceForm.vue
@@ -11,6 +11,7 @@
<NRadioGroup
v-model:value="dataSource.authenticationType"
class="textlabel"
+ :disabled="!allowEdit"
>
<NRadio :value="DataSource_AuthenticationType.PASSWORD">
{{ $t("instance.password-type.password") }}
@@ -53,6 +54,7 @@
<NRadioGroup
class="textlabel"
:value="state.passwordType"
+ :disabled="!allowEdit"
@update:value="changeSecretType"
>
<NRadio
@@ -264,6 +266,7 @@
<NRadioGroup
v-model:value="dataSource.externalSecret.appRole.type"
class="textlabel my-1"
+ :disabled="!allowEdit"
>
<NRadio
:value="
@@ -401,6 +404,7 @@
<DroppableTextarea
v-model:value="dataSource.authenticationPrivateKey"
:resizable="false"
+ :disabled="!allowEdit"
class="w-full h-32 mt-2 whitespace-pre-wrap"
placeholder="-----BEGIN PRIVATE KEY-----
MIIEvQ...
@@ -421,6 +425,7 @@ MIIEvQ...
class="mt-2 w-full"
:input-props="{ autocomplete: 'off' }"
placeholder="admin"
+ :disabled="!allowEdit"
:value="dataSource.authenticationDatabase"
@update:value="dataSource.authenticationDatabase = $event.trim()"
/>
@@ -448,6 +453,7 @@ MIIEvQ...
class="mt-2 w-full"
:input-props="{ autocomplete: 'off' }"
:value="dataSource.host"
+ :disabled="!allowEdit"
@update:value="handleHostInput"
/>
</div>
@@ -466,6 +472,7 @@ MIIEvQ...
:input-props="{ autocomplete: 'off' }"
:value="dataSource.port"
:allow-input="onlyAllowNumber"
+ :disabled="!allowEdit"
@update:value="handlePortInput"
/>
</div>
@@ -499,6 +506,7 @@ MIIEvQ...
<SslCertificateForm
:value="dataSource"
:engine-type="basicInfo.engine"
+ :disabled="!allowEdit"
@change="handleSSLChange"
/>
</template>
@@ -507,6 +515,7 @@ MIIEvQ...
<SslCertificateForm
:value="dataSource"
:engine-type="basicInfo.engine"
+ :disabled="!allowEdit"
@change="handleSSLChange"
/>
</template>
@@ -542,6 +551,7 @@ MIIEvQ...
<SshConnectionForm
:value="dataSource"
:instance="instance"
+ :disabled="!allowEdit"
@change="handleSSHChange"
/>
</template>
@@ -550,6 +560,7 @@ MIIEvQ...
<SshConnectionForm
:value="dataSource"
:instance="instance"
+ :disabled="!allowEdit"
@change="handleSSHChange"
/>
</template>
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
index 0bd157a35b..d349712b48 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SshConnectionForm.vue
@@ -4,6 +4,7 @@
v-for="sshType in SshTypes"
:key="sshType"
:value="sshType"
+ :disabled="disabled"
:checked="state.type === sshType"
@update:checked="handleSelectType(sshType, $event)"
>
@@ -23,6 +24,7 @@
v-model:value="state.value.sshHost"
class="mt-2 w-full"
:placeholder="''"
+ :disabled="disabled"
/>
</div>
@@ -34,6 +36,7 @@
v-model:value="state.value.sshPort"
class="mt-2 w-full"
:placeholder="''"
+ :disabled="disabled"
:allow-input="onlyAllowNumber"
/>
</div>
@@ -50,6 +53,7 @@
v-model:value="state.value.sshUser"
class="mt-2 w-full"
:placeholder="''"
+ :disabled="disabled"
/>
</div>
<div class="mt-2 sm:col-span-3 sm:col-start-1">
@@ -60,6 +64,7 @@
v-model:value="state.value.sshPassword"
class="mt-2 w-full"
:placeholder="$t('instance.password-write-only')"
+ :disabled="disabled"
/>
</div>
</div>
@@ -74,6 +79,7 @@
<DroppableTextarea
v-model:value="state.value.sshPrivateKey"
:resizable="false"
+ :disabled="disabled"
class="w-full h-24 mt-2 whitespace-pre-wrap"
/>
</div>
@@ -91,7 +97,6 @@
<script lang="ts" setup>
import { cloneDeep } from "lodash-es";
import { NInput, NRadio } from "naive-ui";
-import type { PropType } from "vue";
import { reactive, computed, watch } from "vue";
import { useI18n } from "vue-i18n";
import DroppableTextarea from "@/components/misc/DroppableTextarea.vue";
@@ -118,16 +123,11 @@ type LocalState = {
showFeatureModal: boolean;
};
-const props = defineProps({
- value: {
- type: Object as PropType<WithSshOptions>,
- required: true,
- },
- instance: {
- type: Object as PropType<Instance>,
- default: undefined,
- },
-});
+const props = defineProps<{
+ value: WithSshOptions;
+ instance?: Instance;
+ disabled: boolean;
+}>();
const emit = defineEmits<{
(e: "change", value: WithSshOptions): void;
diff --git a/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
index 43eb66214f..a31bda400d 100644
--- a/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
+++ b/frontend/src/components/InstanceForm/DataSourceSection/SslCertificateForm.vue
@@ -1,6 +1,7 @@
<template>
<NRadioGroup
v-model:value="state.type"
+ :disabled="disabled"
class="!flex flex-row items-center gap-x-4 mt-2"
>
<NRadio
@@ -16,6 +17,7 @@
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"
/>
@@ -33,6 +35,7 @@
<DroppableTextarea
v-model:value="state.value.sslCa"
:resizable="false"
+ :disabled="disabled"
class="w-full h-24 whitespace-pre-wrap"
placeholder="Input or drag and drop YOUR_CA_CERTIFICATE"
/>
@@ -46,6 +49,7 @@
<DroppableTextarea
v-model:value="state.value.sslKey"
:resizable="false"
+ :disabled="disabled"
class="w-full h-24 whitespace-pre-wrap"
placeholder="Input or drag and drop YOUR_CLIENT_KEY"
/>
@@ -59,6 +63,7 @@
<DroppableTextarea
v-model:value="state.value.sslCert"
:resizable="false"
+ :disabled="disabled"
class="w-full h-24 whitespace-pre-wrap"
placeholder="Input or drag and drop YOUR_CLIENT_CERT"
/>
@@ -88,6 +93,7 @@ type LocalState = {
const props = defineProps<{
value: WithSslOptions;
engineType: Engine;
+ disabled: boolean;
}>();
const emit = defineEmits<{
diff --git a/frontend/src/components/InstanceForm/InstanceForm.vue b/frontend/src/components/InstanceForm/InstanceForm.vue
index 7d919e4fda..5006362c5f 100644
--- a/frontend/src/components/InstanceForm/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm/InstanceForm.vue
@@ -100,6 +100,7 @@
? undefined
: environment.uid
"
+ :disabled="!allowEdit"
@update:environment="handleSelectEnvironmentUID"
/>
</div>
@@ -367,7 +368,6 @@
import { cloneDeep, isEqual, omit } from "lodash-es";
import { NButton, NInput, NSwitch, NRadioGroup, NRadio } from "naive-ui";
import { Status } from "nice-grpc-common";
-import type { PropType } from "vue";
import { computed, reactive, ref, watch, onMounted, toRef } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -428,16 +428,10 @@ import {
import { provideInstanceFormContext } from "./context";
import { useInstanceSpecs } from "./specs";
-const props = defineProps({
- instance: {
- type: Object as PropType<Instance>,
- default: undefined,
- },
- drawer: {
- type: Boolean,
- default: false,
- },
-});
+const props = defineProps<{
+ instance?: Instance;
+ drawer?: boolean;
+}>();
const emit = defineEmits(["dismiss"]);
@@ -734,7 +728,7 @@ const validateResourceId = async (
return [];
};
-const updateEditState = async (instance: Instance) => {
+const updateEditState = (instance: Instance) => {
basicInfo.value = extractBasicInfo(instance);
const updatedEditState = extractDataSourceEditState(instance);
dataSourceEditState.value.dataSources = updatedEditState.dataSources;
@@ -866,6 +860,9 @@ const doUpdate = async () => {
) {
updateMask.push("options.maximum_connections");
}
+ if (updateMask.length === 0) {
+ return;
+ }
return await instanceV1Store.updateInstance(instancePatch, updateMask);
};
const updateDataSource = async (
@@ -917,7 +914,7 @@ const doUpdate = async () => {
await maybeUpdateAdminDataSource();
await maybeUpsertReadonlyDataSources();
const updatedInstance = instanceV1Store.getInstanceByName(instance.name);
- await updateEditState(updatedInstance);
+ updateEditState(updatedInstance);
pushNotification({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/components/InstanceForm/context.ts b/frontend/src/components/InstanceForm/context.ts
index f6ce771c8f..ee1334f35d 100644
--- a/frontend/src/components/InstanceForm/context.ts
+++ b/frontend/src/components/InstanceForm/context.ts
@@ -1,12 +1,5 @@
-import type { ComputedRef } from "vue";
-import {
- type InjectionKey,
- type Ref,
- provide,
- inject,
- computed,
- ref,
-} from "vue";
+import type { ComputedRef, InjectionKey, Ref } from "vue";
+import { provide, inject, computed, ref } from "vue";
import { useCurrentUserV1, useSubscriptionV1Store } from "@/store";
import type { FeatureType } from "@/types";
import { State } from "@/types/proto/v1/common";
diff --git a/frontend/src/components/ProvideInstanceContext.vue b/frontend/src/components/ProvideInstanceContext.vue
index d282aff49b..440eea7cad 100644
--- a/frontend/src/components/ProvideInstanceContext.vue
+++ b/frontend/src/components/ProvideInstanceContext.vue
@@ -1,24 +1,48 @@
<template>
- <slot />
+ <div v-if="loading" class="flex items-center gap-x-2 m-4">
+ <BBSpin :size="20" />
+ Loading instance...
+ </div>
+ <slot v-else />
</template>
<script lang="ts" setup>
-import { watchEffect } from "vue";
+import { watchEffect, ref, computed } from "vue";
import { useInstanceV1Store } from "@/store";
import { instanceNamePrefix } from "@/store/modules/v1/common";
+import { UNKNOWN_INSTANCE_NAME } from "@/types";
const props = defineProps<{
instanceId: string;
}>();
+const instanceStore = useInstanceV1Store();
+const loading = ref(false);
+
+const instanceName = computed(() => `${instanceNamePrefix}${props.instanceId}`);
+const instance = computed(() =>
+ instanceStore.getInstanceByName(instanceName.value)
+);
+
const prepareInstanceContext = async function () {
- await Promise.all([
- useInstanceV1Store()
- .getOrFetchInstanceByName(`${instanceNamePrefix}${props.instanceId}`)
- .then((instance) => {
- return useInstanceV1Store().fetchInstanceRoleListByName(instance.name);
- }),
- ]);
+ const ins = await prepareInstance();
+ await useInstanceV1Store().fetchInstanceRoleListByName(ins.name);
+};
+
+const prepareInstance = async () => {
+ if (instance.value.name !== UNKNOWN_INSTANCE_NAME) {
+ return instance.value;
+ }
+
+ loading.value = true;
+ try {
+ const ins = await useInstanceV1Store().getOrFetchInstanceByName(
+ instanceName.value
+ );
+ return ins;
+ } finally {
+ loading.value = false;
+ }
};
watchEffect(prepareInstanceContext);
diff --git a/frontend/src/components/misc/DroppableTextarea.vue b/frontend/src/components/misc/DroppableTextarea.vue
index f26cca2344..8b078ebbd6 100644
--- a/frontend/src/components/misc/DroppableTextarea.vue
+++ b/frontend/src/components/misc/DroppableTextarea.vue
@@ -13,6 +13,7 @@
:placeholder="placeholder"
type="textarea"
v-bind="$attrs"
+ :disabled="disabled"
/>
<div
@@ -21,6 +22,7 @@
>
Or drag and drop files here.
<input
+ v-if="!disabled"
type="file"
class="absolute inset-0 opacity-0 cursor-pointer"
title=""
@@ -69,10 +71,12 @@ const props = withDefaults(
value: string | undefined;
placeholder?: string;
maxFileSize?: number; // in MB
+ disabled?: boolean;
}>(),
{
placeholder: undefined,
maxFileSize: 1,
+ disabled: false,
}
);
diff --git a/frontend/src/layouts/InstanceLayout.vue b/frontend/src/layouts/InstanceLayout.vue
index 6735c209e9..c730219b69 100644
--- a/frontend/src/layouts/InstanceLayout.vue
+++ b/frontend/src/layouts/InstanceLayout.vue
@@ -13,14 +13,13 @@
</template>
<script lang="ts" setup>
-import { computed, watchEffect } from "vue";
+import { computed } from "vue";
import { useRouter } from "vue-router";
import ProvideInstanceContext from "@/components/ProvideInstanceContext.vue";
-import { useCurrentUserV1, useInstanceV1Store } from "@/store";
-import { instanceNamePrefix } from "@/store/modules/v1/common";
+import { useCurrentUserV1 } from "@/store";
import { hasWorkspacePermissionV2 } from "@/utils";
-const props = defineProps<{
+defineProps<{
instanceId: string;
}>();
@@ -38,10 +37,4 @@ const hasPermission = computed(() => {
hasWorkspacePermissionV2(currentUser.value, permission)
);
});
-
-watchEffect(async () => {
- await useInstanceV1Store().getOrFetchInstanceByName(
- `${instanceNamePrefix}${props.instanceId}`
- );
-});
</script>