diff --git a/src/http/routes/iceberg/endpoints.test.ts b/src/http/routes/iceberg/endpoints.test.ts new file mode 100644 index 000000000..5d2783b54 --- /dev/null +++ b/src/http/routes/iceberg/endpoints.test.ts @@ -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() + } + }) +}) diff --git a/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts b/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts index 13692cca2..75ac4890c 100644 --- a/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts +++ b/src/storage/protocols/iceberg/catalog/tenant-catalog.test.ts @@ -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, sharding: Partial = {}) { const auth: CatalogAuthType = { @@ -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() + }) +}) diff --git a/src/storage/protocols/iceberg/catalog/tenant-catalog.ts b/src/storage/protocols/iceberg/catalog/tenant-catalog.ts index 6edc0390d..43e90299b 100644 --- a/src/storage/protocols/iceberg/catalog/tenant-catalog.ts +++ b/src/storage/protocols/iceberg/catalog/tenant-catalog.ts @@ -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 * @@ -129,6 +146,7 @@ export class TenantAwareRestCatalog extends RestCatalogClient { overrides: { prefix: catalog.name, }, + endpoints: [...SUPPORTED_ICEBERG_ENDPOINTS] as string[], } }