DrainStdinChannel non-blockingly empties the channel and returns the discarded lines. The caller is responsible for any logging beyond the DEBUG-level summary emitted here.
(ch <-chan string)
| 70 | // discarded lines. The caller is responsible for any logging beyond the |
| 71 | // DEBUG-level summary emitted here. |
| 72 | func (g *InputGuard) DrainStdinChannel(ch <-chan string) []string { |
| 73 | if ch == nil { |
| 74 | return nil |
| 75 | } |
| 76 | var discarded []string |
| 77 | for { |
| 78 | select { |
| 79 | case line, ok := <-ch: |
| 80 | if !ok { |
| 81 | return discarded |
| 82 | } |
| 83 | discarded = append(discarded, line) |
| 84 | default: |
| 85 | if len(discarded) > 0 { |
| 86 | g.logger.Debug("input guard: drained pending stdin lines before security prompt", |
| 87 | zap.Int("count", len(discarded)), |
| 88 | zap.String("first_preview", preview(discarded[0]))) |
| 89 | } |
| 90 | return discarded |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // FlushTTYInput discards any unread input bytes still buffered by the kernel |
| 96 | // for the controlling terminal. On platforms where the operation is not |