1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-11-06 08:59:21 +02:00

Add Redis lock

This commit is contained in:
Kevin Kreitner
2021-02-08 08:31:05 +01:00
parent 45c14bca10
commit b942eb1582
9 changed files with 119 additions and 3 deletions

View File

@@ -26,6 +26,10 @@ type saveFunc func(string, []byte, time.Duration) error
// string key and returning the stored value as []byte
type loadFunc func(string) ([]byte, error)
// lockFunc performs a lock on a persistent store using a
// string key
type lockFunc func(string) error
// clearFunc performs a persistent store's clear functionality using
// a string key for the target of the deletion.
type clearFunc func(string) error
@@ -135,6 +139,17 @@ func (t *ticket) loadSession(loader loadFunc) (*sessions.SessionState, error) {
return sessions.DecodeSessionState(ciphertext, c, false)
}
// lockSession loads a session from the disk store via the passed loadFunc
// using the ticket.id as the key. It then decodes the SessionState using
// ticket.secret to make the AES-GCM cipher.
func (t *ticket) lockSession(loader lockFunc) error {
err := loader(t.id)
if err != nil {
return fmt.Errorf("failed to lock the session state with the ticket: %v", err)
}
return nil
}
// clearSession uses the passed clearFunc to delete a session stored with a
// key of ticket.id
func (t *ticket) clearSession(clearer clearFunc) error {