MCPcopy Create free account
hub / github.com/github/gh-aw / ExtractSecretsFromValue

Function ExtractSecretsFromValue

pkg/workflow/secret_extraction.go:48–74  ·  view source on GitHub ↗

ExtractSecretsFromValue extracts all GitHub Actions secret expressions from a string value Returns a map of environment variable names to their full secret expressions This function detects secrets in both simple expressions and sub-expressions: Examples: - "${{ secrets.DD_API_KEY }}" -> {"DD_API_KE

(value string)

Source from the content-addressed store, hash-verified

46// - "${{ github.workflow && secrets.TOKEN }}" -> {"TOKEN": "${{ github.workflow && secrets.TOKEN }}"}
47// - "${{ (github.actor || secrets.HIDDEN) }}" -> {"HIDDEN": "${{ (github.actor || secrets.HIDDEN) }}"}
48func ExtractSecretsFromValue(value string) map[string]string {
49 secrets := make(map[string]string)
50
51 // Find all ${{ ... }} expressions in the value
52 // Pattern matches from ${{ to }} allowing nested content
53 expressions := InlineExpressionPattern.FindAllString(value, -1)
54
55 // For each expression, check if it contains secrets.VARIABLE_NAME
56 // This handles both simple cases like "${{ secrets.TOKEN }}"
57 // and complex sub-expressions like "${{ github.workflow && secrets.TOKEN }}"
58 for _, expr := range expressions {
59 matches := secretsNamePattern.FindAllStringSubmatch(expr, -1)
60 for _, match := range matches {
61 if len(match) >= 2 {
62 varName := match[1]
63 // Store the full expression that contains this secret
64 secrets[varName] = expr
65 secretLog.Printf("Extracted secret: %s from expression: %s", varName, expr)
66 }
67 }
68 }
69
70 if len(secrets) > 0 {
71 secretLog.Printf("Extracted %d secrets from value", len(secrets))
72 }
73 return secrets
74}
75
76// ExtractSecretsFromMap extracts all secrets from a map of string values
77// Returns a map of environment variable names to their full secret expressions

Calls 1

PrintfMethod · 0.45