mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
fix: hide masked values in log files (#1011)
this commit adds support for the `::add-mask::` command, which was implemented as a stub before. it does not cover debug output that appears when you run act in verbose mode Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se> Co-authored-by: Markus Wolf <markus.wolf@new-work.se> Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se> Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
This commit is contained in:
parent
0cd9ec8998
commit
de31c2cff1
6 changed files with 72 additions and 2 deletions
|
@ -38,13 +38,15 @@ func init() {
|
|||
}
|
||||
|
||||
// WithJobLogger attaches a new logger to context that is aware of steps
|
||||
func WithJobLogger(ctx context.Context, jobName string, secrets map[string]string, insecureSecrets bool) context.Context {
|
||||
func WithJobLogger(ctx context.Context, jobName string, secrets map[string]string, insecureSecrets bool, masks *[]string) context.Context {
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
formatter := new(stepLogFormatter)
|
||||
formatter.color = colors[nextColor%len(colors)]
|
||||
formatter.secrets = secrets
|
||||
formatter.insecureSecrets = insecureSecrets
|
||||
formatter.masks = masks
|
||||
|
||||
nextColor++
|
||||
|
||||
logger := logrus.New()
|
||||
|
@ -66,6 +68,7 @@ type stepLogFormatter struct {
|
|||
color int
|
||||
secrets map[string]string
|
||||
insecureSecrets bool
|
||||
masks *[]string
|
||||
}
|
||||
|
||||
func (f *stepLogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
|
@ -78,6 +81,12 @@ func (f *stepLogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|||
entry.Message = strings.ReplaceAll(entry.Message, v, "***")
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range *f.masks {
|
||||
if v != "" {
|
||||
entry.Message = strings.ReplaceAll(entry.Message, v, "***")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if f.isColored(entry) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue