readFromReader reads the maxBytes from the reader and drains the rest.
(reader io.ReadCloser, maxBytes int64)
| 131 | |
| 132 | // readFromReader reads the maxBytes from the reader and drains the rest. |
| 133 | func readFromReader(reader io.ReadCloser, maxBytes int64) ([]byte, error) { |
| 134 | limitReader := io.LimitReader(reader, maxBytes) |
| 135 | data, err := io.ReadAll(limitReader) |
| 136 | if err != nil { |
| 137 | return []byte{}, err |
| 138 | } |
| 139 | // Drain the reader |
| 140 | if _, err := io.Copy(io.Discard, reader); err != nil { |
| 141 | return []byte{}, err |
| 142 | } |
| 143 | return data, nil |
| 144 | } |
| 145 | |
| 146 | func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, output string) { |
| 147 | var ctx context.Context |