Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Joshen/depr 250 analytics buckets use temporary api key instead of projects (#40342)

Joshen Limd8fcab243336
diff --git a/apps/studio/components/interfaces/Database/ETL/DestinationPanel/DestinationPanel.tsx b/apps/studio/components/interfaces/Database/ETL/DestinationPanel/DestinationPanel.tsx
index 344861e4808..1cb9cd8f7c0 100644
--- a/apps/studio/components/interfaces/Database/ETL/DestinationPanel/DestinationPanel.tsx
+++ b/apps/studio/components/interfaces/Database/ETL/DestinationPanel/DestinationPanel.tsx
@@ -225,7 +225,6 @@ export const DestinationPanel = ({
await createNamespace({
catalogUri,
warehouse: data.warehouseName!,
- token: catalogToken,
namespace: data.newNamespaceName,
})
diff --git a/apps/studio/components/interfaces/Database/ETL/DestinationPanel/DestinationPanelFields.tsx b/apps/studio/components/interfaces/Database/ETL/DestinationPanel/DestinationPanelFields.tsx
index 54f871f94b2..4bba98af5c7 100644
--- a/apps/studio/components/interfaces/Database/ETL/DestinationPanel/DestinationPanelFields.tsx
+++ b/apps/studio/components/interfaces/Database/ETL/DestinationPanel/DestinationPanelFields.tsx
@@ -168,9 +168,9 @@ export const AnalyticsBucketFields = ({
refetch: refetchNamespaces,
} = useIcebergNamespacesQuery(
{
+ projectRef,
catalogUri,
warehouse: warehouseName || '',
- token: serviceApiKey || '',
},
{
enabled: type === 'Analytics Bucket' && !!catalogUri && !!warehouseName && !!serviceApiKey,
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/TableRowComponent.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/TableRowComponent.tsx
index b5a45921ad9..c6d19921169 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/TableRowComponent.tsx
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/TableRowComponent.tsx
@@ -43,7 +43,6 @@ interface TableRowComponentProps {
table: { id: number; name: string; isConnected: boolean }
schema: string
namespace: string
- token: string
isLoading?: boolean
}
@@ -51,7 +50,6 @@ export const TableRowComponent = ({
table,
schema,
namespace,
- token,
isLoading,
}: TableRowComponentProps) => {
const { ref: projectRef, bucketId } = useParams()
@@ -76,7 +74,9 @@ export const TableRowComponent = ({
})
const { mutateAsync: updateFDW } = useFDWUpdateMutation()
- const { mutateAsync: deleteNamespaceTable } = useIcebergNamespaceTableDeleteMutation()
+ const { mutateAsync: deleteNamespaceTable } = useIcebergNamespaceTableDeleteMutation({
+ projectRef,
+ })
const { mutateAsync: updatePublication } = useUpdatePublicationMutation()
const { mutateAsync: startPipeline } = useStartPipelineMutation()
@@ -215,7 +215,6 @@ export const TableRowComponent = ({
const wrapperValues = convertKVStringArrayToJson(wrapperInstance?.server_options ?? [])
await deleteNamespaceTable({
- token,
catalogUri: wrapperValues.catalog_uri,
warehouse: wrapperValues.warehouse,
namespace: namespace,
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/index.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/index.tsx
index 896493b348e..e5419936459 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/index.tsx
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/NamespaceWithTables/index.tsx
@@ -34,7 +34,6 @@ type NamespaceWithTablesProps = {
sourceType: 'replication' | 'direct'
schema: string
tables: (FormattedWrapperTable & { id: number })[]
- token: string
wrapperInstance: FDW
wrapperValues: Record<string, string>
wrapperMeta: WrapperMeta
@@ -49,7 +48,6 @@ export const NamespaceWithTables = ({
sourceType = 'direct',
schema,
tables,
- token,
wrapperInstance,
wrapperValues,
wrapperMeta,
@@ -67,11 +65,10 @@ export const NamespaceWithTables = ({
{
catalogUri: wrapperValues.catalog_uri,
warehouse: wrapperValues.warehouse,
- token: token,
namespace: namespace,
+ projectRef,
},
{
- enabled: !!token,
refetchInterval: (data) => {
if (pollIntervalNamespaceTables === 0) return false
if (tablesToPoll.length > 0) {
@@ -239,7 +236,6 @@ export const NamespaceWithTables = ({
key={table.name}
table={table}
namespace={namespace}
- token={token}
schema={displaySchema}
isLoading={isImportingForeignSchema || isLoadingNamespaceTables}
/>
diff --git a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/index.tsx b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/index.tsx
index 8191cfae13a..1138c60358f 100644
--- a/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/index.tsx
+++ b/apps/studio/components/interfaces/Storage/AnalyticsBuckets/AnalyticsBucketDetails/index.tsx
@@ -30,7 +30,6 @@ import { useStartPipelineMutation } from 'data/etl/start-pipeline-mutation'
import { AnalyticsBucket } from 'data/storage/analytics-buckets-query'
import { useIcebergNamespacesQuery } from 'data/storage/iceberg-namespaces-query'
import { useIcebergWrapperCreateMutation } from 'data/storage/iceberg-wrapper-create-mutation'
-import { useVaultSecretDecryptedValueQuery } from 'data/vault/vault-secret-decrypted-value-query'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { DOCS_URL } from 'lib/constants'
import { Button, Card, CardContent } from 'ui'
@@ -111,23 +110,13 @@ export const AnalyticBucketDetails = () => {
})
const wrappersExtension = extensionsData?.find((ext) => ext.name === 'wrappers')
- const { data: token, isSuccess: isSuccessToken } = useVaultSecretDecryptedValueQuery(
- {
- projectRef: project?.ref,
- connectionString: project?.connectionString,
- id: wrapperValues.vault_token,
- },
- { enabled: wrapperValues.vault_token !== undefined }
- )
-
const { data: namespacesData, isLoading: isLoadingNamespaces } = useIcebergNamespacesQuery(
{
+ projectRef,
catalogUri: wrapperValues.catalog_uri,
warehouse: wrapperValues.warehouse,
- token: token!,
},
{
- enabled: isSuccessToken,
refetchInterval: (data) => {
if (pollIntervalNamespaces === 0) return false
if (tablesToPoll.length > 0) {
@@ -328,7 +317,6 @@ export const AnalyticBucketDetails = () => {
sourceType="direct"
schema={schema}
tables={tables as any}
- token={token!}
wrapperInstance={wrapperInstance}
wrapperValues={wrapperValues}
wrapperMeta={wrapperMeta}
diff --git a/apps/studio/data/storage/iceberg-namespace-create-mutation.ts b/apps/studio/data/storage/iceberg-namespace-create-mutation.ts
index 9181128a1b5..126d50bdcfb 100644
--- a/apps/studio/data/storage/iceberg-namespace-create-mutation.ts
+++ b/apps/studio/data/storage/iceberg-namespace-create-mutation.ts
@@ -1,6 +1,7 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
+import { useTemporaryAPIKeyQuery } from 'data/api-keys/temp-api-keys-query'
import { constructHeaders, fetchHandler, handleError } from 'data/fetchers'
import type { ResponseError, UseCustomMutationOptions } from 'types'
import { storageKeys } from './keys'
@@ -8,50 +9,40 @@ import { storageKeys } from './keys'
type CreateIcebergNamespaceVariables = {
catalogUri: string
warehouse: string
- token: string
namespace: string
}
-// [Joshen] Investigate if we can use the temp API keys here
+const errorPrefix = 'Failed to create Iceberg namespace'
+
async function createIcebergNamespace({
catalogUri,
warehouse,
- token,
namespace,
-}: CreateIcebergNamespaceVariables) {
- let headers = new Headers()
- // handle both secret key and service role key
- if (token.startsWith('sb_secret_')) {
+ tempApiKey,
+}: CreateIcebergNamespaceVariables & { tempApiKey?: string }) {
+ try {
+ if (!tempApiKey) throw new Error(`${errorPrefix}: API Key missing`)
+
+ let headers = new Headers()
headers = await constructHeaders({
'Content-Type': 'application/json',
- apikey: `${token}`,
+ apikey: tempApiKey,
})
headers.delete('Authorization')
- } else {
- headers = await constructHeaders({
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- })
- }
- const url = `${catalogUri}/v1/${warehouse}/namespaces`.replaceAll(/(?<!:)\/\//g, '/')
+ const url = `${catalogUri}/v1/${warehouse}/namespaces`.replaceAll(/(?<!:)\/\//g, '/')
- try {
const response = await fetchHandler(url, {
headers,
method: 'POST',
- body: JSON.stringify({
- namespace: namespace,
- }),
+ body: JSON.stringify({ namespace: namespace }),
})
-
const result = await response.json()
if (result.error) {
- if (result.error.message) {
- throw new Error(result.error.message)
- }
- throw new Error('Failed to create Iceberg namespace')
+ if (result.error.message) throw new Error(`${errorPrefix}: ${result.error.message}`)
+ else throw new Error(errorPrefix)
}
+
return result
} catch (error) {
handleError(error)
@@ -61,10 +52,11 @@ async function createIcebergNamespace({
type IcebergNamespaceCreateData = Awaited<ReturnType<typeof createIcebergNamespace>>
export const useIcebergNamespaceCreateMutation = ({
+ projectRef,
onSuccess,
onError,
...options
-}: Omit<
+}: { projectRef?: string } & Omit<
UseCustomMutationOptions<
IcebergNamespaceCreateData,
ResponseError,
@@ -73,9 +65,11 @@ export const useIcebergNamespaceCreateMutation = ({
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
+ const { data } = useTemporaryAPIKeyQuery({ projectRef })
+ const tempApiKey = data?.api_key
return useMutation<IcebergNamespaceCreateData, ResponseError, CreateIcebergNamespaceVariables>({
- mutationFn: (vars) => createIcebergNamespace(vars),
+ mutationFn: (vars) => createIcebergNamespace({ ...vars, tempApiKey }),
async onSuccess(data, variables, context) {
await queryClient.invalidateQueries({
queryKey: storageKeys.icebergNamespace(
@@ -85,7 +79,10 @@ export const useIcebergNamespaceCreateMutation = ({
),
})
await queryClient.invalidateQueries({
- queryKey: storageKeys.icebergNamespaces(variables.catalogUri, variables.warehouse),
+ queryKey: storageKeys.icebergNamespaces({
+ catalog: variables.catalogUri,
+ warehouse: variables.warehouse,
+ }),
})
await onSuccess?.(data, variables, context)
},
diff --git a/apps/studio/data/storage/iceberg-namespace-exists-query.ts b/apps/studio/data/storage/iceberg-namespace-exists-query.ts
deleted file mode 100644
index b05e1eee118..00000000000
--- a/apps/studio/data/storage/iceberg-namespace-exists-query.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-import { useQuery } from '@tanstack/react-query'
-
-import { constructHeaders, fetchHandler, handleError } from 'data/fetchers'
-import type { ResponseError, UseCustomQueryOptions } from 'types'
-import { storageKeys } from './keys'
-
-type ExistsNamespaceVariables = {
- catalogUri: string
- warehouse: string
- token: string
- namespace: string
-}
-
-async function checkNamespaceExists({
- catalogUri,
- warehouse,
- token,
- namespace,
-}: ExistsNamespaceVariables) {
- let headers = new Headers()
- // handle both secret key and service role key
- if (token.startsWith('sb_secret_')) {
- headers = await constructHeaders({
- 'Content-Type': 'application/json',
- apikey: `${token}`,
- })
- headers.delete('Authorization')
- } else {
- headers = await constructHeaders({
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- })
- }
-
- const url = `${catalogUri}/v1/${warehouse}/namespaces/${namespace}`.replaceAll(/(?<!:)\/\//g, '/')
-
- try {
- const response = await fetchHandler(url, {
- headers,
- method: 'HEAD',
- })
-
- return response.status === 204
- } catch (error) {
- handleError(error)
- }
-}
-
-type IcebergNamespaceExistsData = Awaited<ReturnType<typeof checkNamespaceExists>>
-
-export type IcebergNamespaceExistsError = ResponseError
-
-export const useIcebergNamespaceExistsQuery = <TData = IcebergNamespaceExistsData>(
- params: ExistsNamespaceVariables,
- {
- ...options
- }: UseCustomQueryOptions<IcebergNamespaceExistsData, IcebergNamespaceExistsError, TData> = {}
-) => {
- return useQuery<IcebergNamespaceExistsData, IcebergNamespaceExistsError, TData>({
- queryKey: storageKeys.icebergNamespace(params.catalogUri, params.warehouse, params.namespace),
- queryFn: () => checkNamespaceExists(params),
- ...options,
- })
-}
diff --git a/apps/studio/data/storage/iceberg-namespace-table-delete-mutation.ts b/apps/studio/data/storage/iceberg-namespace-table-delete-mutation.ts
index a80cd0e5291..2af9d5401af 100644
--- a/apps/studio/data/storage/iceberg-namespace-table-delete-mutation.ts
+++ b/apps/studio/data/storage/iceberg-namespace-table-delete-mutation.ts
@@ -1,6 +1,7 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
+import { useTemporaryAPIKeyQuery } from 'data/api-keys/temp-api-keys-query'
import { constructHeaders, fetchHandler, handleError } from 'data/fetchers'
import type { ResponseError, UseCustomMutationOptions } from 'types'
import { storageKeys } from './keys'
@@ -8,45 +9,43 @@ import { storageKeys } from './keys'
type DeleteIcebergNamespaceTableVariables = {
catalogUri: string
warehouse: string
- token: string
namespace: string
table: string
+ projectRef?: string
}
-// [Joshen] Investigate if we can use the temp API keys here
+const errorPrefix = 'Failed to delete Iceberg namespace table'
+
async function deleteIcebergNamespaceTable({
catalogUri,
warehouse,
- token,
namespace,
table,
-}: DeleteIcebergNamespaceTableVariables) {
- let headers = new Headers()
- // handle both secret key and service role key
- if (token.startsWith('sb_secret_')) {
+ tempApiKey,
+}: DeleteIcebergNamespaceTableVariables & { tempApiKey?: string }) {
+ try {
+ if (!tempApiKey) throw new Error(`${errorPrefix}: API Key missing`)
+
+ let headers = new Headers()
headers = await constructHeaders({
'Content-Type': 'application/json',
- apikey: `${token}`,
+ apikey: tempApiKey,
})
headers.delete('Authorization')
- } else {
- headers = await constructHeaders({
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- })
- }
- const url =
- `${catalogUri}/v1/${warehouse}/namespaces/${namespace}/tables/${table}?purgeRequested=true`.replaceAll(
- /(?<!:)\/\//g,
- '/'
- )
+ const url =
+ `${catalogUri}/v1/${warehouse}/namespaces/${namespace}/tables/${table}?purgeRequested=true`.replaceAll(
+ /(?<!:)\/\//g,
+ '/'
+ )
+
+ const response = await fetchHandler(url, { headers, method: 'DELETE' })
+ const result = await response.json()
+ if (result.error) {
+ if (result.error.message) throw new Error(`${errorPrefix}: ${result.error.message}`)
+ else throw new Error(errorPrefix)
+ }
- try {
- const response = await fetchHandler(url, {
- headers,
- method: 'DELETE',
- })
return response.status === 204
} catch (error) {
handleError(error)
@@ -56,10 +55,11 @@ async function deleteIcebergNamespaceTable({
type IcebergNamespaceTableDeleteData = Awaited<ReturnType<typeof deleteIcebergNamespaceTable>>
export const useIcebergNamespaceTableDeleteMutation = ({
+ projectRef,
onSuccess,
onError,
...options
-}: Omit<
+}: { projectRef?: string } & Omit<
UseCustomMutationOptions<
IcebergNamespaceTableDeleteData,
ResponseError,
@@ -68,13 +68,15 @@ export const useIcebergNamespaceTableDeleteMutation = ({
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
+ const { data } = useTemporaryAPIKeyQuery({ projectRef })
+ const tempApiKey = data?.api_key
return useMutation<
IcebergNamespaceTableDeleteData,
ResponseError,
DeleteIcebergNamespaceTableVariables
>({
- mutationFn: (vars) => deleteIcebergNamespaceTable(vars),
+ mutationFn: (vars) => deleteIcebergNamespaceTable({ ...vars, tempApiKey }),
async onSuccess(data, variables, context) {
await queryClient.invalidateQueries({
queryKey: storageKeys.icebergNamespace(
diff --git a/apps/studio/data/storage/iceberg-namespace-tables-query.ts b/apps/studio/data/storage/iceberg-namespace-tables-query.ts
index 6fe81e573f8..1f05938d9ae 100644
--- a/apps/studio/data/storage/iceberg-namespace-tables-query.ts
+++ b/apps/studio/data/storage/iceberg-namespace-tables-query.ts
@@ -1,5 +1,6 @@
import { useQuery } from '@tanstack/react-query'
+import { useTemporaryAPIKeyQuery } from 'data/api-keys/temp-api-keys-query'
import { constructHeaders, fetchHandler, handleError } from 'data/fetchers'
import type { ResponseError, UseCustomQueryOptions } from 'types'
import { storageKeys } from './keys'
@@ -7,49 +8,40 @@ import { storageKeys } from './keys'
type GetNamespaceTablesVariables = {
catalogUri: string
warehouse: string
- token: string
namespace: string
+ projectRef?: string
}
+const errorPrefix = 'Failed to retrieve Iceberg namespace tables'
+
async function getNamespaceTables({
catalogUri,
warehouse,
- token,
namespace,
-}: GetNamespaceTablesVariables) {
- let headers = new Headers()
- // handle both secret key and service role key
- if (token.startsWith('sb_secret_')) {
+ tempApiKey,
+}: GetNamespaceTablesVariables & { tempApiKey?: string }) {
+ try {
+ if (!tempApiKey) throw new Error(`${errorPrefix}: API Key missing`)
+
+ let headers = new Headers()
headers = await constructHeaders({
'Content-Type': 'application/json',
- apikey: `${token}`,
+ apikey: tempApiKey,
})
headers.delete('Authorization')
- } else {
- headers = await constructHeaders({
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- })
- }
-
- const url = `${catalogUri}/v1/${warehouse}/namespaces/${namespace}/tables`.replaceAll(
- /(?<!:)\/\//g,
- '/'
- )
- try {
- const response = await fetchHandler(url, {
- headers,
- method: 'GET',
- })
+ const url = `${catalogUri}/v1/${warehouse}/namespaces/${namespace}/tables`.replaceAll(
+ /(?<!:)\/\//g,
+ '/'
+ )
+ const response = await fetchHandler(url, { headers, method: 'GET' })
const result = await response.json()
if (result.error) {
- if (result.error.message) {
- throw new Error(result.error.message)
- }
- throw new Error('Failed to get iceberg namespace')
+ if (result.error.message) throw new Error(`${errorPrefix}: ${result.error.message}`)
+ else throw new Error(errorPrefix)
}
+
const r = result as { identifiers: { name: string; namespace: string[] }[] }
return r.identifiers.map((i) => i.name)
} catch (error) {
@@ -64,16 +56,29 @@ export type IcebergNamespaceTablesError = ResponseError
export const useIcebergNamespaceTablesQuery = <TData = IcebergNamespaceTablesData>(
params: GetNamespaceTablesVariables,
{
+ enabled = true,
...options
}: UseCustomQueryOptions<IcebergNamespaceTablesData, IcebergNamespaceTablesError, TData> = {}
) => {
+ const { projectRef, catalogUri, warehouse, namespace } = params
+ const { data } = useTemporaryAPIKeyQuery({ projectRef })
+ const tempApiKey = data?.api_key
+
return useQuery<IcebergNamespaceTablesData, IcebergNamespaceTablesError, TData>({
- queryKey: storageKeys.icebergNamespaceTables(
- params.catalogUri,
- params.warehouse,
- params.namespace
- ),
- queryFn: () => getNamespaceTables(params),
+ queryKey: storageKeys.icebergNamespaceTables({
+ projectRef,
+ warehouse,
+ namespace,
+ catalog: catalogUri,
+ }),
+ queryFn: () => getNamespaceTables({ ...params, tempApiKey }),
+ enabled:
+ enabled &&
+ typeof projectRef !== 'undefined' &&
+ typeof tempApiKey !== 'undefined' &&
+ typeof warehouse !== 'undefined' &&
+ typeof namespace !== 'undefined' &&
+ typeof catalogUri !== 'undefined',
...options,
})
}
diff --git a/apps/studio/data/storage/iceberg-namespaces-query.ts b/apps/studio/data/storage/iceberg-namespaces-query.ts
index 035e86c4f8a..494b953cbea 100644
--- a/apps/studio/data/storage/iceberg-namespaces-query.ts
+++ b/apps/studio/data/storage/iceberg-namespaces-query.ts
@@ -1,5 +1,6 @@
import { useQuery } from '@tanstack/react-query'
+import { useTemporaryAPIKeyQuery } from 'data/api-keys/temp-api-keys-query'
import { constructHeaders, fetchHandler, handleError } from 'data/fetchers'
import type { ResponseError, UseCustomQueryOptions } from 'types'
import { storageKeys } from './keys'
@@ -7,41 +8,35 @@ import { storageKeys } from './keys'
type GetNamespacesVariables = {
catalogUri: string
warehouse: string
- token: string
+ projectRef?: string
}
-// [Joshen] Investigate if we can use the temp API keys here
-async function getNamespaces({ catalogUri, warehouse, token }: GetNamespacesVariables) {
- let headers = new Headers()
- // handle both secret key and service role key
- if (token.startsWith('sb_secret_')) {
+const errorPrefix = 'Failed to delete Iceberg namespaces'
+
+async function getNamespaces({
+ catalogUri,
+ warehouse,
+ tempApiKey,
+}: GetNamespacesVariables & { tempApiKey?: string }) {
+ try {
+ if (!tempApiKey) throw new Error(`${errorPrefix}: API Key missing`)
+
+ let headers = new Headers()
headers = await constructHeaders({
'Content-Type': 'application/json',
- apikey: `${token}`,
+ apikey: tempApiKey,
})
headers.delete('Authorization')
- } else {
- headers = await constructHeaders({
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${token}`,
- })
- }
-
- const url = `${catalogUri}/v1/${warehouse}/namespaces`.replaceAll(/(?<!:)\/\//g, '/')
- try {
- const response = await fetchHandler(url, {
- headers,
- method: 'GET',
- })
+ const url = `${catalogUri}/v1/${warehouse}/namespaces`.replaceAll(/(?<!:)\/\//g, '/')
+ const response = await fetchHandler(url, { headers, method: 'GET' })
const result = await response.json()
if (result.error) {
- if (result.error.message) {
- throw new Error(result.error.message)
- }
- throw new Error('Failed to get iceberg namespaces')
+ if (result.error.message) throw new Error(`${errorPrefix}: ${result.error.message}`)
+ else throw new Error(errorPrefix)
}
+
const r = result as { namespaces: string[][] }
return r.namespaces.flat()
} catch (error) {
@@ -55,11 +50,28 @@ export type IcebergNamespacesError = ResponseError
export const useIcebergNamespacesQuery = <TData = IcebergNamespacesData>(
params: GetNamespacesVariables,
- { ...options }: UseCustomQueryOptions<IcebergNamespacesData, IcebergNamespacesError, TData> = {}
+ {
+ enabled = true,
+ ...options
+ }: UseCustomQueryOptions<IcebergNamespacesData, IcebergNamespacesError, TData> = {}
) => {
+ const { projectRef, catalogUri, warehouse } = params
+ const { data } = useTemporaryAPIKeyQuery({ projectRef })
+ const tempApiKey = data?.api_key
+
return useQuery<IcebergNamespacesData, IcebergNamespacesError, TData>({
- queryKey: storageKeys.icebergNamespaces(params.catalogUri, params.warehouse),
- queryFn: () => getNamespaces(params),
+ queryKey: storageKeys.icebergNamespaces({
+ projectRef,
+ warehouse,
+ catalog: catalogUri,
+ }),
+ queryFn: () => getNamespaces({ ...params, tempApiKey }),
+ enabled:
+ options &&
+ typeof projectRef !== 'undefined' &&
+ typeof tempApiKey !== 'undefined' &&
+ typeof catalogUri !== 'undefined' &&
+ typeof warehouse !== 'undefined',
...options,
})
}
diff --git a/apps/studio/data/storage/keys.ts b/apps/studio/data/storage/keys.ts
index 2ff2c226d0e..6cfc534206f 100644
--- a/apps/studio/data/storage/keys.ts
+++ b/apps/studio/data/storage/keys.ts
@@ -9,10 +9,36 @@ export const storageKeys = {
vectorBucketsIndexes: (projectRef: string | undefined, vectorBucketName: string | undefined) =>
['projects', projectRef, 'vector-buckets', vectorBucketName, 'indexes'] as const,
archive: (projectRef: string | undefined) => ['projects', projectRef, 'archive'] as const,
- icebergNamespaces: (catalog: string, warehouse: string) =>
- ['catalog', catalog, 'warehouse', warehouse, 'namespaces'] as const,
+ icebergNamespaces: ({
+ projectRef,
+ catalog,
+ warehouse,
+ }: {
+ projectRef?: string
+ catalog: string
+ warehouse: string
+ }) => [projectRef, 'catalog', catalog, 'warehouse', warehouse, 'namespaces'] as const,
icebergNamespace: (catalog: string, warehouse: string, namespace: string) =>
['catalog', catalog, 'warehouse', warehouse, 'namespaces', namespace] as const,
- icebergNamespaceTables: (catalog: string, warehouse: string, namespace: string) =>
- ['catalog', catalog, 'warehouse', warehouse, 'namespaces', namespace, 'tables'] as const,
+ icebergNamespaceTables: ({
+ projectRef,
+ catalog,
+ warehouse,
+ namespace,
+ }: {
+ projectRef?: string
+ catalog: string
+ warehouse: string
+ namespace: string
+ }) =>
+ [
+ projectRef,
+ 'catalog',
+ catalog,
+ 'warehouse',
+ warehouse,
+ 'namespaces',
+ namespace,
+ 'tables',
+ ] as const,
}