Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Duplicate Code] Share OIDC unavailable-response scaffold across provider adapters

Chiusa
#9,019 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript

Direzione di ricerca

Review the repeated OIDC handling in containers/api-proxy/providers/openai.js, anthropic.js, and google-adapter.js, then inspect oidc-adapter-utils.js or adapter-factory.js for the appropriate shared-helper location. Confirm the requested-versus-configured behavior and provider-specific wording before extracting the response pair. Done means all three adapters use the shared logic while preserving retryability and matching unavailable health states.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

code-quality refactoring

Duplicate Code Opportunity

Summary
  • Pattern: The provider adapters repeat the same OIDC failure-handling scaffold: compute an oidcUnavailableError, return a provider_not_configured response when OIDC was requested but the token is unavailable, and expose a matching unavailableWhen health state.
  • Locations: containers/api-proxy/providers/openai.js lines 105-121; containers/api-proxy/providers/anthropic.js lines 180-203; containers/api-proxy/providers/google-adapter.js lines 86-124.
  • Impact: This is security-critical auth-path logic. A change to OIDC retryability, error wording, or the "requested vs configured" distinction must be kept in sync across multiple adapters.
Evidence
// containers/api-proxy/providers/openai.js:105-121
buildAdapterOptions: ({ oidcConfigured }) => ({
  name: 'openai',
  port: 10000,
  isManagementPort: true,
  bodyTransform: composedBodyTransform,
  missingCredentialResponse: {
    kind: 'plain_error',
    statusCode: 404,
    message: 'OpenAI proxy not configured (no OPENAI_API_KEY/COPILOT_PROVIDER_API_KEY or OIDC auth)',
  },
  unconfiguredResponseWhen: () => (oidcConfigured
    ? {
        kind: 'provider_not_configured',
        message: 'OpenAI OIDC token unavailable; retry shortly',
        retryable: true,
      }
    : null),
  extra: {
    participatesInValidation: true,
    _hostedWebPolicy: hostedWebPolicy,
  },
}),
// containers/api-proxy/providers/anthropic.js:180-203
buildAdapterOptions: ({ oidcConfigured }) => {
  const oidcUnavailableError = oidcConfigured
    ? 'Anthropic OIDC token unavailable; retry shortly'
    : 'Anthropic OIDC requires ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN (permissions: id-token: write).';
  return {
    name: 'anthropic',
    port: 10001,
    isManagementPort: false,
    bodyTransform: composedBodyTransform,
    missingCredentialResponse: {
      kind: 'provider_not_configured',
      message: 'Credentials for Anthropic (port 10001) are not configured. Set ANTHROPIC_API_KEY to enable this provider.',
    },
    unconfiguredResponseWhen: () => (oidcRequested
      ? {
          kind: 'provider_not_configured',
          message: oidcUnavailableError,
          retryable: oidcConfigured,
        }
      : null),
    healthServiceName: 'awf-api-proxy-anthropic',
    missingCredentialMessage: 'ANTHROPIC_API_KEY not configured in api-proxy sidecar',
    unavailableWhen: () => oidcRequested ? { message: oidcUnavailableError, status: 'unavailable' } : null,
  };
},
Suggested Refactoring

Extract a small helper in oidc-adapter-utils.js or adapter-factory.js that builds the OIDC unavailable response pair from { provider, requested, configured, unavailableMessage }. That helper should return the retryable provider_not_configured payload and the matching health-state object so adapters only supply provider-specific wording.

Affected Files
  • containers/api-proxy/providers/openai.js — lines 105-121
  • containers/api-proxy/providers/anthropic.js — lines 180-203
  • containers/api-proxy/providers/google-adapter.js — lines 86-124
Effort Estimate

Low


Detected by Duplicate Code Detector workflow. Run date: 2026-09-25

Generated by Duplicate Code Detector · copilot · gpt50mini · 14.2 AIC · ⊞ 21K · ◷

  • expires on Oct 25, 2026, 9:45 PM UTC
Lingua principale
TypeScript
Stelle
150
Fork
76
Merge medio
3h 29m
PR unite (30g)
451

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/gh-aw-firewall

Tutte le issue di github/gh-aw-firewall

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.