MCPcopy
hub / github.com/go-task/task / MaskSecretsWithExtra

Function MaskSecretsWithExtra

internal/templater/secrets.go:15–51  ·  view source on GitHub ↗

MaskSecretsWithExtra is like MaskSecrets but also resolves extra variables (e.g., loop vars).

(cmdTemplate string, vars *ast.Vars, extra map[string]any)

Source from the content-addressed store, hash-verified

13
14// MaskSecretsWithExtra is like MaskSecrets but also resolves extra variables (e.g., loop vars).
15func MaskSecretsWithExtra(cmdTemplate string, vars *ast.Vars, extra map[string]any) string {
16 if vars == nil {
17 vars = ast.NewVars()
18 }
19
20 // Fast path: if there are no secrets to mask, resolve the template directly
21 // without the extra DeepCopy + masking pass.
22 if !hasSecrets(vars) {
23 cache := &Cache{Vars: vars}
24 result := ReplaceWithExtra(cmdTemplate, cache, extra)
25 if cache.Err() != nil {
26 return cmdTemplate
27 }
28 return result
29 }
30
31 // Create a copy with secret values masked, leaving the originals untouched.
32 maskedVars := vars.DeepCopy()
33 for name, v := range maskedVars.All() {
34 if v.Secret {
35 maskedVars.Set(name, ast.Var{
36 Value: "*****",
37 Secret: true,
38 })
39 }
40 }
41
42 cache := &Cache{Vars: maskedVars}
43 result := ReplaceWithExtra(cmdTemplate, cache, extra)
44
45 // If there was an error, return the original template
46 if cache.Err() != nil {
47 return cmdTemplate
48 }
49
50 return result
51}
52
53// hasSecrets reports whether any variable is marked as secret.
54func hasSecrets(vars *ast.Vars) bool {

Callers 3

compiledTaskMethod · 0.92
runDeferredMethod · 0.92
MaskSecretsFunction · 0.85

Calls 7

ErrMethod · 0.95
NewVarsFunction · 0.92
hasSecretsFunction · 0.85
ReplaceWithExtraFunction · 0.85
DeepCopyMethod · 0.65
AllMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…