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
|
||||
logRows []*runnerv1.LogRow
|
||||
logReplacer *strings.Replacer
|
||||
state *runnerv1.TaskState
|
||||
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{
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
client: client,
|
||||
logReplacer: strings.NewReplacer(oldnew...),
|
||||
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 {
|
||||
content := strings.TrimSuffix(entry.Message, "\r\n")
|
||||
content = r.logReplacer.Replace(content)
|
||||
return &runnerv1.LogRow{
|
||||
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)
|
||||
|
||||
lastWords := ""
|
||||
reporter := NewReporter(ctx, cancel, t.client, task.Id)
|
||||
reporter := NewReporter(ctx, cancel, t.client, task)
|
||||
defer func() {
|
||||
_ = reporter.Close(lastWords)
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue