Skip to content

[Duplicate Code] Provider unconfigured health responses repeat sidecar status logic #5919

Description

@github-actions

Duplicate Code Opportunity

Summary

  • Pattern: Each API proxy adapter declares a small getUnconfiguredHealthResponse() wrapper that differs only by service name, env-var message, and optional OIDC unavailable branch.
  • Locations: containers/api-proxy/providers/anthropic.js lines 225-231, containers/api-proxy/providers/copilot.js lines 265-271, containers/api-proxy/providers/gemini.js lines 78-81, and containers/api-proxy/providers/vertex.js lines 70-73.
  • Impact: More than 20 lines across four copies can be replaced by default adapter metadata. This reproduces the completed prior issue [Duplicate Code] getUnconfiguredHealthResponse body structure duplicated across three provider adapters #4635 in current code. Score: >20 duplicate lines (+3), more than 2 copies (+2), easy extraction (+1) = 6.

Evidence

containers/api-proxy/providers/anthropic.js lines 225-231:

/** /health response when not configured. */
getUnconfiguredHealthResponse() {
  if (oidcRequested) {
    return makeUnconfiguredHealthResponse('awf-api-proxy-anthropic', oidcUnavailableError, 'unavailable');
  }
  return makeUnconfiguredHealthResponse('awf-api-proxy-anthropic', 'ANTHROPIC_API_KEY not configured in api-proxy sidecar');
},

containers/api-proxy/providers/copilot.js lines 265-271:

/** /health response when not configured. */
getUnconfiguredHealthResponse() {
  if (oidcConfigured) {
    return makeUnconfiguredHealthResponse('awf-api-proxy-copilot', `Copilot OIDC token (${authProvider}) not yet available in api-proxy sidecar`);
  }
  return makeUnconfiguredHealthResponse('awf-api-proxy-copilot', 'COPILOT_GITHUB_TOKEN or COPILOT_PROVIDER_API_KEY not configured in api-proxy sidecar');
},

containers/api-proxy/providers/gemini.js lines 78-81:

/** /health response when not configured. */
getUnconfiguredHealthResponse() {
  return makeUnconfiguredHealthResponse('awf-api-proxy-gemini', 'GEMINI_API_KEY not configured in api-proxy sidecar');
},

containers/api-proxy/providers/vertex.js lines 70-73:

/** /health response when not configured. */
getUnconfiguredHealthResponse() {
  return makeUnconfiguredHealthResponse('awf-api-proxy-vertex', 'GOOGLE_API_KEY not configured in api-proxy sidecar');
},

Suggested Refactoring

Move the default health-response construction into buildProviderAdapter or a provider metadata helper. Let adapters pass static metadata such as healthServiceName, missingCredentialMessage, and optionally an unavailableWhen/unavailableMessage callback for OIDC. That would keep provider-specific wording close to configuration while eliminating repeated imperative wrappers.

Affected Files

  • containers/api-proxy/providers/anthropic.js — lines 225-231
  • containers/api-proxy/providers/copilot.js — lines 265-271
  • containers/api-proxy/providers/gemini.js — lines 78-81
  • containers/api-proxy/providers/vertex.js — lines 70-73

Effort Estimate

Low


Detected by Duplicate Code Detector workflow. Run date: 2026-07-05

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Duplicate Code Detector · 141.2 AIC · ⊞ 20.1K ·

  • expires on Aug 4, 2026, 6:56 AM UTC

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions