Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.1 kB · 38 lines
123456789101112131415161718192021222324252627282930313233343536373839package localdb
import ( "errors" "fmt"
"gorm.io/gorm")
// ViewLogSalt is the per-UTC-day HMAC salt used to anonymize IP// addresses in the view-log pipeline. Same date returns the same salt,// so two requests from the same IP within a day share a hash; across// days the hash changes because the salt rotates. Cleaning up old rows// makes historical logs unrecoverable.type ViewLogSalt struct { Date string `gorm:"primaryKey;column:date"` Salt []byte `gorm:"column:salt"`}
func (m *LocalDatabase) GetViewLogSalt(date string) ([]byte, error) { var row ViewLogSalt err := m.DB.Where("date = ?", date).First(&row).Error if errors.Is(err, gorm.ErrRecordNotFound) { return nil, nil } if err != nil { return nil, fmt.Errorf("get view log salt: %w", err) } return row.Salt, nil}
func (m *LocalDatabase) PutViewLogSalt(date string, salt []byte) error { return m.DB.Save(&ViewLogSalt{Date: date, Salt: salt}).Error}
func (m *LocalDatabase) DeleteViewLogSaltsBefore(date string) error { return m.DB.Where("date < ?", date).Delete(&ViewLogSalt{}).Error}