parseHumanReadable reads human-readable relation tuples from the reader. Input is limited to MaxFileSizeBytes.
(r io.Reader)
| 65 | // parseHumanReadable reads human-readable relation tuples from the reader. |
| 66 | // Input is limited to MaxFileSizeBytes. |
| 67 | func parseHumanReadable(r io.Reader) ([]*ketoapi.RelationTuple, error) { |
| 68 | fc, err := io.ReadAll(io.LimitReader(r, int64(MaxFileSizeBytes)+1)) |
| 69 | if err != nil { |
| 70 | return nil, fmt.Errorf("reading input: %w", err) |
| 71 | } |
| 72 | if len(fc) > MaxFileSizeBytes { |
| 73 | return nil, fmt.Errorf("input exceeds maximum size of %d bytes", MaxFileSizeBytes) |
| 74 | } |
| 75 | |
| 76 | parts := strings.Split(string(fc), "\n") |
| 77 | rts := make([]*ketoapi.RelationTuple, 0, len(parts)) |
| 78 | for i, row := range parts { |
| 79 | row = strings.TrimSpace(row) |
| 80 | // ignore comments and empty lines |
| 81 | if row == "" || strings.HasPrefix(row, "//") { |
| 82 | continue |
| 83 | } |
| 84 | |
| 85 | rt, err := (&ketoapi.RelationTuple{}).FromString(row) |
| 86 | if err != nil { |
| 87 | return nil, fmt.Errorf("line %d: could not decode %q: %w", i+1, row, err) |
| 88 | } |
| 89 | rts = append(rts, rt) |
| 90 | } |
| 91 | |
| 92 | return rts, nil |
| 93 | } |
nothing calls this directly
no test coverage detected