You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pattern: Gemini and Vertex each rebuild the same Google API-key adapter shape: auth scaffold, x-goog-api-key header builder, createAdapterMethods, buildProviderAdapter, enablement, unconfigured response, and health response.
Locations: containers/api-proxy/providers/gemini.js lines 28-82 and containers/api-proxy/providers/vertex.js lines 30-74.
Impact: Roughly 40-45 lines of provider boilerplate could move behind one Google adapter factory, reducing drift in a credential-isolation path. Score: >20 duplicate lines (+3), security-critical credential path (+3), easy extraction (+1) = 7.
functioncreateVertexAdapter(env,deps={}){const{ apiKey, rawTarget, basePath, bodyTransform }=createProviderAuthScaffold(env,deps,{keyEnvVar: VERTEX_ENV.KEY,targetEnvVar: VERTEX_ENV.TARGET,basePathEnvVar: VERTEX_ENV.BASE_PATH,defaultTarget: 'aiplatform.googleapis.com',});constbuildAuthHeaders=()=>providerKeyHeaders('x-goog-api-key',apiKey);constadapterMethods=createAdapterMethods({
apiKey,
rawTarget,
basePath,provider: 'vertex',port: 10004,defaultTarget: 'aiplatform.googleapis.com',validationPath: '/v1/projects',validationHeaders: buildAuthHeaders,modelsPath: null,modelsFetchHeaders: null,});returnbuildProviderAdapter({name: 'vertex',port: 10004,isManagementPort: false,alwaysBind: true,
adapterMethods,getAuthHeaders(){returnbuildAuthHeaders();},
bodyTransform,isEnabled(){return!!apiKey;},getUnconfiguredResponse(){return{statusCode: 503,body: {error: 'Vertex AI proxy not configured (no GOOGLE_API_KEY). Set GOOGLE_API_KEY in the AWF runner environment to enable credential isolation.'},};},getUnconfiguredHealthResponse(){returnmakeUnconfiguredHealthResponse('awf-api-proxy-vertex','GOOGLE_API_KEY not configured in api-proxy sidecar');},});}
Suggested Refactoring
Extract a createGoogleApiKeyAdapter(env, deps, options) helper, either in a new provider utility module or beside the existing adapter helpers. The helper can own the shared createProviderAuthScaffold, providerKeyHeaders('x-goog-api-key', apiKey), createAdapterMethods, getAuthHeaders, isEnabled, and default unconfigured responses, while each provider supplies only name, port, env constants, default target, validation/models paths, and optional request URL transform.
Duplicate Code Opportunity
Summary
x-goog-api-keyheader builder,createAdapterMethods,buildProviderAdapter, enablement, unconfigured response, and health response.containers/api-proxy/providers/gemini.jslines 28-82 andcontainers/api-proxy/providers/vertex.jslines 30-74.Evidence
containers/api-proxy/providers/gemini.jslines 28-82:containers/api-proxy/providers/vertex.jslines 30-74:Suggested Refactoring
Extract a
createGoogleApiKeyAdapter(env, deps, options)helper, either in a new provider utility module or beside the existing adapter helpers. The helper can own the sharedcreateProviderAuthScaffold,providerKeyHeaders('x-goog-api-key', apiKey),createAdapterMethods,getAuthHeaders,isEnabled, and default unconfigured responses, while each provider supplies onlyname,port, env constants, default target, validation/models paths, and optional request URL transform.Affected Files
containers/api-proxy/providers/gemini.js— lines 28-82containers/api-proxy/providers/vertex.js— lines 30-74Effort 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:
awmgmcpgSee Network Configuration for more information.