diff --git a/packages/nc-gui-v2/pages/index/index/create-external.vue b/packages/nc-gui-v2/pages/index/index/create-external.vue index 18e8d48b19..801df33e12 100644 --- a/packages/nc-gui-v2/pages/index/index/create-external.vue +++ b/packages/nc-gui-v2/pages/index/index/create-external.vue @@ -39,7 +39,7 @@ useSidebar({ hasSidebar: false }) const { t } = useI18n() -const formState = $ref({ +let formState = $ref({ title: '', dataSource: { ...getDefaultConnectionConfig(ClientType.MYSQL) }, inflection: { @@ -120,6 +120,18 @@ const onSSLModeChange = ((mode: 'No' | 'Allow' | string) => { } }) as unknown as SelectHandler +const updateSSLUse = () => { + if (formState?.dataSource?.connection?.ssl) { + if (typeof formState.dataSource.connection.ssl === 'string') { + formState.sslUse = 'Allowed' + } else { + formState.sslUse = 'Preferred' + } + } else { + formState.sslUse = 'No' + } +} + const addNewParam = () => { formState.extraParameters.push({ key: '', value: '' }) } @@ -265,6 +277,7 @@ const handleImportURL = async () => { message.error('Invalid URL') } importURLDlg.value = false + updateSSLUse() } const handleEditJSON = () => { @@ -273,20 +286,21 @@ const handleEditJSON = () => { } const handleOk = () => { - formState.dataSource = { ...customFormState.value.dataSource } + formState = { ...customFormState.value } configEditDlg.value = false + updateSSLUse() } // reset test status on config change watch( - () => formState.dataSource, + () => formState?.dataSource, () => (testSuccess.value = false), { deep: true }, ) // populate database name based on title watch( - () => formState.title, + () => formState?.title, (v) => populateName(v), ) diff --git a/packages/nocodb/src/lib/utils/NcConfigFactory.ts b/packages/nocodb/src/lib/utils/NcConfigFactory.ts index 480b2b6f18..d3aa41b63e 100644 --- a/packages/nocodb/src/lib/utils/NcConfigFactory.ts +++ b/packages/nocodb/src/lib/utils/NcConfigFactory.ts @@ -644,7 +644,7 @@ export default class NcConfigFactory implements NcConfig { const config = parseDbUrl(url); - const parsedConfig: { driver?: string, host?: string, port?: string, database?: string, user?:string, password?: string } = {} + const parsedConfig: { driver?: string, host?: string, port?: string, database?: string, user?:string, password?: string, ssl?: string } = {} for (const [key, value] of Object.entries(config)) { const fnd = knownQueryParams.find((param) => param.parameter === key || param.aliases.includes(key)) if (fnd) { @@ -655,12 +655,20 @@ export default class NcConfigFactory implements NcConfig { } if (!parsedConfig?.port) parsedConfig.port = defaultClientPortMapping[driverClientMapping[parsedConfig.driver] || parsedConfig.driver]; - + if (rtConfig) { const { driver, ...connectionConfig } = parsedConfig; + + const client = driverClientMapping[driver] || driver; + + const avoidSSL = ['localhost', '127.0.0.1', 'host.docker.internal', '172.17. 0.1'] + + if (client === 'pg' && !connectionConfig?.ssl && !avoidSSL.includes(connectionConfig.host)) { + connectionConfig.ssl = 'true'; + } return { - client: driverClientMapping[driver] || driver, + client: client, connection: { ...connectionConfig }