redactSyncFragments returns a deep copy of sync fragments with sensitive fields (note body, book label) removed for safe logging
(fragments []client.SyncFragment)
| 190 | |
| 191 | // redactSyncFragments returns a deep copy of sync fragments with sensitive fields (note body, book label) removed for safe logging |
| 192 | func redactSyncFragments(fragments []client.SyncFragment) []client.SyncFragment { |
| 193 | redacted := make([]client.SyncFragment, len(fragments)) |
| 194 | for i, frag := range fragments { |
| 195 | // Create new notes with redacted bodies |
| 196 | notes := make([]client.SyncFragNote, len(frag.Notes)) |
| 197 | for j, note := range frag.Notes { |
| 198 | notes[j] = client.SyncFragNote{ |
| 199 | UUID: note.UUID, |
| 200 | BookUUID: note.BookUUID, |
| 201 | USN: note.USN, |
| 202 | CreatedAt: note.CreatedAt, |
| 203 | UpdatedAt: note.UpdatedAt, |
| 204 | AddedOn: note.AddedOn, |
| 205 | EditedOn: note.EditedOn, |
| 206 | Body: func() string { |
| 207 | if note.Body != "" { |
| 208 | return "<redacted>" |
| 209 | } |
| 210 | return "" |
| 211 | }(), |
| 212 | Deleted: note.Deleted, |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // Create new books with redacted labels |
| 217 | books := make([]client.SyncFragBook, len(frag.Books)) |
| 218 | for j, book := range frag.Books { |
| 219 | books[j] = client.SyncFragBook{ |
| 220 | UUID: book.UUID, |
| 221 | USN: book.USN, |
| 222 | CreatedAt: book.CreatedAt, |
| 223 | UpdatedAt: book.UpdatedAt, |
| 224 | AddedOn: book.AddedOn, |
| 225 | Label: func() string { |
| 226 | if book.Label != "" { |
| 227 | return "<redacted>" |
| 228 | } |
| 229 | return "" |
| 230 | }(), |
| 231 | Deleted: book.Deleted, |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | redacted[i] = client.SyncFragment{ |
| 236 | FragMaxUSN: frag.FragMaxUSN, |
| 237 | UserMaxUSN: frag.UserMaxUSN, |
| 238 | CurrentTime: frag.CurrentTime, |
| 239 | Notes: notes, |
| 240 | Books: books, |
| 241 | ExpungedNotes: frag.ExpungedNotes, |
| 242 | ExpungedBooks: frag.ExpungedBooks, |
| 243 | } |
| 244 | } |
| 245 | return redacted |
| 246 | } |
| 247 | |
| 248 | // resolveLabel resolves a book label conflict by repeatedly appending an increasing integer |
| 249 | // to the label until it finds a unique label. It returns the first non-conflicting label. |