Files
supabase/apps/studio/components/interfaces/Storage/ImportForeignSchemaDialog.utils.ts
Ivan Vasilov 32c3eeb389 feat: Create new schema when creating a FDW with the schema option (#37205)
* Change the import foreign schema to always create a schema.

* Fix the Iceberg wrapper.

* Refactor the create wrapper to always create a new schema.

* Remove unneeded props.

* Smol fixes

* Prevent double error toasts

* Smol fix

* Fix the wrapper creation to include the correct api key.

* Fix a bug with the new api keys.

* Handle both types of keys when fetching the iceberg namespaces.

* Add a field to all wrappers to hold the schema name which can import foreign schema.

* sq

* When importing a foreign schema, save the schema in a special field.

* Fix a type error.

* Fix importing foreign schema overriding wrapper server options with unencrypted values

* Add comment

* Handle duplicate and empty schemas when importing a foreign schema.

* Update the copy in the foreign schema wrappers.

* Remove unnecessary code.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-07-25 10:54:17 +02:00

52 lines
1.7 KiB
TypeScript

import { getFDWs } from 'data/fdw/fdws-query'
import { getDecryptedValues } from 'data/vault/vault-secret-decrypted-value-query'
import { INTEGRATIONS } from '../Integrations/Landing/Integrations.constants'
import { WrapperMeta } from '../Integrations/Wrappers/Wrappers.types'
import { convertKVStringArrayToJson } from '../Integrations/Wrappers/Wrappers.utils'
export const getDecryptedParameters = async ({
ref,
connectionString,
serverName,
}: {
ref?: string
connectionString?: string
serverName: string
}) => {
const integration = INTEGRATIONS.find((i) => i.id === 'iceberg_wrapper' && i.type === 'wrapper')
const wrapperMeta = (integration?.type === 'wrapper' && integration.meta) as WrapperMeta
const wrapperServerOptions = wrapperMeta.server.options
const FDWs = await getFDWs({ projectRef: ref, connectionString: connectionString })
const wrapper = FDWs.find((fdw) => fdw.server_name === serverName)
const serverOptions = convertKVStringArrayToJson(wrapper?.server_options ?? [])
const paramsToBeDecrypted = Object.fromEntries(
new Map(
Object.entries(serverOptions).filter(([key, value]) => {
return wrapperServerOptions.find((option) => option.name === key)?.encrypted
})
)
)
const decryptedValues = await getDecryptedValues({
projectRef: ref,
connectionString: connectionString,
ids: Object.values(paramsToBeDecrypted),
})
const paramsWithDecryptedValues = Object.fromEntries(
new Map(
Object.entries(paramsToBeDecrypted).map(([name, id]) => {
const decryptedValue = decryptedValues[id]
return [name, decryptedValue]
})
)
)
return {
...serverOptions,
...paramsWithDecryptedValues,
}
}