Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/http/routes/iceberg/endpoints.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { SUPPORTED_ICEBERG_ENDPOINTS } from '@storage/protocols/iceberg/catalog/tenant-catalog'
import fastify from 'fastify'
import namespace from './namespace'
import table from './table'

describe('iceberg advertised endpoints', () => {
it('match the Iceberg REST routes registered by the router', async () => {
// Auto-generated HEAD routes are not catalog endpoints, so only collect explicit ones.
const app = fastify({ exposeHeadRoutes: false })
app.setValidatorCompiler(() => () => true)
app.setSerializerCompiler(() => (data) => JSON.stringify(data))
const registered: string[] = []
app.addHook('onRoute', (route) => {
const methods = Array.isArray(route.method) ? route.method : [route.method]
const path = route.url.replace(/:(\w+)/g, '{$1}')
methods.forEach((method) => registered.push(`${method} ${path}`))
})

await app.register(namespace, { prefix: 'v1' })
await app.register(table, { prefix: 'v1' })
await app.ready()

try {
expect([...new Set(registered)].sort()).toEqual([...SUPPORTED_ICEBERG_ENDPOINTS].sort())
} finally {
await app.close()
}
})
})
26 changes: 25 additions & 1 deletion src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { describe, expect, it, vi } from 'vitest'
import type { Metastore } from '../metastore'
import { IcebergErrorType } from './errors'
import type { CatalogAuthType } from './rest-catalog-client'
import { TenantAwareRestCatalog } from './tenant-catalog'
import { SUPPORTED_ICEBERG_ENDPOINTS, TenantAwareRestCatalog } from './tenant-catalog'

function createCatalog(metastore: Partial<Metastore>, sharding: Partial<Sharder> = {}) {
const auth: CatalogAuthType = {
Expand Down Expand Up @@ -659,3 +659,27 @@ describe('TenantAwareRestCatalog resource mutations', () => {
expect(fetchMock).not.toHaveBeenCalled()
})
})

describe('TenantAwareRestCatalog getConfig', () => {
it('advertises only the Iceberg REST endpoints served by this catalog', async () => {
const fetchMock = vi.fn()
vi.stubGlobal('fetch', fetchMock)

const catalog = createCatalog({
findCatalogByName: vi.fn().mockResolvedValue({ id: 'catalog-id', name: 'warehouse' }),
})

const result = await catalog.getConfig({ warehouse: 'warehouse' })

expect(result.defaults.prefix).toBe('warehouse')
expect(result.overrides).toEqual({ prefix: 'warehouse' })
expect(result.endpoints).toEqual([...SUPPORTED_ICEBERG_ENDPOINTS])
expect(result.endpoints).not.toContain('POST /v1/{prefix}/namespaces/{namespace}/properties')
expect(result.endpoints).not.toContain('POST /v1/{prefix}/tables/rename')
expect(result.endpoints).not.toContain('POST /v1/{prefix}/namespaces/{namespace}/register')

result.endpoints.push('POST /v1/{prefix}/tables/rename')
expect(SUPPORTED_ICEBERG_ENDPOINTS).toHaveLength(11)
expect(fetchMock).not.toHaveBeenCalled()
})
})
18 changes: 18 additions & 0 deletions src/storage/protocols/iceberg/catalog/tenant-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ async function findTableByNameOrThrow(
}
}

/**
* Apache Iceberg REST catalog endpoints served by the storage HTTP router.
*/
export const SUPPORTED_ICEBERG_ENDPOINTS = [
'GET /v1/{prefix}/namespaces',
'POST /v1/{prefix}/namespaces',
'GET /v1/{prefix}/namespaces/{namespace}',
'HEAD /v1/{prefix}/namespaces/{namespace}',
'DELETE /v1/{prefix}/namespaces/{namespace}',
'GET /v1/{prefix}/namespaces/{namespace}/tables',
'POST /v1/{prefix}/namespaces/{namespace}/tables',
'GET /v1/{prefix}/namespaces/{namespace}/tables/{table}',
'HEAD /v1/{prefix}/namespaces/{namespace}/tables/{table}',
'POST /v1/{prefix}/namespaces/{namespace}/tables/{table}',
'DELETE /v1/{prefix}/namespaces/{namespace}/tables/{table}',
] as const

/**
* A tenant-aware REST catalog implementation for Iceberg tables
*
Expand Down Expand Up @@ -129,6 +146,7 @@ export class TenantAwareRestCatalog extends RestCatalogClient {
overrides: {
prefix: catalog.name,
},
endpoints: [...SUPPORTED_ICEBERG_ENDPOINTS] as string[],
}
}

Expand Down