package store import ( "database/sql" "errors" "time" "github.com/gin-contrib/sessions" "github.com/go-logr/logr" "edge-infra.dev/pkg/edge/audit" ) const ( // MaxSessionLength is the maximum length of the session value which is 1 gigabyte. MaxSessionLength = 1073741824 // SessionIdentifier is the name of the session store/cookie. SessionIdentifier = "edge-session" ) type Store interface { sessions.Store MaxLength(int) error Cleanup(time.Duration) (chan<- struct{}, <-chan struct{}) StopCleanup(chan<- struct{}, <-chan struct{}) } type SubStore struct { *PGStore } var _ Store = new(SubStore) func NewStore(db *sql.DB, log logr.Logger, auditLog *audit.Sink, keyPairs ...[]byte) (Store, error) { p, err := NewPGStoreFromPool(db, log, auditLog, keyPairs...) if err != nil { return nil, err } return &SubStore{p}, nil } func (s *SubStore) Options(options sessions.Options) { s.PGStore.Options = options.ToGorillaOptions() } func (s *SubStore) MaxLength(l int) error { if l > MaxSessionLength { return errors.New("length cannot be greater than 1 gigabyte") } if l < 0 { l = MaxSessionLength } s.PGStore.MaxLength(l) return nil } func (s *SubStore) Cleanup(interval time.Duration) (chan<- struct{}, <-chan struct{}) { return s.PGStore.Cleanup(interval) } func (s *SubStore) StopCleanup(quit chan<- struct{}, done <-chan struct{}) { s.PGStore.StopCleanup(quit, done) }