diff --git a/containers/api-proxy/providers/anthropic.js b/containers/api-proxy/providers/anthropic.js index 0c0187152..141709096 100644 --- a/containers/api-proxy/providers/anthropic.js +++ b/containers/api-proxy/providers/anthropic.js @@ -15,6 +15,7 @@ const { composeBodyTransforms, makeProviderNotConfiguredResponse, + makeUnconfiguredHealthResponse, validateAuthHeaderEnv, createBaseAdapterConfig, createAdapterMethods, @@ -229,15 +230,9 @@ function createAnthropicAdapter(env, deps = {}) { /** /health response when not configured. */ getUnconfiguredHealthResponse() { if (oidcRequested) { - return { - statusCode: 503, - body: { status: 'unavailable', service: 'awf-api-proxy-anthropic', error: oidcUnavailableError }, - }; + return makeUnconfiguredHealthResponse('awf-api-proxy-anthropic', oidcUnavailableError, 'unavailable'); } - return { - statusCode: 503, - body: { status: 'not_configured', service: 'awf-api-proxy-anthropic', error: 'ANTHROPIC_API_KEY not configured in api-proxy sidecar' }, - }; + return makeUnconfiguredHealthResponse('awf-api-proxy-anthropic', 'ANTHROPIC_API_KEY not configured in api-proxy sidecar'); }, // Exposed for introspection (logging, tests) diff --git a/containers/api-proxy/providers/copilot.js b/containers/api-proxy/providers/copilot.js index 36723bb42..ed4f64b06 100644 --- a/containers/api-proxy/providers/copilot.js +++ b/containers/api-proxy/providers/copilot.js @@ -20,6 +20,7 @@ const { normalizeBasePath, makeProviderNotConfiguredResponse, + makeUnconfiguredHealthResponse, createAdapterMethods, composeBodyTransforms, } = require('../proxy-utils'); @@ -305,15 +306,9 @@ function createCopilotAdapter(env, deps = {}) { /** /health response when not configured. */ getUnconfiguredHealthResponse() { if (oidcConfigured) { - return { - statusCode: 503, - body: { status: 'not_configured', service: 'awf-api-proxy-copilot', error: `Copilot OIDC token (${authProvider}) not yet available in api-proxy sidecar` }, - }; + return makeUnconfiguredHealthResponse('awf-api-proxy-copilot', `Copilot OIDC token (${authProvider}) not yet available in api-proxy sidecar`); } - return { - statusCode: 503, - body: { status: 'not_configured', service: 'awf-api-proxy-copilot', error: 'COPILOT_GITHUB_TOKEN or COPILOT_PROVIDER_API_KEY not configured in api-proxy sidecar' }, - }; + return makeUnconfiguredHealthResponse('awf-api-proxy-copilot', 'COPILOT_GITHUB_TOKEN or COPILOT_PROVIDER_API_KEY not configured in api-proxy sidecar'); }, // Exposed for introspection / testing diff --git a/containers/api-proxy/providers/gemini.js b/containers/api-proxy/providers/gemini.js index 844ec03e9..9d13715b1 100644 --- a/containers/api-proxy/providers/gemini.js +++ b/containers/api-proxy/providers/gemini.js @@ -13,7 +13,7 @@ * Gemini SDK versions append alongside the header. */ -const { stripGeminiKeyParam, createBaseAdapterConfig, createAdapterMethods } = require('../proxy-utils'); +const { stripGeminiKeyParam, createBaseAdapterConfig, createAdapterMethods, makeUnconfiguredHealthResponse } = require('../proxy-utils'); /** * Create the Google Gemini provider adapter. @@ -90,10 +90,7 @@ function createGeminiAdapter(env, deps = {}) { /** /health response when not configured. */ getUnconfiguredHealthResponse() { - return { - statusCode: 503, - body: { status: 'not_configured', service: 'awf-api-proxy-gemini', error: 'GEMINI_API_KEY not configured in api-proxy sidecar' }, - }; + return makeUnconfiguredHealthResponse('awf-api-proxy-gemini', 'GEMINI_API_KEY not configured in api-proxy sidecar'); }, }; } diff --git a/containers/api-proxy/proxy-utils.js b/containers/api-proxy/proxy-utils.js index 4dc4e1f05..6bf2658c0 100644 --- a/containers/api-proxy/proxy-utils.js +++ b/containers/api-proxy/proxy-utils.js @@ -216,6 +216,16 @@ function makeProviderNotConfiguredResponse(provider, port, message) { }; } +/** + * Build the standard health-endpoint response for an unconfigured provider. + * @param {string} service - Service identifier (e.g. 'awf-api-proxy-anthropic') + * @param {string} error - Human-readable error message + * @param {string} [status='not_configured'] - Status string ('not_configured' or 'unavailable') + */ +function makeUnconfiguredHealthResponse(service, error, status = 'not_configured') { + return { statusCode: 503, body: { status, service, error } }; +} + /** * Validate that a string is a legal HTTP header name. * @param {string} name - The header name to validate @@ -392,6 +402,7 @@ module.exports = { shouldStripHeader, composeBodyTransforms, makeProviderNotConfiguredResponse, + makeUnconfiguredHealthResponse, isValidHeaderName, validateAuthHeaderEnv, createBaseAdapterConfig,