...

Source file src/edge-infra.dev/pkg/edge/auth-proxy/store/session.go

Documentation: edge-infra.dev/pkg/edge/auth-proxy/store

     1  package store
     2  
     3  import (
     4  	"database/sql"
     5  	"errors"
     6  	"time"
     7  
     8  	"github.com/gin-contrib/sessions"
     9  	"github.com/go-logr/logr"
    10  
    11  	"edge-infra.dev/pkg/edge/audit"
    12  )
    13  
    14  const (
    15  	// MaxSessionLength is the maximum length of the session value which is 1 gigabyte.
    16  	MaxSessionLength = 1073741824
    17  	// SessionIdentifier is the name of the session store/cookie.
    18  	SessionIdentifier = "edge-session"
    19  )
    20  
    21  type Store interface {
    22  	sessions.Store
    23  	MaxLength(int) error
    24  	Cleanup(time.Duration) (chan<- struct{}, <-chan struct{})
    25  	StopCleanup(chan<- struct{}, <-chan struct{})
    26  }
    27  
    28  type SubStore struct {
    29  	*PGStore
    30  }
    31  
    32  var _ Store = new(SubStore)
    33  
    34  func NewStore(db *sql.DB, log logr.Logger, auditLog *audit.Sink, keyPairs ...[]byte) (Store, error) {
    35  	p, err := NewPGStoreFromPool(db, log, auditLog, keyPairs...)
    36  	if err != nil {
    37  		return nil, err
    38  	}
    39  
    40  	return &SubStore{p}, nil
    41  }
    42  
    43  func (s *SubStore) Options(options sessions.Options) {
    44  	s.PGStore.Options = options.ToGorillaOptions()
    45  }
    46  
    47  func (s *SubStore) MaxLength(l int) error {
    48  	if l > MaxSessionLength {
    49  		return errors.New("length cannot be greater than 1 gigabyte")
    50  	}
    51  	if l < 0 {
    52  		l = MaxSessionLength
    53  	}
    54  	s.PGStore.MaxLength(l)
    55  	return nil
    56  }
    57  
    58  func (s *SubStore) Cleanup(interval time.Duration) (chan<- struct{}, <-chan struct{}) {
    59  	return s.PGStore.Cleanup(interval)
    60  }
    61  
    62  func (s *SubStore) StopCleanup(quit chan<- struct{}, done <-chan struct{}) {
    63  	s.PGStore.StopCleanup(quit, done)
    64  }
    65  

View as plain text