Skip to content

[Duplicate Code] getConfigEnvValue private function defined identically in two sibling api-proxy service files #4334

@github-actions

Description

@github-actions

Duplicate Code Opportunity

Summary

  • Pattern: The getConfigEnvValue helper function (10 lines) is defined as a private function in two sibling service modules with byte-for-byte identical implementations. Both files also independently compute normalizedAuthType with the same expression.
  • Locations: src/services/api-proxy-credential-env.ts:17–26 and src/services/api-proxy-service-config.ts:75–84
  • Impact: The credential-injection path reads env values through two independent copies of the same lookup logic (additionalEnv → envFile → process.env); any change to env-precedence rules must be applied to both files

Evidence

src/services/api-proxy-credential-env.ts (lines 17–26):

function getConfigEnvValue(config: WrapperConfig, key: string): string | undefined {
  const envFileValue = config.envFile
    ? readEnvFile(config.envFile)[key]
    : undefined;
  const value =
    config.additionalEnv?.[key] ??
    envFileValue ??
    (config.envAll ? process.env[key] : undefined);
  const normalizedValue = value?.trim();
  return normalizedValue || undefined;
}

src/services/api-proxy-service-config.ts (lines 75–84) — identical:

function getConfigEnvValue(config: WrapperConfig, key: string): string | undefined {
  const envFileValue = config.envFile
    ? readEnvFile(config.envFile)[key]
    : undefined;
  const value =
    config.additionalEnv?.[key] ??
    envFileValue ??
    (config.envAll ? process.env[key] : undefined);
  const normalizedValue = value?.trim();
  return normalizedValue || undefined;
}

Additionally, both files compute normalizedAuthType with the same expression:

  • api-proxy-credential-env.ts:38: const normalizedAuthType = (process.env.AWF_AUTH_TYPE || '').trim().toLowerCase();
  • api-proxy-service-config.ts:93: const normalizedAuthType = (process.env.AWF_AUTH_TYPE || '').trim().toLowerCase();

Note: These two files were split from a single api-proxy-service.ts during a prior refactoring. The duplication was introduced by that split.

Suggested Refactoring

Export getConfigEnvValue from a shared module — either extend the existing src/env-utils.ts or create src/services/api-proxy-config-utils.ts:

// src/env-utils.ts (or a new shared module)
export function getConfigEnvValue(config: WrapperConfig, key: string): string | undefined {
  const envFileValue = config.envFile ? readEnvFile(config.envFile)[key] : undefined;
  const value =
    config.additionalEnv?.[key] ??
    envFileValue ??
    (config.envAll ? process.env[key] : undefined);
  return value?.trim() || undefined;
}

Both api-proxy-credential-env.ts and api-proxy-service-config.ts then import and use the shared function, removing the private copies.

Affected Files

  • src/services/api-proxy-credential-env.ts — lines 17–26 (remove private copy), line 38 (normalizedAuthType)
  • src/services/api-proxy-service-config.ts — lines 75–84 (remove private copy), line 93 (normalizedAuthType)

Effort Estimate

Low


Detected by Duplicate Code Detector workflow. Run date: 2026-06-04

Generated by Duplicate Code Detector · sonnet46 2.2M ·

  • expires on Jul 4, 2026, 10:15 PM UTC

Metadata

Metadata

Assignees

Type

No type
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