Skip to content

Commit

Permalink
refactor(connector): hide ssl for IoTDB thrift
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinplemelon committed Oct 9, 2024
1 parent e5fcebc commit 8e30da1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
23 changes: 18 additions & 5 deletions src/hooks/Rule/connector/useSchemaConnectorPropsLayout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BridgeType } from '@/types/enum'
import { omit } from 'lodash'
import { isFunction, omit } from 'lodash'
import type { ComputedRef, WritableComputedRef } from 'vue'
import { computed } from 'vue'
import useSyncConfiguration from '../bridge/useSyncConfiguration'
Expand Down Expand Up @@ -34,7 +34,7 @@ type PropsType = Readonly<{
*/
export default (
props: PropsType,
bridgeRecord: WritableComputedRef<Record<string, any>>,
recordData: WritableComputedRef<Record<string, any>>,
): {
propsOrderMap: ComputedRef<Record<string, number>>
customColClass: ComputedRef<Record<string, string>>
Expand Down Expand Up @@ -290,13 +290,23 @@ export default (
return ret
})
const GCPColClass = { service_account_json: 'custom-col-24' }
const typeColClassMap: Record<string, Record<string, string>> = {
const getIoTDBColClass = (formData: Record<string, any>): Record<string, string> => {
if (/thrift/i.test(formData?.driver)) {
return { ssl: 'col-hidden' }
}
return {}
}
const typeColClassMap: Record<
string,
Record<string, string> | ((formData: Record<string, any>) => Record<string, string>)
> = {
[BridgeType.GCPProducer]: GCPColClass,
[BridgeType.GCPConsumer]: GCPColClass,
[BridgeType.MongoDB]: { 'parameters.mongo_type': 'col-hidden' },
[BridgeType.Redis]: { 'parameters.redis_type': 'col-hidden' },
[BridgeType.InfluxDB]: { 'parameters.influxdb_type': 'col-hidden' },
[BridgeType.S3]: { 'transport_options.ssl': 'col-ssl' },
[BridgeType.IoTDB]: getIoTDBColClass,
}

const pgSqlAdvancedFields = ['disable_prepared_statements']
Expand All @@ -323,9 +333,12 @@ export default (
return [...commonAdvancedFields, ...externalFields]
})

const { syncEtcFieldsClassMap } = useSyncConfiguration(bridgeRecord)
const { syncEtcFieldsClassMap } = useSyncConfiguration(recordData)
const customColClass = computed(() => {
const externalClass = props.type ? typeColClassMap[props.type] || {} : {}
let externalClass = props.type ? typeColClassMap[props.type] || {} : {}
if (isFunction(externalClass)) {
externalClass = externalClass(recordData.value)
}
return {
...syncEtcFieldsClassMap.value,
name: `dividing-line-below`,
Expand Down
24 changes: 16 additions & 8 deletions src/hooks/Rule/useDataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,30 @@ export const useConnectorDataHandler = (): {
} = useCommonDataHandler()

const { tl } = useI18nTl('RuleEngine')
const handleGCPBridgeData = (bridgeData: any) => {
if (bridgeData.service_account_json && typeof bridgeData.service_account_json === 'string') {
const handleGCPData = (data: any) => {
if (data.service_account_json && typeof data.service_account_json === 'string') {
try {
bridgeData.service_account_json = JSON.parse(bridgeData.service_account_json)
return bridgeData
data.service_account_json = JSON.parse(data.service_account_json)
return data
} catch (error) {
ElMessage.error(tl('accountJSONError'))
return Promise.reject()
}
}
return bridgeData
return data
}

const handleIoTDBData = (data: any) => {
if (/thrift/i.test(data?.driver)) {
Reflect.deleteProperty(data, 'ssl')
}
return data
}

const specialDataHandlerBeforeSubmit = new Map([
[BridgeType.GCPProducer, handleGCPBridgeData],
[BridgeType.GCPConsumer, handleGCPBridgeData],
[BridgeType.GCPProducer, handleGCPData],
[BridgeType.GCPConsumer, handleGCPData],
[BridgeType.IoTDB, handleIoTDBData],
])

const handleConnectorDataBeforeSubmit = async (data: Connector): Promise<Connector> => {
Expand All @@ -122,7 +130,7 @@ export const useConnectorDataHandler = (): {
if (handler) {
ret = await handler(ret)
}
ret = handleDataBeforeSubmit(data)
ret = handleDataBeforeSubmit(ret)
return Promise.resolve(omit(ret, connectorKeysDoNotNeedForAPI) as Connector)
} catch (error) {
console.error(error)
Expand Down

0 comments on commit 8e30da1

Please sign in to comment.