-
Notifications
You must be signed in to change notification settings - Fork 36
Description
Objective
Eliminate ~60% code duplication in secret extraction logic by consolidating similar functions from mcp-config.go and secrets.go into shared utilities.
Context
Currently secret extraction logic is duplicated across multiple files with ~60% similarity. Functions like extractSecretsFromValue, extractSecretsFromHeaders (mcp-config.go) and extractSecretsFromConfig (secrets.go) all perform similar pattern matching for ${{ secrets.NAME }} with slight variations.
Related to #3713 - Duplicate #2: Secret Extraction Functions.
Approach
-
Create new file
pkg/workflow/secret_extraction.gowith shared utilities:- Common secret pattern regex
- Generic secret extraction from strings
- Generic secret extraction from maps
- Helper functions for parsing secret expressions with defaults
-
Refactor existing functions to use shared utilities:
- Update
extractSecretsFromValuein mcp-config.go - Update
extractSecretsFromHeadersin mcp-config.go - Update
extractSecretsFromConfigin cli/secrets.go
- Update
-
Add comprehensive tests for the new utilities
-
Verify all existing tests continue to pass
Files to Create
pkg/workflow/secret_extraction.go- Shared secret extraction utilitiespkg/workflow/secret_extraction_test.go- Tests for new utilities
Files to Modify
pkg/workflow/mcp-config.go- Refactor to use shared utilitiespkg/cli/secrets.go- Refactor to use shared utilities- Existing test files that test secret extraction
Acceptance Criteria
- New
secret_extraction.gofile created with shared utilities - Common secret pattern regex defined once (DRY principle)
- All existing secret extraction functions refactored to use utilities
- Code duplication reduced significantly
- All existing tests pass without modification
- New tests added for shared utilities
- Secret extraction behavior identical to original
- Handles edge cases: defaults (
secrets.X || 'default'), malformed expressions - Single source of truth for secret pattern matching
Related to [refactor] 🔧 Semantic Function Clustering Analysis: Refactoring Opportunities #3713
AI generated by Plan Command for #3713