mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 05:09:12 +03:00
* Swap analytics buckets endpoint * Fix type issues * fix * Update API types * Fix tests * nit * Final fixes * Fix * chore(studio): analytics buckets contents (#39701) * first commit * improvements * misc * cleanup * remove tappable whole * design updates * analytics improvements * polish * add clashed case * fix pairing status * connect tables basics * add multiselect * restore prod version for non-feature preview users * fix padding inconsistency * terminology fix * better empty state * fix terminology * block table connection dialog button * Nit refactors * minor nits * Add comment --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> * Default circumstance to fresh in ImportForeignSchemaDialog * Hook up connecting tables for analytics buckets (#39906) * Hook up connecting tables for analytics buckets * Address comments * Clean up iceberg wrapper when deleting analytics bucket (#39902) * Clean up iceberg wrapper when deleting analytics bucket * Clean up s3 access key when deleting analytics bucket * Make connect table disabled for now * Most clean up and refactoring * Refactor RQ * Nit * Refactor * nit --------- Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
80 lines
3.0 KiB
TypeScript
80 lines
3.0 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
|
|
import { WRAPPERS } from 'components/interfaces/Integrations/Wrappers/Wrappers.constants'
|
|
import {
|
|
getAnalyticsBucketFDWName,
|
|
getAnalyticsBucketS3KeyName,
|
|
} from 'components/interfaces/Storage/AnalyticsBucketDetails/AnalyticsBucketDetails.utils'
|
|
import {
|
|
getCatalogURI,
|
|
getConnectionURL,
|
|
} from 'components/interfaces/Storage/StorageSettings/StorageSettings.utils'
|
|
import { getKeys, useAPIKeysQuery } from 'data/api-keys/api-keys-query'
|
|
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
|
|
import { FDWCreateVariables, useFDWCreateMutation } from 'data/fdw/fdw-create-mutation'
|
|
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import { useS3AccessKeyCreateMutation } from './s3-access-key-create-mutation'
|
|
|
|
export const useIcebergWrapperCreateMutation = () => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const { data: apiKeys } = useAPIKeysQuery({ projectRef: project?.ref, reveal: true })
|
|
const { secretKey, serviceKey } = getKeys(apiKeys)
|
|
|
|
const { data: settings } = useProjectSettingsV2Query({ projectRef: project?.ref })
|
|
const protocol = settings?.app_config?.protocol ?? 'https'
|
|
const endpoint = settings?.app_config?.storage_endpoint || settings?.app_config?.endpoint
|
|
|
|
const apiKey = secretKey?.api_key ?? serviceKey?.api_key ?? 'SUPABASE_CLIENT_API_KEY'
|
|
|
|
const wrapperMeta = WRAPPERS.find((wrapper) => wrapper.name === 'iceberg_wrapper')
|
|
|
|
const { can: canCreateCredentials } = useAsyncCheckPermissions(
|
|
PermissionAction.STORAGE_ADMIN_WRITE,
|
|
'*'
|
|
)
|
|
|
|
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: getAnalyticsBucketS3KeyName(bucketName),
|
|
})
|
|
|
|
const wrapperName = getAnalyticsBucketFDWName(bucketName)
|
|
|
|
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: apiKey,
|
|
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,
|
|
}
|
|
}
|