mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 14:19:11 +03:00
* Migrate the CreateBucketModal to use RHF. * Minor fixes for the create bucket modal. * Use the bucket type from the API everywhere. * Improve the types on some functions. Add "skip" mode to FDWCreateMutation. * Expand the CreateBucketModal to explain what will happen when creating an iceberg bucket. * Add a page for iceberg buckets. * Add error states to the iceberg explorer. * Fix the names for the FDWs. * Add a dialog for setting up namespace. * Restructure the new files. * Add a download env button. * Add warning to install the wrappers extension when creating an iceberg bucket. * Add failover details when the FDW is not setup. * Fix a lint error. * Fix a type error. * Minor fixes. * Fix the server name. * Add an icon for iceberg buckets. * Fix the import foreign schema dialog. * Make the setup wrapper button functional. * Fix a bad useMemo dependency. * Small changes to the iceberg bucket page. * Minor fix for the edit wrapper sheet. * Rename the files from kebab-case to PascalCase. * Rename the files again to include Analytic instead of Iceberg. * Rename Iceberg type to Analytic. * Add a switch for creating namespace in the import foreign schema dialog. * Fix the CreateBucketModal. * Fix the delete modal feature. * Fix the S3 keys in the FDW. * Only create a namespace if the switch is true. * Regenerate and fix the types. * Fix the FDW create mutation to handle numbers in the FDW names. * Make the icon smaller. * Check whether the namespace exists, if it doesn't create it. * Hide action from the analytic bucket which don't work. * Invalidate namespaces when creating them. * Add small explanation for the creation of namespaces. * Minor fixes. * Tons of changes to make the namespace feature work. * Fix type errors. * Fix bad import. * Minor copy fixes. * Replace the multiple cards with a table of namespaces. * update copy icon * tiny copy update * Fix the empty state for foreign tables. * Hide the analytics bucket option for self-hosted. * Minor copy fixes. * Expand the CTA on no namespaces state. * More minor fixes. * More small fixes. --------- Co-authored-by: Alaister Young <a@alaisteryoung.com>
81 lines
3.0 KiB
TypeScript
81 lines
3.0 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
|
|
import { WRAPPERS } from 'components/interfaces/Integrations/Wrappers/Wrappers.constants'
|
|
import {
|
|
useIsProjectActive,
|
|
useProjectContext,
|
|
} from 'components/layouts/ProjectLayout/ProjectContext'
|
|
import {
|
|
getCatalogURI,
|
|
getConnectionURL,
|
|
} from 'components/to-be-cleaned/Storage/StorageSettings/StorageSettings.utils'
|
|
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
|
|
import { useProjectStorageConfigQuery } from 'data/config/project-storage-config-query'
|
|
import { FDWCreateVariables, useFDWCreateMutation } from 'data/fdw/fdw-create-mutation'
|
|
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { snakeCase } from 'lodash'
|
|
import { useS3AccessKeyCreateMutation } from './s3-access-key-create-mutation'
|
|
|
|
export const useIcebergWrapperCreateMutation = () => {
|
|
const { project } = useProjectContext()
|
|
const { data: settings } = useProjectSettingsV2Query({ projectRef: project?.ref })
|
|
const protocol = settings?.app_config?.protocol ?? 'https'
|
|
const endpoint = settings?.app_config?.endpoint
|
|
|
|
const serviceApiKey =
|
|
(settings?.service_api_keys ?? []).find((key) => key.tags === 'service_role')?.api_key ??
|
|
'SUPABASE_CLIENT_SERVICE_KEY'
|
|
|
|
const wrapperMeta = WRAPPERS.find((wrapper) => wrapper.name === 'iceberg_wrapper')
|
|
|
|
const isProjectActive = useIsProjectActive()
|
|
|
|
const canCreateCredentials = useCheckPermissions(PermissionAction.STORAGE_ADMIN_WRITE, '*')
|
|
|
|
const { data: config } = useProjectStorageConfigQuery({ projectRef: project?.ref })
|
|
const isS3ConnectionEnabled = config?.features.s3Protocol.enabled
|
|
const disableCreation = !isProjectActive || !canCreateCredentials || !isS3ConnectionEnabled
|
|
|
|
const { mutateAsync: createS3AccessKey, isLoading: isCreatingS3AccessKey } =
|
|
useS3AccessKeyCreateMutation()
|
|
|
|
const { mutateAsync: createFDW, isLoading: isCreatingFDW } = useFDWCreateMutation()
|
|
|
|
const mutateAsync = async ({ bucketName }: { bucketName: string }) => {
|
|
const createS3KeyData = await createS3AccessKey({
|
|
projectRef: project?.ref,
|
|
description: `${snakeCase(bucketName)}_keys`,
|
|
})
|
|
|
|
const wrapperName = `${snakeCase(bucketName)}_fdw`
|
|
|
|
const params: FDWCreateVariables = {
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
wrapperMeta: wrapperMeta!,
|
|
formState: {
|
|
wrapper_name: wrapperName,
|
|
server_name: `${wrapperName}_server`,
|
|
vault_aws_access_key_id: createS3KeyData?.access_key,
|
|
vault_aws_secret_access_key: createS3KeyData?.secret_key,
|
|
vault_token: serviceApiKey,
|
|
warehouse: bucketName,
|
|
's3.endpoint': getConnectionURL(project?.ref ?? '', protocol, endpoint),
|
|
catalog_uri: getCatalogURI(project?.ref ?? '', protocol, endpoint),
|
|
},
|
|
mode: 'skip',
|
|
tables: [],
|
|
sourceSchema: '',
|
|
targetSchema: '',
|
|
}
|
|
|
|
await createFDW(params)
|
|
}
|
|
|
|
return {
|
|
mutateAsync,
|
|
isLoading: isCreatingFDW || isCreatingS3AccessKey,
|
|
hasPermission: canCreateCredentials,
|
|
}
|
|
}
|