Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add connection string section for data source and the corresponding copy button
天舟7389796eb3ee
diff --git a/frontend/package.json b/frontend/package.jsonindex 9f61201635..939d086765 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -8,6 +8,7 @@"demo": "vite build --mode demo"},"dependencies": {+ "@soerenmartius/vue3-clipboard": "^0.1.2","@tailwindcss/forms": "^0.2.1","@tailwindcss/typography": "^0.4.0","@types/uuid": "^8.3.0",@@ -27,6 +28,7 @@"uuid": "^8.3.2","vue": "^3.0.5","vue-router": "^4.0.3",+ "vue3-clipboard": "^1.0.0","vuex": "^4.0.0"},"devDependencies": {diff --git a/frontend/src/main.js b/frontend/src/main.jsindex db31401b84..b2c6a016a4 100644--- a/frontend/src/main.js+++ b/frontend/src/main.js@@ -1,5 +1,6 @@import { createApp } from "vue";import moment from "moment";+import VueClipboard from "vue3-clipboard";import highlight from "./bbkit/directives/highlight";import App from "./App.vue";import { store } from "./store";@@ -51,6 +52,7 @@ app.directive("data-source-type", dataSourceType).use(store).use(router)+ .use(VueClipboard).component("BBAlert", BBAlert).component("BBAvatar", BBAvatar).component("BBButtonTrash", BBButtonTrash)diff --git a/frontend/src/views/DataSourceDetail.vue b/frontend/src/views/DataSourceDetail.vueindex d4690e2335..73e5e73e84 100644--- a/frontend/src/views/DataSourceDetail.vue+++ b/frontend/src/views/DataSourceDetail.vue@@ -195,11 +195,56 @@</div></div>- <form class="mt-6">+ <div class="mt-6"><div class="max-w-6xl mx-auto px-4"><!-- Description list --><div class="max-w-5xl mx-auto px-4 mb-6"><dl class="grid grid-cols-1 gap-x-4 gap-y-8 sm:grid-cols-2">+ <div class="sm:col-span-2">+ <dt class="text-sm font-medium text-control-light">+ Connection string+ </dt>+ <dd class="mt-2.5 text-sm text-main">+ <div class="space-y-4">+ <div+ class="flex"+ v-for="(connection, index) in connectionStringList"+ :key="index"+ >+ <span+ class="whitespace-nowrap inline-flex items-center px-3 rounded-l-md border border-l border-r-0 border-control-border bg-gray-50 text-control-light sm:text-sm"+ >+ {{ connection.name }}+ </span>+ <span+ class="flex-1 min-w-0 block w-full inline-flex items-center px-3 py-2 border border-r border-control-border sm:text-sm"+ >+ {{ connection.value }}+ </span>+ <button+ class="-ml-px px-2 py-2 border border-gray-300 text-sm font-medium text-control-light bg-gray-50 hover:bg-gray-100 focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1"+ @click.prevent="copyText(connection)"+ >+ <svg+ class="w-6 h-6"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"+ ></path>+ </svg>+ </button>+ </div>+ </div>+ </dd>+ </div>+<div class="sm:col-span-1"><dt class="text-sm font-medium text-control-light">Username<span v-if="state.editing" class="text-red-600"@@ -308,7 +353,7 @@/></div></div>- </form>+ </div></main></div></template>@@ -319,10 +364,16 @@ import { useStore } from "vuex";import { useRouter } from "vue-router";import cloneDeep from "lodash-es/cloneDeep";import isEqual from "lodash-es/isEqual";+import { toClipboard } from "@soerenmartius/vue3-clipboard";import DataSourceMemberTable from "../components/DataSourceMemberTable.vue";import { idFromSlug } from "../utils";import { DataSource } from "../types";+type Connection = {+ name: string;+ value: string;+};+interface LocalState {editing: boolean;showPassword: boolean;@@ -380,6 +431,60 @@ export default {return "* (All databases)";});+ const connectionStringList = computed<Connection[]>(() => {+ // If host starts with "/", we assume it's a local socket.+ const isSocket = instance.value.host.startsWith("/");+ const cliOptionList = isSocket+ ? [`mysql -S ${instance.value.host}`]+ : [`mysql -h ${instance.value.host}`];+ if (instance.value.port) {+ cliOptionList.push(`-P ${instance.value.port}`);+ }+ if (dataSource.value.databaseId) {+ cliOptionList.push(`-D ${databaseName.value}`);+ }+ if (dataSource.value.username) {+ cliOptionList.push(`-u ${dataSource.value.username}`);+ }+ if (dataSource.value.password) {+ if (state.showPassword) {+ cliOptionList.push(`-p${dataSource.value.password}`);+ } else {+ cliOptionList.push(`-p`);+ }+ }++ let jdbcString = `JDBC can't connect to socket ${instance.value.host} `;+ if (!isSocket) {+ jdbcString = `jdbc:mysql://${instance.value.host}`;+ if (instance.value.port) {+ jdbcString += `:${instance.value.port}`;+ }+ if (dataSource.value.databaseId) {+ jdbcString += `/${databaseName.value}`;+ }+ const optionList = [];+ if (dataSource.value.username) {+ optionList.push(`user=${dataSource.value.username}`);+ }+ if (dataSource.value.password) {+ if (state.showPassword) {+ optionList.push(`password=${dataSource.value.password}`);+ } else {+ optionList.push(`password=******`);+ }+ }+ if (optionList.length > 0) {+ jdbcString += `&${optionList.join("&")}`;+ }+ }++ return [+ { name: "CLI", value: cliOptionList.join(" ") },+ { name: "JDBC", value: jdbcString },+ ];+ });+const allowEdit = computed(() => {const myRoleMapping = store.getters["roleMapping/roleMappingByPrincipalId"@@ -441,18 +546,30 @@ export default {});};+ const copyText = (connection: Connection) => {+ toClipboard(connection.value).then(() => {+ store.dispatch("notification/pushNotification", {+ module: "bytebase",+ style: "INFO",+ title: `${connection.name} string copied to clipboard.`,+ });+ });+ };+return {editNameTextField,state,dataSource,instance,databaseName,+ connectionStringList,allowEdit,allowSave,editDataSource,cancelEdit,saveEdit,doDelete,+ copyText,};},};diff --git a/frontend/yarn.lock b/frontend/yarn.lockindex 6a07b77a52..42757b7492 100644--- a/frontend/yarn.lock+++ b/frontend/yarn.lock@@ -33,6 +33,13 @@resolved "https://registry.yarnpkg.com/@miragejs/pretender-node-polyfill/-/pretender-node-polyfill-0.1.2.tgz#d26b6b7483fb70cd62189d05c95d2f67153e43f2"integrity sha512-M/BexG/p05C5lFfMunxo/QcgIJnMT2vDVCd00wNqK2ImZONIlEETZwWJu1QtLxtmYlSHlCFl3JNzp0tLe7OJ5g==+"@soerenmartius/vue3-clipboard@^0.1.2":+ version "0.1.2"+ resolved "https://registry.yarnpkg.com/@soerenmartius/vue3-clipboard/-/vue3-clipboard-0.1.2.tgz#83927f65b48da71bde044a276cdf858c1c021c38"+ integrity sha512-a5er6cFGcFIQ/3qg6kWvU0yFqIz9iWoQGEVs9azjevyRyMAKvj1w3JuLH9y6+u0WhMNby3kn7nuR8nktSnDesg==+ dependencies:+ clipboard "^2.0.0"+"@tailwindcss/forms@^0.2.1":version "0.2.1"resolved "https://registry.yarnpkg.com/@tailwindcss/forms/-/forms-0.2.1.tgz#3244b185854fae1a7cbe8d2456314d8b2d98cf43"@@ -279,6 +286,15 @@ chalk@^4.1.0:ansi-styles "^4.1.0"supports-color "^7.1.0"+clipboard@^2.0.0, clipboard@^2.0.6:+ version "2.0.8"+ resolved "https://registry.yarnpkg.com/clipboard/-/clipboard-2.0.8.tgz#ffc6c103dd2967a83005f3f61976aa4655a4cdba"+ integrity sha512-Y6WO0unAIQp5bLmk1zdThRhgJt/x3ks6f30s3oE3H1mgIEU33XyQjEf8gsf6DxC7NPX8Y1SsNWjUjL/ywLnnbQ==+ dependencies:+ good-listener "^1.2.2"+ select "^1.1.2"+ tiny-emitter "^2.0.0"+color-convert@^1.9.0, color-convert@^1.9.1:version "1.9.3"resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"@@ -361,6 +377,11 @@ defined@^1.0.0:resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693"integrity sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=+delegate@^3.1.2:+ version "3.2.0"+ resolved "https://registry.yarnpkg.com/delegate/-/delegate-3.2.0.tgz#b66b71c3158522e8ab5744f720d8ca0c2af59166"+ integrity sha512-IofjkYBZaZivn0V8nnsMJGBr4jVLxHDheKSW88PyxS5QC4Vo9ZbZVvhzlSxY87fVq3STR6r+4cGepyHkcWOQSw==+detective@^5.2.0:version "5.2.0"resolved "https://registry.yarnpkg.com/detective/-/detective-5.2.0.tgz#feb2a77e85b904ecdea459ad897cc90a99bd2a7b"@@ -469,6 +490,13 @@ glob@^7.0.0, glob@^7.1.2:once "^1.3.0"path-is-absolute "^1.0.0"+good-listener@^1.2.2:+ version "1.2.2"+ resolved "https://registry.yarnpkg.com/good-listener/-/good-listener-1.2.2.tgz#d53b30cdf9313dffb7dc9a0d477096aa6d145c50"+ integrity sha1-1TswzfkxPf+33JoNR3CWqm0UXFA=+ dependencies:+ delegate "^3.1.2"+graceful-fs@^4.1.6, graceful-fs@^4.2.0:version "4.2.5"resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.5.tgz#bc18864a6c9fc7b303f2e2abdb9155ad178fbe29"@@ -1036,6 +1064,11 @@ route-recognizer@^0.3.3:resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.4.tgz#39ab1ffbce1c59e6d2bdca416f0932611e4f3ca3"integrity sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g==+select@^1.1.2:+ version "1.1.2"+ resolved "https://registry.yarnpkg.com/select/-/select-1.1.2.tgz#0e7350acdec80b1108528786ec1d4418d11b396d"+ integrity sha1-DnNQrN7ICxEIUoeG7B1EGNEbOW0=+simple-swizzle@^0.2.2:version "0.2.2"resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"@@ -1112,6 +1145,11 @@ supports-color@^7.1.0:reduce-css-calc "^2.1.6"resolve "^1.19.0"+tiny-emitter@^2.0.0:+ version "2.1.0"+ resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423"+ integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==+to-fast-properties@^2.0.0:version "2.0.0"resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"@@ -1154,6 +1192,13 @@ vue-router@^4.0.3:resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.0.3.tgz#8b26050c88b2dec7e27a88835f71046b365823ec"integrity sha512-AD1OjtVPyQHTSpoRsEGfPpxRQwhAhxcacOYO3zJ3KNkYP/r09mileSp6kdMQKhZWP2cFsPR3E2M3PZguSN5/ww==+vue3-clipboard@^1.0.0:+ version "1.0.0"+ resolved "https://registry.yarnpkg.com/vue3-clipboard/-/vue3-clipboard-1.0.0.tgz#f7d17a00bce6579ba866df825541563b272610f2"+ integrity sha512-GUqKh1oO79xDpq0z+cCv/NDVTpcJGNDzeNgT3PmTdTp/WJh3gcTrDqIYKycKhzMFOtIFJ7hO/+usgyWtT+fNhA==+ dependencies:+ clipboard "^2.0.6"+vue@^3.0.5:version "3.0.5"resolved "https://registry.yarnpkg.com/vue/-/vue-3.0.5.tgz#de1b82eba24abfe71e0970fc9b8d4b2babdc3fe1"