Skip to content

[duplicate-code] Duplicate Code Pattern: Deprecated API Key Alias Functions (4 instances across 3 packages) #7136

@github-actions

Description

@github-actions

🔍 Duplicate Code Pattern: Deprecated API Key Alias Functions

Part of duplicate code analysis: #aw_parentreport1

Summary

The Agent ID rename commit introduced 4 deprecated single-line wrapper functions that follow the exact same pattern across 3 packages. Each wrapper calls the new AgentID-named function. These create an ongoing maintenance burden — callers must be found and migrated before the aliases can be removed.

Duplication Details

Pattern: One-liner deprecated wrapper delegating to the renamed function

  • Severity: Medium
  • Occurrences: 4 instances across 3 packages
  • Locations:
    • internal/auth/header.go (line 123–125)
    • internal/config/config_core.go (line 186–188)
    • internal/config/config_env.go (line 82–84)
    • internal/auth/header.go (line 209–220) — GenerateRandomAPIKey retains old external name without a new-named counterpart

Code Samples:

// internal/auth/header.go
// ValidateAPIKey is a deprecated alias for ValidateAgentID.
func ValidateAPIKey(provided, expected string) bool {
    return ValidateAgentID(provided, expected)
}

// internal/config/config_core.go
// GetAPIKey is a deprecated alias for GetAgentID.
func (c *Config) GetAPIKey() string {
    return c.GetAgentID()
}

// internal/config/config_env.go
// GetGatewayAPIKeyFromEnv is a deprecated alias for GetGatewayAgentIDFromEnv.
func GetGatewayAPIKeyFromEnv() string {
    return GetGatewayAgentIDFromEnv()
}

Additionally, GenerateRandomAPIKey() in internal/auth/header.go retains the old naming with no new-named equivalent, and its single caller in internal/cmd/root.go:277 still uses the old name.

Impact Analysis

  • Maintainability: Four deprecated wrapper functions across 3 packages must all be removed in a future cleanup pass. New contributors may use the old names when writing code (IDEs will suggest deprecated names).
  • Bug Risk: Low — wrappers are trivial one-liners. Risk is that callers are never migrated and old names persist indefinitely.
  • Code Bloat: ~15 lines of pure forwarding code that adds noise to the API surface.

Refactoring Recommendations

  1. Audit callers of all deprecated functions (including in test files) to confirm readiness for removal:

    • ValidateAPIKey (callers outside _test.go?)
    • GetAPIKey (callers outside _test.go?)
    • GetGatewayAPIKeyFromEnv (callers?)
    • GenerateRandomAPIKeyinternal/cmd/root.go:277
  2. Rename GenerateRandomAPIKeyGenerateRandomAgentID in internal/auth/header.go and update its single caller in root.go:277. This function was not given a forwarding alias unlike the others.

  3. Remove deprecated wrappers once all callers are migrated:

    • Estimated effort: 1–2 hours (audit + search-replace + test run)
    • Benefits: Removes ambiguity, shrinks public API surface, eliminates confusion about which name to use

Implementation Checklist

  • Run grep -rn "ValidateAPIKey\|GetAPIKey\|GetGatewayAPIKeyFromEnv\|GenerateRandomAPIKey" to find all remaining callers
  • Update callers to use new names
  • Remove deprecated wrapper functions
  • Rename GenerateRandomAPIKeyGenerateRandomAgentID and update call site in root.go
  • Run make test-all to verify

Parent Issue

See parent analysis report: #aw_parentreport1

Generated by Duplicate Code Detector · sonnet46 4.3M ·

  • expires on Jun 14, 2026, 3:44 AM 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