MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / HashRedact

Method HashRedact

db/document.go:216–269  ·  view source on GitHub ↗

HashRedact does in-place redaction of UserData inside SyncData, by hashing channel names, user access, role access, and attachment names.

(salt string)

Source from the content-addressed store, hash-verified

214
215// HashRedact does in-place redaction of UserData inside SyncData, by hashing channel names, user access, role access, and attachment names.
216func (sd *SyncData) HashRedact(salt string) error {
217
218 // Redact channel names
219 for k, v := range sd.Channels {
220 sd.Channels[base.Sha1HashString(k, salt)] = v
221 delete(sd.Channels, k)
222 }
223 for i, v := range sd.ChannelSet {
224 sd.ChannelSet[i].Name = base.Sha1HashString(v.Name, salt)
225 }
226 for i, v := range sd.ChannelSetHistory {
227 sd.ChannelSetHistory[i].Name = base.Sha1HashString(v.Name, salt)
228 }
229
230 // Redact history. This is done as it also includes channel names
231 for k, revInfo := range sd.History {
232 if revInfo.Channels != nil {
233 redactedChannels := make(base.Set, len(revInfo.Channels))
234 for existingChanKey := range revInfo.Channels {
235 redactedChannels.Add(base.Sha1HashString(existingChanKey, salt))
236 }
237 revInfo.Channels = redactedChannels
238 }
239 sd.History[k] = revInfo
240 }
241
242 // Redact user access
243 for k, v := range sd.Access {
244 accessTimerSet := map[string]channels.VbSequence{}
245 for channelName, vbStats := range v {
246 accessTimerSet[base.Sha1HashString(channelName, salt)] = vbStats
247 }
248 sd.Access[base.Sha1HashString(k, salt)] = accessTimerSet
249 delete(sd.Access, k)
250 }
251
252 // Redact user role access
253 for k, v := range sd.RoleAccess {
254 accessTimerSet := map[string]channels.VbSequence{}
255 for channelName, vbStats := range v {
256 accessTimerSet[base.Sha1HashString(channelName, salt)] = vbStats
257 }
258 sd.RoleAccess[base.Sha1HashString(k, salt)] = accessTimerSet
259 delete(sd.RoleAccess, k)
260 }
261
262 // Redact attachment names (pre-4.0 attachment location)
263 for k, v := range sd.AttachmentsPre4dot0 {
264 sd.AttachmentsPre4dot0[base.Sha1HashString(k, salt)] = v
265
266 }
267
268 return nil
269}
270
271// A document as stored in Couchbase. Contains the body of the current revision plus metadata.
272// In its JSON form, the body's properties are at top-level while the SyncData is in a special

Callers 1

RedactRawSyncDataFunction · 0.95

Calls 2

Sha1HashStringFunction · 0.92
AddMethod · 0.45

Tested by

no test coverage detected