Uh oh!
There was an error while loading. Please reload this page.
Consolidate duplicate secret extraction logic into shared utilities - #3752
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
| @@ -5,20 +5,15 @@ import ( | |||
| "fmt" | |||
… directly Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
This PR successfully consolidates duplicate secret extraction logic from multiple files into a shared utility module, reducing code duplication and improving maintainability. The refactoring moves secret pattern matching and extraction functions into pkg/workflow/secret_extraction.go and updates all call sites to use the new shared utilities.
Key changes:
- Created centralized secret extraction utilities with comprehensive test coverage
- Eliminated ~75 lines of duplicate code from
mcp-config.go - Removed thin wrapper function from
secrets.goin favor of direct use of shared utilities
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/secret_extraction.go | New shared utilities for secret extraction with exported functions for extracting secret names and expressions from strings and maps |
pkg/workflow/secret_extraction_test.go | Comprehensive test suite with 31 test cases covering all shared utilities including edge cases |
pkg/workflow/mcp-config.go | Refactored to use shared ExtractSecretsFromMap() and ReplaceSecretsWithEnvVars() utilities, removing 3 duplicate private functions |
pkg/workflow/mcp_http_headers_test.go | Updated test calls to use new exported function names (ExtractSecretsFromValue, ExtractSecretsFromMap, ReplaceSecretsWithEnvVars) |
pkg/cli/secrets.go | Removed duplicate extractSecretName() wrapper function and unused regex pattern; now directly uses workflow.ExtractSecretName() |
pkg/cli/secrets_test.go | Updated to import and use workflow.ExtractSecretName() instead of the removed local wrapper |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // SecretExpression represents a parsed secret expression | ||
| type SecretExpression struct { | ||
| VarName string // The secret variable name (e.g., "DD_API_KEY") | ||
| FullExpr string // The full expression (e.g., "${{ secrets.DD_API_KEY }}") | ||
| } |
There was a problem hiding this comment.
The SecretExpression struct is defined but never used anywhere in the codebase. This is dead code that should be removed.
| // SecretExpression represents a parsed secret expression | |
| typeSecretExpressionstruct { | |
| VarNamestring// The secret variable name (e.g., "DD_API_KEY") | |
| FullExprstring// The full expression (e.g., "${{ secrets.DD_API_KEY }}") | |
| } |
Uh oh!
There was an error while loading. Please reload this page.
✅ Consolidate Secret Extraction Logic - COMPLETE
Summary
Successfully eliminated ~60% code duplication in secret extraction logic by consolidating similar functions from
mcp-config.goandsecrets.gointo shared utilities.Changes Made
1. Created Shared Utilities ✓
pkg/workflow/secret_extraction.go(115 lines)secretExprPattern- Common pre-compiled regex for secret matchingExtractSecretName()- Extract just the secret name from expressionExtractSecretsFromValue()- Extract all secrets from a single stringExtractSecretsFromMap()- Extract all secrets from a map of stringsReplaceSecretsWithEnvVars()- Replace secret expressions with env var references2. Comprehensive Test Coverage ✓
pkg/workflow/secret_extraction_test.go(340 lines)3. Refactored Existing Code ✓
pkg/workflow/mcp-config.go:ExtractSecretsFromMap()ReplaceSecretsWithEnvVars()pkg/cli/secrets.go:extractSecretName()functionworkflow.ExtractSecretName()in all call sites4. Validation ✓
Benefits
Code Metrics
Files Changed
pkg/workflow/secret_extraction.go(new)pkg/workflow/secret_extraction_test.go(new)pkg/workflow/mcp-config.go(refactored)pkg/workflow/mcp_http_headers_test.go(updated)pkg/cli/secrets.go(refactored - removed thin wrapper)pkg/cli/secrets_test.go(updated to use workflow.ExtractSecretName)Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.