mirror of https://code.forgejo.org/forgejo/runner
feat: replace ciphertext in log
parent
222b5100b6
commit
d650bae0b6
|
@ -27,17 +27,27 @@ type Reporter struct {
|
||||||
|
|
||||||
logOffset int
|
logOffset int
|
||||||
logRows []*runnerv1.LogRow
|
logRows []*runnerv1.LogRow
|
||||||
|
logReplacer *strings.Replacer
|
||||||
state *runnerv1.TaskState
|
state *runnerv1.TaskState
|
||||||
stateM sync.RWMutex
|
stateM sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.Client, taskID int64) *Reporter {
|
func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.Client, task *runnerv1.Task) *Reporter {
|
||||||
|
var oldnew []string
|
||||||
|
if v := task.Context.Fields["token"].GetStringValue(); v != "" {
|
||||||
|
oldnew = append(oldnew, v, "***")
|
||||||
|
}
|
||||||
|
for _, v := range task.Secrets {
|
||||||
|
oldnew = append(oldnew, v, "***")
|
||||||
|
}
|
||||||
|
|
||||||
return &Reporter{
|
return &Reporter{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
client: client,
|
client: client,
|
||||||
|
logReplacer: strings.NewReplacer(oldnew...),
|
||||||
state: &runnerv1.TaskState{
|
state: &runnerv1.TaskState{
|
||||||
Id: taskID,
|
Id: task.Id,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,8 +276,10 @@ func (r *Reporter) parseResult(result interface{}) (runnerv1.Result, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reporter) parseLogRow(entry *log.Entry) *runnerv1.LogRow {
|
func (r *Reporter) parseLogRow(entry *log.Entry) *runnerv1.LogRow {
|
||||||
|
content := strings.TrimSuffix(entry.Message, "\r\n")
|
||||||
|
content = r.logReplacer.Replace(content)
|
||||||
return &runnerv1.LogRow{
|
return &runnerv1.LogRow{
|
||||||
Time: timestamppb.New(entry.Time),
|
Time: timestamppb.New(entry.Time),
|
||||||
Content: strings.TrimSuffix(entry.Message, "\r\n"),
|
Content: content,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ func (t *Task) Run(ctx context.Context, task *runnerv1.Task) error {
|
||||||
defer globalTaskMap.Delete(task.Id)
|
defer globalTaskMap.Delete(task.Id)
|
||||||
|
|
||||||
lastWords := ""
|
lastWords := ""
|
||||||
reporter := NewReporter(ctx, cancel, t.client, task.Id)
|
reporter := NewReporter(ctx, cancel, t.client, task)
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = reporter.Close(lastWords)
|
_ = reporter.Close(lastWords)
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue