snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
This commit is contained in:
58
continuity/container_reference_store.go
Normal file
58
continuity/container_reference_store.go
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package continuity
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/ory/kratos/x"
|
||||
)
|
||||
|
||||
// ContainerReferenceStore abstracts where a continuity container's ID is
|
||||
// stored between Pause and Continue/Abort calls.
|
||||
type ContainerReferenceStore interface {
|
||||
Store(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, id uuid.UUID) error
|
||||
Retrieve(ctx context.Context, w http.ResponseWriter, r *http.Request, name string) (uuid.UUID, error)
|
||||
Clear(ctx context.Context, w http.ResponseWriter, r *http.Request, name string) error
|
||||
}
|
||||
|
||||
// CookieReferenceStore stores the container ID in an HTTP cookie.
|
||||
type CookieReferenceStore struct {
|
||||
cs sessions.StoreExact
|
||||
}
|
||||
|
||||
func NewCookieReferenceStore(cs sessions.StoreExact) *CookieReferenceStore {
|
||||
return &CookieReferenceStore{cs: cs}
|
||||
}
|
||||
|
||||
func (s *CookieReferenceStore) Store(_ context.Context, w http.ResponseWriter, r *http.Request, name string, id uuid.UUID) error {
|
||||
return x.SessionPersistValues(w, r, s.cs, CookieName, map[string]any{
|
||||
name: id.String(),
|
||||
})
|
||||
}
|
||||
|
||||
func (s *CookieReferenceStore) Retrieve(_ context.Context, w http.ResponseWriter, r *http.Request, name string) (uuid.UUID, error) {
|
||||
str, err := x.SessionGetString(r, s.cs, CookieName, name)
|
||||
if err != nil {
|
||||
_ = x.SessionUnsetKey(w, r, s.cs, CookieName, name)
|
||||
return uuid.Nil, errors.WithStack(ErrNotResumable().WithDebugf("%+v", err))
|
||||
}
|
||||
|
||||
sid, err := uuid.FromString(str)
|
||||
if err != nil {
|
||||
_ = x.SessionUnsetKey(w, r, s.cs, CookieName, name)
|
||||
return uuid.Nil, errors.WithStack(ErrNotResumable().WithDebug("session id is not a valid uuid"))
|
||||
}
|
||||
|
||||
return sid, nil
|
||||
}
|
||||
|
||||
func (s *CookieReferenceStore) Clear(_ context.Context, w http.ResponseWriter, r *http.Request, name string) error {
|
||||
return x.SessionUnsetKey(w, r, s.cs, CookieName, name)
|
||||
}
|
||||
Reference in New Issue
Block a user